-
Notifications
You must be signed in to change notification settings - Fork 1
/
hfst_xfst_extensions.cc
68 lines (57 loc) · 2.14 KB
/
hfst_xfst_extensions.cc
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
namespace hfst {
// *** Wrapper variables for IOString outputs *** //
std::string hfst_xfst_string_one("");
char * get_hfst_xfst_string_one() { return strdup(hfst::hfst_xfst_string_one.c_str()); }
std::string hfst_xfst_string_two("");
char * get_hfst_xfst_string_two() { return strdup(hfst::hfst_xfst_string_two.c_str()); }
int hfst_compile_xfst_to_string_one(hfst::xfst::XfstCompiler & comp, std::string input)
{
hfst::hfst_xfst_string_one="";
hfst::hfst_xfst_string_two="";
std::ostringstream os(std::ostringstream::ate);
hfst::set_warning_stream(&os);
comp.set_output_stream(os);
comp.set_error_stream(os);
int retval = comp.parse_line(input);
hfst::hfst_xfst_string_one = os.str();
hfst::set_warning_stream(&std::cerr);
return retval;
}
int hfst_compile_xfst(hfst::xfst::XfstCompiler & comp, std::string input, const std::string & output_stream, const std::string & error_stream)
{
hfst::hfst_xfst_string_one="";
hfst::hfst_xfst_string_two="";
std::ostringstream * os1 = NULL;
std::ostringstream * os2 = NULL;
if (output_stream == "cout")
comp.set_output_stream(std::cout);
else if (output_stream == "cerr")
comp.set_output_stream(std::cerr);
else {
os1 = new std::ostringstream(std::ostringstream::ate);
comp.set_output_stream(*os1);
}
if (error_stream == "cout") {
comp.set_error_stream(std::cout);
hfst::set_warning_stream(&std::cout);
}
else if (error_stream == "cerr")
comp.set_error_stream(std::cerr);
else {
os2 = new std::ostringstream(std::ostringstream::ate);
comp.set_error_stream(*os2);
hfst::set_warning_stream(os2);
}
int retval = comp.parse_line(input);
hfst::set_warning_stream(&std::cerr);
if (output_stream == "") {
hfst::hfst_xfst_string_one = os1->str();
delete os1;
}
if (error_stream == "") {
hfst::hfst_xfst_string_two = os2->str();
delete os2;
}
return retval;
}
}