FST  openfst-1.7.1
OpenFst Library
strings.cc
Go to the documentation of this file.
1 // See www.openfst.org for extensive documentation on this weighted
2 // finite-state transducer library.
3 
4 #include <cmath>
5 #include <string>
6 
7 #include <fst/flags.h>
9 #include <fstream>
10 
11 DEFINE_string(far_field_separator, "\t",
12  "Set of characters used as a separator between printed fields");
13 
14 namespace fst {
15 
16 // Computes the minimal length required to encode each line number as a decimal
17 // number.
18 int KeySize(const char *filename) {
19  std::ifstream istrm(filename);
20  istrm.seekg(0);
21  string s;
22  int nline = 0;
23  while (getline(istrm, s)) ++nline;
24  istrm.seekg(0);
25  return nline ? ceil(log10(nline + 1)) : 1;
26 }
27 
28 } // namespace fst
int KeySize(const char *filename)
Definition: strings.cc:18
DEFINE_string(far_field_separator,"\t","Set of characters used as a separator between printed fields")