diff --git a/parse-input.cc b/parse-input.cc index 208a587..1a449aa 100644 --- a/parse-input.cc +++ b/parse-input.cc @@ -1,21 +1,26 @@ #include +#include #include #include /* isspace() */ #include "parse-input.h" using namespace std; #define SET_ERROR(err, args...) \ - sprintf(errstr, err " at line %d, column %d", ##args, lineno, colno) + do { \ + error = true; \ + sprintf(errstr, err " at line %d, column %d", ##args, lineno, colno); \ + } while(0) void parse_input(refptr< vector > ucs) { - enum State { INITIAL, LB, SECTION_NAME, RB }; + enum State { INITIAL, SECTION_NAME, RULES }; State state = INITIAL; int lineno = 1; int colno = 1; bool error = false; char errstr[200]; + unistring build_str; for (int i = 0, sz = ucs->size(); i < sz; i++) { @@ -34,18 +39,36 @@ void parse_input(refptr< vector > ucs) case INITIAL: if (c == '[') { - state = LB; + state = SECTION_NAME; + build_str = ""; } else if (isspace(c)) { } else { - error = true; SET_ERROR("Unexpected character 0x%x (%c) in input file", c, c); } break; + case SECTION_NAME: + switch (c) + { + case ']': + if (build_str == "rules") + { + state = RULES; + } + else + { + SET_ERROR("Unknown section name"); + } + break; + case '\n': + SET_ERROR("Unterminated section header"); + break; + } + break; } } } diff --git a/unicode.cc b/unicode.cc new file mode 100644 index 0000000..bff58b5 --- /dev/null +++ b/unicode.cc @@ -0,0 +1,27 @@ + +#include "unicode.h" +#include + +unistring & unistring::operator=(const char * ascii_str) +{ + chars.clear(); + const char * as_ptr = ascii_str; + while (*as_ptr != '\0') + { + chars.push_back(*as_ptr); + } + return *this; +} + +bool unistring::operator==(const char * ascii_str) +{ + int len = chars.size(); + if (len != strlen(ascii_str)) + return false; + for (int i = 0; i < len; i++) + { + if (chars[i] != ascii_str[i]) + return false; + } + return true; +} diff --git a/unicode.h b/unicode.h index ba93a1c..e161819 100644 --- a/unicode.h +++ b/unicode.h @@ -2,7 +2,18 @@ #ifndef UNICODE_H #include +#include typedef uint32_t unichar_t; +class unistring +{ + public: + unistring & operator=(const char * ascii_str); + bool operator==(const char * ascii_str); + + protected: + std::vector chars; +}; + #endif