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);
+ bool b = t.analyze(it, param);
+
+ if ( b ){
+ if ( *it == '\r' )
+ param << _cr_t;
+ else if ( *it == '\n' )
+ param << _lf_t;
+ }
+ return b;
}
template <typename T, typename _Param>
bool generate(const T&, const _Param&){ return true; }
////
- template <typename T>
+ class line_counter_docbase
+ {
+ protected:
+ unsigned 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_is_prev_cr )
+ m_line_count++;
+ m_is_prev_cr = false;
+ }
+ void operator << (const _cr_t_&){
+ m_line_count++;
+ m_is_prev_cr = true;
+ }
+
+ unsigned int get_line(){ return m_line_count; }
+ };
+ /*template <typename T>
class line_counter_docbase_
{
protected:
m_is_prev_cr = false;
}
void operator << (const _lf_t_&){
- if ( m_prev_char != '\r' )
+ if ( m_is_prev_cr )
m_line_count++;
m_is_prev_cr = false;
}
m_line_count++;
m_is_prev_cr = true;
}
- };
+ };*/
/////////////////////////////////////////////////////////////
unichar<' '>,
unichar<'\t'>,
chars::line_countable_crlf
- > line_countable_whitespace;
+ > line_countable_whitespace, lc_whitespace;
typedef seq<line_countable_whitespace, optional_repeat<line_countable_whitespace> >
lc_requre__whitespace, _lcreqws, lcreqws;
typedef optional_repeat<line_countable_whitespace>
template <typename _It, typename _Param>
bool operator()(const _It& start_it, const _It& it, _Param& param)
{
- T t;
+ line_countable<T> t;
_It it_work = it;
return t.analyze(it_work, param);
}
seq<lesser, header_internal, greater>
header, xmldecl;
- //////////////////////////////////////////////////////
+ ///////////////////////////////////////////////
- // No Elements
-
- class noelems : public seq<lcnrqws, optional<comment>, lcnrqws> {};
+ // No Means (Whitespace and Comments)
+ class nomeans : public seq<lcnrqws, optional<comment>, lcnrqws> {};
template <typename T>
- class noelems_ : public seq<noelems, T>{};
+ class nomeans_ : public seq<nomeans, T>{};
+
+ ////
// XML Document Rule
-
typedef ::roast::lexical::rule::seq
<
- rule::noelems_<rule::header>,
- rule::noelems_<rule::body>,
- rule::noelems
+ rule::nomeans_<rule::header>,
+ rule::nomeans_<rule::body>,
+ rule::nomeans
> _rule;
}
///////
- template <typename _SaxCallback, bool _ValidateCheck=true>
- class sax_impl_ : public _SaxCallback
+ template <typename _SaxCallback, bool _ValidateCheck=false, bool _DetailInfos=true>
+ class sax_impl_ : public _SaxCallback, public lexical::rule::line_counter_docbase
{
private:
int m_code;
sax_impl_(){ m_code = rule::pcode::_null; }
sax_impl_(_SaxCallback &sub) : _SaxCallback(sub){}
+ void operator << (const lexical::rule::_lf_t_&){ lexical::rule::line_counter_docbase::operator <<(lexical::rule::_lf_t_()); }
+ void operator << (const lexical::rule::_cr_t_&){ lexical::rule::line_counter_docbase::operator <<(lexical::rule::_cr_t_()); }
+
template <typename _It>
void operator << ( const ::std::pair<_It, _It> &p )
{
void end_element( const sized_ccharbuf &s ){}
};
-typedef sax_impl_<_test_sax_impl> test_sax_impl;
-typedef sax_impl_<_speed_test_sax_impl> speed_test_sax_impl;
\ No newline at end of file
+//typedef sax_impl_<_test_sax_impl> test_sax_impl;
+//typedef sax_impl_<_speed_test_sax_impl> speed_test_sax_impl;
+static sax_impl_<_test_sax_impl> test_sax_impl;
+static sax_impl_<_speed_test_sax_impl> speed_test_sax_impl;
{
try
{
- FILE* fp = fopen("big_xml.xml","r");
+ FILE* fp = fopen("temp.xml","r");
char* work = new char [BUF_SIZE];
memset(work,0,BUF_SIZE);
fread(work,1,BUF_SIZE,fp);
printf("start:%d\n", clock());
sax sx;
- sx.analyze((const char*)work, speed_test_sax_impl());
+ sx.analyze((const char*)work, speed_test_sax_impl);
printf("end:%d\n", clock());
+ printf("lines:%d\n", speed_test_sax_impl.get_line());
/*
//printf(work);