1 // See www.openfst.org for extensive documentation on this weighted
2 // finite-state transducer library.
4 // FST utility definitions.
10 #include <fst/flags.h>
12 #include <fst/mapped-file.h>
14 // Utility flag definitions
16 DEFINE_bool(fst_error_fatal, true,
17 "FST errors are fatal; o.w. return objects flagged as bad: "
18 "e.g., FSTs: kError property set, FST weights: not a Member()");
22 void SplitToVector(char *full, const char *delim, std::vector<char *> *vec,
23 bool omit_empty_strings) {
26 if ((p = strpbrk(full, delim))) {
29 if (!omit_empty_strings || full[0] != '\0') vec->push_back(full);
34 int64 StrToInt64(const string &s, const string &src, size_t nline,
35 bool allow_negative, bool *error) {
37 const char *cs = s.c_str();
39 if (error) *error = false;
40 n = strtoll(cs, &p, 10);
41 if (p < cs + s.size() || (!allow_negative && n < 0)) {
42 FSTERROR() << "StrToInt64: Bad integer = " << s << "\", source = " << src
43 << ", line = " << nline;
44 if (error) *error = true;
50 void ConvertToLegalCSymbol(string *s) {
51 for (auto it = s->begin(); it != s->end(); ++it) {
58 // Skips over input characters to align to 'align' bytes. Returns
59 // false if can't align.
60 bool AlignInput(std::istream &strm) {
62 for (int i = 0; i < MappedFile::kArchAlignment; ++i) {
63 int64 pos = strm.tellg();
65 LOG(ERROR) << "AlignInput: Can't determine stream position";
68 if (pos % MappedFile::kArchAlignment == 0) break;
74 // Write null output characters to align to 'align' bytes. Returns
75 // false if can't align.
76 bool AlignOutput(std::ostream &strm) {
77 for (int i = 0; i < MappedFile::kArchAlignment; ++i) {
78 int64 pos = strm.tellp();
80 LOG(ERROR) << "AlignOutput: Can't determine stream position";
83 if (pos % MappedFile::kArchAlignment == 0) break;