File: hfst_regex_extensions.cpp

package info (click to toggle)
hfst 3.16.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 14,532 kB
  • sloc: cpp: 101,875; sh: 6,717; python: 5,225; yacc: 4,985; lex: 2,900; makefile: 2,017; xml: 6
file content (34 lines) | stat: -rw-r--r-- 1,044 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
namespace hfst {

// *** Wrapper variables for IOString outputs *** //

std::string hfst_regex_error_message("");
std::string get_hfst_regex_error_message() { return hfst::hfst_regex_error_message; }

hfst::HfstTransducer * hfst_regex(hfst::xre::XreCompiler & comp, const std::string & regex_string, const std::string & error_stream)
{
        hfst_regex_error_message="";
        
        if (error_stream == "cout")
        {
          comp.set_error_stream(&std::cout);
          return comp.compile(regex_string);
        }
        else if (error_stream == "cerr")
        {
          comp.set_error_stream(&std::cerr);
          return comp.compile(regex_string);
        }
        else
        {
          std::ostringstream os(std::ostringstream::ate);
          comp.set_error_stream(&os);
          hfst::set_warning_stream(&os);
          hfst::HfstTransducer * retval = comp.compile(regex_string);
          hfst_regex_error_message = os.str();
          hfst::set_warning_stream(&std::cerr);
          return retval;
        }
}

}