OSDN Git Service

lexical/string_rule.hpp: line_counter を最初の方へ移動。で、line_countableを実装してみた。
authorMyun2 <myun2@nwhite.info>
Sun, 10 Oct 2010 17:05:27 +0000 (02:05 +0900)
committerMyun2 <myun2@nwhite.info>
Sun, 10 Oct 2010 17:05:27 +0000 (02:05 +0900)
roast/include/roast/lexical/string_rule.hpp

index 49c70b4..7fb598c 100644 (file)
@@ -14,6 +14,55 @@ namespace roast
        {
                namespace rule
                {
+                       ///////////////////////////////////////////////////////////////////
+
+                       struct _cr_t_{} _cr_t;
+                       struct _lf_t_{} _lf_t;
+
+                       template <typename T>
+                       class line_countable
+                       {
+                       public:
+                               template <typename _It, typename _Param>
+                               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 <typename T, typename _Param>
+                               bool generate(const T&, const _Param&){ return true; }
+                       };
+
+                       ////
+
+                       template <typename T>
+                       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 <int _Char>
@@ -226,52 +275,6 @@ namespace roast
                        };
 
                        ///////////////////////////////////////////////////////////////////
-
-                       struct _lf_t{};
-                       struct _cr_t{};
-
-                       template <typename T>
-                       class line_counter
-                       {
-                       public:
-                               template <typename _It, typename _Param>
-                               bool analyze(_It& it, _Param& param)
-                               {
-                                       for(const char* p=m_str; *p!='\0'; p++, it++)
-                                       {
-                                               if ( *it != *p )
-                                                       return false;
-                                       }
-                                       return true;
-                               }
-                               template <typename T, typename _Param>
-                               bool generate(const T&, const _Param&){ return true; }
-                       };
-
-                       template <typename T>
-                       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;
-                               }
-                       };
-
-                       ///////////////////////////////////////////////////////////////////
                }
        }
 }