31 #include <system_error> 35 #include <string_view> 41 "FST errors are fatal; o.w. return objects flagged as bad: " 42 "e.g., FSTs: kError property set, FST weights: not a Member()");
46 std::optional<int64_t>
ParseInt64(std::string_view s,
int base) {
54 if (
const auto [p, ec] =
55 std::from_chars(s.data(), s.data() + s.size(), n, base);
56 ec != std::errc() || p != (s.data() + s.size())) {
62 int64_t
StrToInt64(std::string_view s, std::string_view source,
size_t nline,
64 if (error) *error =
false;
65 const std::optional<int64_t> maybe_n =
ParseInt64(s);
66 if (!maybe_n.has_value()) {
67 FSTERROR() <<
"StrToInt64: Bad integer = " << s <<
"\", source = " << source
68 <<
", line = " << nline;
69 if (error) *error =
true;
76 for (
auto it = s->begin(); it != s->end(); ++it) {
87 for (
size_t i = 0; i < align; ++i) {
88 int64_t pos = strm.tellg();
90 LOG(ERROR) <<
"AlignInput: Can't determine stream position";
93 if (pos % align == 0)
break;
102 for (
size_t i = 0; i < align; ++i) {
103 int64_t pos = strm.tellp();
105 LOG(ERROR) <<
"AlignOutput: Can't determine stream position";
108 if (pos % align == 0)
break;
115 std::ostringstream &buffer,
117 const auto strm_pos = strm.tellp();
118 if (strm_pos == -1) {
119 LOG(ERROR) <<
"Cannot determine stream position";
122 const int stream_offset = strm_pos % align;
123 for (
int i = 0; i < stream_offset; ++i) buffer.write(
"", 1);
124 return stream_offset;
DEFINE_bool(fst_error_fatal, true,"FST errors are fatal; o.w. return objects flagged as bad: ""e.g., FSTs: kError property set, FST weights: not a Member()")
bool AlignInput(std::istream &strm, size_t align=MappedFile::kArchAlignment)
void ConvertToLegalCSymbol(std::string *s)
bool AlignOutput(std::ostream &strm, size_t align=MappedFile::kArchAlignment)
std::optional< int64_t > ParseInt64(std::string_view s, int base=10)
int AlignBufferWithOutputStream(std::ostream &strm, std::ostringstream &buffer, size_t align)
int64_t StrToInt64(std::string_view s, std::string_view source, size_t nline, bool *error=nullptr)