From 9c9b5279b2046fc4741429f66096557fddada9fe Mon Sep 17 00:00:00 2001 From: Myun2 Date: Mon, 11 Oct 2010 02:05:27 +0900 Subject: [PATCH] =?utf8?q?lexical/string=5Frule.hpp:=20line=5Fcounter=20?= =?utf8?q?=E3=82=92=E6=9C=80=E5=88=9D=E3=81=AE=E6=96=B9=E3=81=B8=E7=A7=BB?= =?utf8?q?=E5=8B=95=E3=80=82=E3=81=A7=E3=80=81line=5Fcountable=E3=82=92?= =?utf8?q?=E5=AE=9F=E8=A3=85=E3=81=97=E3=81=A6=E3=81=BF=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- roast/include/roast/lexical/string_rule.hpp | 95 +++++++++++++++-------------- 1 file changed, 49 insertions(+), 46 deletions(-) diff --git a/roast/include/roast/lexical/string_rule.hpp b/roast/include/roast/lexical/string_rule.hpp index 49c70b47..7fb598c9 100644 --- a/roast/include/roast/lexical/string_rule.hpp +++ b/roast/include/roast/lexical/string_rule.hpp @@ -14,6 +14,55 @@ namespace roast { namespace rule { + /////////////////////////////////////////////////////////////////// + + struct _cr_t_{} _cr_t; + struct _lf_t_{} _lf_t; + + template + class line_countable + { + public: + template + bool analyze(_It& it, _Param& param) + { + if ( *it == '\r' ) + param << _cr_t; + if ( *it == '\n' ) + param << _lf_t; + + T t; + return t.analyze(it, param); + } + template + bool generate(const T&, const _Param&){ return true; } + }; + + //// + + template + class line_counter_docbase_ + { + protected: + int m_line_count; + private: + bool m_is_prev_cr; + public: + line_counter_docbase_(){ + m_line_count = 1; + m_is_prev_cr = false; + } + void operator << (const _lf_t_&){ + if ( m_prev_char != '\r' ) + m_line_count++; + m_is_prev_cr = false; + } + void operator << (const _cr_t_&){ + m_line_count++; + m_is_prev_cr = true; + } + }; + ///////////////////////////////////////////////////////////// template @@ -226,52 +275,6 @@ namespace roast }; /////////////////////////////////////////////////////////////////// - - struct _lf_t{}; - struct _cr_t{}; - - template - class line_counter - { - public: - template - bool analyze(_It& it, _Param& param) - { - for(const char* p=m_str; *p!='\0'; p++, it++) - { - if ( *it != *p ) - return false; - } - return true; - } - template - bool generate(const T&, const _Param&){ return true; } - }; - - template - class line_counter_docbase_ - { - protected: - int m_line_count; - private: - bool m_is_prev_cr; - public: - line_counter_docbase_(){ - m_line_count = 1; - m_is_prev_cr = false; - } - void operator << (const _lf_t&){ - if ( m_prev_char != '\r' ) - m_line_count++; - m_is_prev_cr = false; - } - void operator << (const _cr_t&){ - m_line_count++; - m_is_prev_cr = true; - } - }; - - /////////////////////////////////////////////////////////////////// } } } -- 2.11.0