{
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>
};
///////////////////////////////////////////////////////////////////
-
- 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;
- }
- };
-
- ///////////////////////////////////////////////////////////////////
}
}
}