00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef TaggedParser_h
00023 #define TaggedParser_h
00024
00025 #include <iosfwd>
00026 #include <string>
00027 #include <list>
00028 #include <vector>
00029 #include <map>
00030
00031 using std::vector;
00032 using std::map;
00033 using std::streamoff;
00034 using std::istream;
00035
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 class TaggedParser {
00060 public:
00061 enum tag_type {
00062 NONE=0,
00063 SINGLE,
00064 START,
00065 END,
00066 OLDSINGLE,
00067 OLDMULTI
00068 };
00069 typedef tag_type TagType;
00070
00071 private:
00072
00073 static const unsigned bufferLen_i;
00074 static char buffer_ac[];
00075
00076 std::string currentLine;
00077
00078 private:
00079
00080 streamoff _tagPos;
00081 streamoff _startPos;
00082 streamoff _endPos;
00083
00084 int _bufferPos;
00085 unsigned int _bufferLen;
00086
00087 int _lineNumber;
00088
00089 std::string _currentTag;
00090 std::string _currentLocale;
00091 std::string _currentData;
00092
00093 bool _oldstyle;
00094
00095
00096 int _offset;
00097
00098 private:
00099
00100 void _reset();
00101 void _datareset();
00102
00103
00104 static streamoff readLine (istream & stream_fr, std::string & cline_tr );
00105
00106
00107 TagType tagOnLine (const std::string & cline_tr, std::string & tag_tr,
00108 std::string::size_type & delim_ir, std::string & lang_tr);
00109
00110 public:
00111
00112 TaggedParser();
00113 virtual ~TaggedParser();
00114
00115 void asOldstyle (bool oldstyle) { _oldstyle = oldstyle; _offset = (oldstyle?0:1); }
00116 static const streamoff nopos;
00117
00118 int lineNumber () const { return _lineNumber; }
00119
00120 streamoff tagPos() const { return _tagPos; }
00121 const std::string & currentTag() const { return _currentTag; }
00122 const std::string & currentLocale() const { return _currentLocale; }
00123
00124 public:
00125
00126 streamoff dataStartPos () const { return _startPos; }
00127 streamoff dataEndPos () const { return _endPos; }
00128 unsigned dataLength () const { return _endPos - _startPos; }
00129
00130
00131 const std::string& data() { return (_currentData = currentLine.substr (_bufferPos, _bufferLen)); }
00132
00133 public:
00134
00141 TagType lookupTag( istream & stream_fr, const std::string & stag_tr = "", const std::string & slang_tr = "");
00142
00147 TagType lookupEndTag ( istream & stream_fr, const std::string & etag_tr,
00148 const std::string & elang_tr = "", bool reverseLocale = false );
00149
00150
00151 static std::string data2string( const std::list<std::string> & data_Vtr );
00152 static vector<std::string> split2words( const std::string & line_tr, const std::string & sepchars_tr = " \t\n" );
00153 };
00154
00155 #endif // TaggedParser_h
00156
00157