31 #include <string_view> 37 "FST errors are fatal; o.w. return objects flagged as bad: " 38 "e.g., FSTs: kError property set, FST weights: not a Member()");
42 std::optional<int64_t>
ParseInt64(std::string_view s,
int base) {
50 if (
const auto [p, ec] =
51 std::from_chars(s.data(), s.data() + s.size(), n, base);
52 ec != std::errc() || p != (s.data() + s.size())) {
58 int64_t
StrToInt64(std::string_view s, std::string_view source,
size_t nline,
59 bool allow_negative,
bool *error) {
60 if (error) *error =
false;
61 const std::optional<int64_t> maybe_n =
ParseInt64(s);
62 if (!maybe_n.has_value() || (!allow_negative && *maybe_n < 0)) {
63 FSTERROR() <<
"StrToInt64: Bad integer = " << s <<
"\", source = " << source
64 <<
", line = " << nline;
65 if (error) *error =
true;
72 for (
auto it = s->begin(); it != s->end(); ++it) {
83 for (
size_t i = 0; i < align; ++i) {
84 int64_t pos = strm.tellg();
86 LOG(ERROR) <<
"AlignInput: Can't determine stream position";
89 if (pos % align == 0)
break;
98 for (
size_t i = 0; i < align; ++i) {
99 int64_t pos = strm.tellp();
101 LOG(ERROR) <<
"AlignOutput: Can't determine stream position";
104 if (pos % align == 0)
break;
111 std::ostringstream &buffer,
113 const auto strm_pos = strm.tellp();
114 if (strm_pos == -1) {
115 LOG(ERROR) <<
"Cannot determine stream position";
118 const int stream_offset = strm_pos % align;
119 for (
int i = 0; i < stream_offset; ++i) buffer.write(
"", 1);
120 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 allow_negative, bool *error=nullptr)