Index: branches/apertium-separable/src/lsx_processor.cc =================================================================== --- branches/apertium-separable/src/lsx_processor.cc (revision 80786) +++ branches/apertium-separable/src/lsx_processor.cc (revision 80787) @@ -105,19 +105,42 @@ bool outOfWord = true; bool isEscaped = false; bool finalFound = false; + bool reset = false; - wstring in, out; + wstring in = L""; + wstring out; + bool leading = false; + // int i=0; while(!feof(input)) { + // i++; + int val = fgetwc(input); // read 1 wide char + // cout << i << " " << &alive_states[0] << endl; + // cout << &alive_states.front() << " " << initial_state << endl << endl; if(alive_states.size() == 0 && !finalFound) { + // wcout << "val: " << (wchar_t)val << endl; alive_states.push_back(*initial_state); + // fputws(L"IN",output); fputws(in.c_str(), output); in = L""; + leading = true; } + else if(alive_states.size() == 0 && finalFound) + { + in = L""; + finalFound = false; + } + else if(alive_states.size() == 1 && &alive_states.front() == initial_state) + { + // fputws(in.c_str(), output); + // in = L""; + // cout <<"Here"<(alphabet(tag)); in += tag; - // fwprintf(stderr, L"tag %S: %d\n", tag.c_str(), val); } else { @@ -188,6 +210,7 @@ if(s.size() > 0) { new_states.push_back(s); + } // wcout << L"| | " << /*(wchar_t) val << */L"val " << L"size: " << s.size() << L" final: " << s.isFinal(anfinals) << endl; // wcerr << L"| | cur: " << s.getReadableString(alphabet) << endl; @@ -197,6 +220,8 @@ out = s.filterFinals(anfinals, alphabet, escaped_chars); // wcerr << s.getReadableString(alphabet) << endl; new_states.push_back(*initial_state); + + reset = true; finalFound = true; for (int i=0; i < (int) out.size(); i++) @@ -213,12 +238,17 @@ out[i+1] = L'^'; } } - out = out.substr(0, out.length()-2); // remove extra trailing ' ^ + out = out.substr(0, out.length()-3); // remove extra trailing '$ ^ + // '^ ' is excess, '$' will be added in the next loop with fputws(in,output) + // fputwc(L' ', output); + if(leading) { fputwc(L' ', output); + } fputws(out.c_str(), output); } } alive_states.swap(new_states); + } if(outOfWord) @@ -248,12 +278,14 @@ // else if (!finalFound) { - out = in; + // wcout << in << endl; + fputws(in.c_str(), output); + // wcout << in << endl; // wcout << out << endl; // wcout << "equals? " << (out==in); } // wcout << out.c_str() << endl; - // fputws(out.c_str(), output); + fputwc(L'\n', output); return 0; } \ No newline at end of file