From 9cb8daac1cdcd6bdfa1a16c374d4dbcfac25df36 Mon Sep 17 00:00:00 2001 From: Myun2 Date: Wed, 28 Jul 2010 22:02:55 +0900 Subject: [PATCH] =?utf8?q?string=5Fstructure.hpp=20=E3=81=B8=E3=81=AE?= =?utf8?q?=E5=88=86=E9=9B=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- roast/include/roast/lexical/string_structure.hpp | 211 +++++++++++++++++++++++ roast/include/roast/lexical/structure_base.hpp | 191 +------------------- roast/include/roast/xml/roast_xml/structure.hpp | 2 +- 3 files changed, 214 insertions(+), 190 deletions(-) create mode 100644 roast/include/roast/lexical/string_structure.hpp diff --git a/roast/include/roast/lexical/string_structure.hpp b/roast/include/roast/lexical/string_structure.hpp new file mode 100644 index 00000000..bc1b939d --- /dev/null +++ b/roast/include/roast/lexical/string_structure.hpp @@ -0,0 +1,211 @@ +// Roast+ License +/* +*/ +#ifndef __SFJP_ROAST__lexical__string_structure_HPP__ +#define __SFJP_ROAST__lexical__string_structure_HPP__ + +#include "roast/lexical/structure_base.hpp" + +#pragma warning(disable:4503) + +namespace roast +{ + namespace lexical + { + namespace structure + { + ///////////////////////////////////////////////////////////// + + template + class unichar + { + public: + template + bool analyze(T& it, _Param& param) + { + switch(*it) + { + case _Char: + it++; + return true; + case 0: + throw 1; + //return false; + } + return false; + } + }; + + ////// +/* + template + class multichar_or + { + public: + template + bool analyze(T& it, _Param& param) + { + switch(*it) + { + case _Char: + it++; + return true; + } + return false; + } + };*/ + + /////////////////////////////////////////////////// + + /*typedef + class requre_whitespace + { + public: + template + bool analyze(T& it, _Param& param) + { + bool exist_ws = false; + for(;;) + { + //char c = it.operator *(); + switch(*it) + { + case ' ': + case '\t': + case '\r': + case '\n': + it++; + exist_ws = true; + continue; + } + + break; + } + + return exist_ws; + } + } + _reqws, reqws;*/ + + typedef or< + unichar<' '>, + unichar<'\t'>, + unichar<'\r'>, + unichar<'\n'> + > whitespace; + typedef seq > + requre_whitespace, _reqws, reqws; + typedef repeat + no_requre_whitespace, _nrqws, _noreqws, nrqws, noreqws, optws; + + ///////////////////// + + /* + typedef + class no_requre_whitespace + { + public: + template + bool analyze(T& it, _Param& param) + { + for(;;) + { + //char c = it.operator *(); + switch(*it) + { + case ' ': + case '\t': + case '\r': + case '\n': + it++; + continue; + } + + break; + } + + return true; + } + template + bool analyze(const T& it, _Param& param) + { + fail. (Cant const Iterator); + } + } + _nrqws, _noreqws, nrqws, noreqws, optws; + */ + + //////////////////////////////////////////////////////////// + + template + class get_string_by_ + { + public: + __It start_it; + __It end_it; + + template + bool analyze(T& it, _Param& param) + { + start_it = it; + + _EndProc proc; + for(;;) + { + if ( proc((const T&)start_it, (const T&)it, param) ) + break; + it++; + } + end_it = it; + return true; + } + + template + bool analyze(const T& it, _Param& param) + { + T cant const. + } + }; + + ///////////// + + template + class _get_string_end_proc_by_analyze_true + { + public: + template + bool operator()(const _It& start_it, const _It& it, _Param& param) + { + T t; + _It it_work = it; + return t.analyze(it_work, param); + } + }; + + template + class get_string_end_by_analyze_true : public get_string_by_<_get_string_end_proc_by_analyze_true<_EndAnalyzeT>, __It> + {}; + + ///////////// + + template + class get_string_end_by + { + public: + template + bool analyze(_It& it, _Param& param) + { + get_string_end_by_analyze_true gs; + if ( gs.analyze(it, param) == false ) + return false; + param << ::std::make_pair( gs.start_it, gs.end_it ); + return true; + } + }; + } + + /////////////////////////////////////// + } +} + +#endif//__SFJP_ROAST__lexical__string_structure_HPP__ diff --git a/roast/include/roast/lexical/structure_base.hpp b/roast/include/roast/lexical/structure_base.hpp index 90fc19eb..8429b72b 100644 --- a/roast/include/roast/lexical/structure_base.hpp +++ b/roast/include/roast/lexical/structure_base.hpp @@ -265,195 +265,6 @@ namespace roast } }; - ///////////////////////////////////////////////////////////// - - template - class unichar - { - public: - template - bool analyze(T& it, _Param& param) - { - switch(*it) - { - case _Char: - it++; - return true; - case 0: - throw 1; - //return false; - } - return false; - } - }; - - ////// -/* - template - class multichar_or - { - public: - template - bool analyze(T& it, _Param& param) - { - switch(*it) - { - case _Char: - it++; - return true; - } - return false; - } - };*/ - - /////////////////////////////////////////////////// - - /*typedef - class requre_whitespace - { - public: - template - bool analyze(T& it, _Param& param) - { - bool exist_ws = false; - for(;;) - { - //char c = it.operator *(); - switch(*it) - { - case ' ': - case '\t': - case '\r': - case '\n': - it++; - exist_ws = true; - continue; - } - - break; - } - - return exist_ws; - } - } - _reqws, reqws;*/ - - typedef or< - unichar<' '>, - unichar<'\t'>, - unichar<'\r'>, - unichar<'\n'> - > whitespace; - typedef seq > - requre_whitespace, _reqws, reqws; - typedef repeat - no_requre_whitespace, _nrqws, _noreqws, nrqws, noreqws, optws; - - ///////////////////// - - /* - typedef - class no_requre_whitespace - { - public: - template - bool analyze(T& it, _Param& param) - { - for(;;) - { - //char c = it.operator *(); - switch(*it) - { - case ' ': - case '\t': - case '\r': - case '\n': - it++; - continue; - } - - break; - } - - return true; - } - template - bool analyze(const T& it, _Param& param) - { - fail. (Cant const Iterator); - } - } - _nrqws, _noreqws, nrqws, noreqws, optws; - */ - - //////////////////////////////////////////////////////////// - - template - class get_string_by_ - { - public: - __It start_it; - __It end_it; - - template - bool analyze(T& it, _Param& param) - { - start_it = it; - - _EndProc proc; - for(;;) - { - if ( proc((const T&)start_it, (const T&)it, param) ) - break; - it++; - } - end_it = it; - return true; - } - - template - bool analyze(const T& it, _Param& param) - { - T cant const. - } - }; - - ///////////// - - template - class _get_string_end_proc_by_analyze_true - { - public: - template - bool operator()(const _It& start_it, const _It& it, _Param& param) - { - T t; - _It it_work = it; - return t.analyze(it_work, param); - } - }; - - template - class get_string_end_by_analyze_true : public get_string_by_<_get_string_end_proc_by_analyze_true<_EndAnalyzeT>, __It> - {}; - - ///////////// - - template - class get_string_end_by - { - public: - template - bool analyze(_It& it, _Param& param) - { - get_string_end_by_analyze_true gs; - if ( gs.analyze(it, param) == false ) - return false; - param << ::std::make_pair( gs.start_it, gs.end_it ); - return true; - } - }; - //////////////////////////////////////////////////////////// template @@ -507,6 +318,7 @@ namespace roast /////////////////////////////////////// + /* template class structure_base { @@ -517,6 +329,7 @@ namespace roast return ( *s == '>' ); } }; + */ } } diff --git a/roast/include/roast/xml/roast_xml/structure.hpp b/roast/include/roast/xml/roast_xml/structure.hpp index b9e0beca..25587a93 100644 --- a/roast/include/roast/xml/roast_xml/structure.hpp +++ b/roast/include/roast/xml/roast_xml/structure.hpp @@ -6,7 +6,7 @@ #define __SFJP_ROAST__xml__roast_xml__roast_xml_HPP__ #include "roast/lexical/base.hpp" -#include "roast/lexical/structure_base.hpp" +#include "roast/lexical/string_structure.hpp" #include "roast/str/sized_charbuf.hpp" namespace roast -- 2.11.0