Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * g++ -o lt-regexp lt-regexp.cc -I/usr/include/libxml2 -I/home/fran/local/include/lttoolbox-3.2 -L/home/fran/local/lib -llttoolbox3 -llibxml2
- */
- #include <cwchar>
- #include <cstdio>
- #include <cerrno>
- #include <string>
- #include <iostream>
- #include <list>
- #include <set>
- #include <lttoolbox/ltstr.h>
- #include <lttoolbox/lt_locale.h>
- #include <lttoolbox/transducer.h>
- #include <lttoolbox/alphabet.h>
- #include <lttoolbox/pool.h>
- #include <lttoolbox/state.h>
- #include <lttoolbox/regexp_compiler.h>
- #include <lttoolbox/match_exe.h>
- #include <lttoolbox/match_state.h>
- #include <lttoolbox/xml_parse_util.h>
- wstring ws(char *arg)
- {
- wchar_t buf[1024];
- memset(buf, '\0', 1024);
- size_t num_chars = mbstowcs(buf, arg, strlen(arg));
- wstring ws(buf, num_chars);
- return ws;
- }
- bool match(Transducer t, wstring str, Alphabet a)
- {
- map<int, int> finals;
- for(int i = 0; i < t.size(); i++)
- {
- if(t.isFinal(i))
- {
- finals[i] = i;
- }
- fwprintf(stdout, L"%d %d\n", i, t.isFinal(i));
- }
- MatchExe me(t, finals);
- MatchState ms;
- ms.init(me.getInitial());
- ms.step(L'b');
- ms.step(L'e');
- ms.step(L'e');
- ms.step(L'r');
- int val = ms.classifyFinals(me.getFinals());
- fwprintf(stdout, L"%d\n", val);
- /*
- for(wstring::iterator it = str.begin(); it != str.end(); it++)
- {
- ms.step(*it);
- wcout << *it << endl;
- }
- int val = ms.classifyFinals(me.getFinals());
- fwprintf(stdout, L"%d\n", val);
- */
- }
- int main (int argc, char** argv)
- {
- Alphabet alphabet;
- Transducer t;
- RegexpCompiler re;
- bool matched;
- LtLocale::tryToSetLocale();
- if(argc < 3)
- {
- wcout << L"Usage: lt-regexp <pattern> <string to match>" << endl;
- exit(-1);
- }
- FILE *output = stdout;
- wstring pattern = ws(argv[1]);
- wstring s = ws(argv[2]);
- re.initialize(&alphabet);
- re.compile(pattern);
- t = re.getTransducer();
- t.minimize();
- t.show(alphabet, output);
- matched = match(t, s, alphabet);
- wcout << endl << pattern << " " << s << endl;
- }
Add Comment
Please, Sign In to add comment