diff options
Diffstat (limited to 'pjlib/include/pj++/scanner.hpp')
-rw-r--r-- | pjlib/include/pj++/scanner.hpp | 108 |
1 files changed, 82 insertions, 26 deletions
diff --git a/pjlib/include/pj++/scanner.hpp b/pjlib/include/pj++/scanner.hpp index e9ffe304..fb012056 100644 --- a/pjlib/include/pj++/scanner.hpp +++ b/pjlib/include/pj++/scanner.hpp @@ -22,35 +22,91 @@ #include <pjlib-util/scanner.h> #include <pj++/string.hpp> -class Pj_Char_Spec +class Pj_Cis; +class Pj_Cis_Buffer; +class Pj_Scanner; + +class Pj_Cis_Buffer { + friend class Pj_Cis; + public: - Pj_Char_Spec() { pj_cs_init(cs__); } + Pj_Cis_Buffer() + { + pj_cis_buf_init(&buf_); + } + +private: + pj_cis_buf_t buf_; +}; + + +class Pj_Cis +{ + friend class Pj_Scanner; + +public: + Pj_Cis(Pj_Cis_Buffer *buf) + { + pj_cis_init(&buf->buf_, &cis_); + } + + Pj_Cis(const Pj_Cis &rhs) + { + pj_cis_dup(&cis_, (pj_cis_t*)&rhs.cis_); + } + + void add_range(int start, int end) + { + pj_cis_add_range(&cis_, start, end); + } - void set(int c) { pj_cs_set(cs__, c); } - void add_range(int begin, int end) { pj_cs_add_range(cs__, begin, end); } - void add_alpha() { pj_cs_add_alpha(cs__); } - void add_num() { pj_cs_add_num(cs__); } - void add_str(const char *str) { pj_cs_add_str(cs__, str); } - void del_range(int begin, int end) { pj_cs_del_range(cs__, begin, end); } - void del_str(const char *str) { pj_cs_del_str(cs__, str); } - void invert() { pj_cs_invert(cs__); } - int match(int c) { return pj_cs_match(cs__, c); } + void add_alpha() + { + pj_cis_add_alpha(&cis_); + } + + void add_num() + { + pj_cis_add_num(&cis_); + } - pj_char_spec_element_t *cs_() + void add_str(const char *str) { - return cs__; + pj_cis_add_str(&cis_, str); } - const pj_char_spec_element_t *cs_() const + void add_cis(const Pj_Cis &rhs) { - return cs__; + pj_cis_add_cis(&cis_, &rhs.cis_); + } + + void del_range(int start, int end) + { + pj_cis_del_range(&cis_, start, end); + } + + void del_str(const char *str) + { + pj_cis_del_str(&cis_, str); + } + + void invert() + { + pj_cis_invert(&cis_); + } + + bool match(int c) const + { + return pj_cis_match(&cis_, c) != 0; } private: - pj_char_spec cs__; + pj_cis_t cis_; }; + + class Pj_Scanner { public: @@ -85,9 +141,9 @@ public: return *scanner_.curptr; } - int peek(const Pj_Char_Spec *cs, Pj_String *out) + int peek(const Pj_Cis *cis, Pj_String *out) { - return pj_scan_peek(&scanner_, cs->cs_(), out); + return pj_scan_peek(&scanner_, &cis->cis_, out); } int peek_n(pj_size_t len, Pj_String *out) @@ -95,14 +151,14 @@ public: return pj_scan_peek_n(&scanner_, len, out); } - int peek_until(const Pj_Char_Spec *cs, Pj_String *out) + int peek_until(const Pj_Cis *cis, Pj_String *out) { - return pj_scan_peek_until(&scanner_, cs->cs_(), out); + return pj_scan_peek_until(&scanner_, &cis->cis_, out); } - void get(const Pj_Char_Spec *cs, Pj_String *out) + void get(const Pj_Cis *cis, Pj_String *out) { - pj_scan_get(&scanner_, cs->cs_(), out); + pj_scan_get(&scanner_, &cis->cis_, out); } void get_n(unsigned N, Pj_String *out) @@ -125,9 +181,9 @@ public: pj_scan_get_newline(&scanner_); } - void get_until(const Pj_Char_Spec *cs, Pj_String *out) + void get_until(const Pj_Cis *cis, Pj_String *out) { - pj_scan_get_until(&scanner_, cs->cs_(), out); + pj_scan_get_until(&scanner_, &cis->cis_, out); } void get_until_ch(int until_ch, Pj_String *out) @@ -160,7 +216,7 @@ public: pj_scan_skip_whitespace(&scanner_); } - void save_state(State *state) + void save_state(State *state) const { pj_scan_save_state(&scanner_, state); } @@ -177,7 +233,7 @@ public: int get_pos_col() const { - return scanner_.col; + return pj_scan_get_col(&scanner_); } |