00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef TagParser_h
00020 #define TagParser_h
00021
00022 #include <iosfwd>
00023 #include <string>
00024 #include <list>
00025 #include <vector>
00026 #include <map>
00027
00028 using std::vector;
00029 using std::map;
00030 using std::streamoff;
00031 using std::istream;
00032
00034
00035
00036
00037
00038
00039
00040 class TagParser {
00041
00042 private:
00043
00044 static const unsigned bufferLen_i;
00045 static char buffer_ac[];
00046
00047 private:
00048
00049 streamoff lookupStart_i;
00050 streamoff startTag_i;
00051 streamoff startData_i;
00052 streamoff endData_i;
00053 streamoff endTag_i;
00054
00055 std::string startTag_t;
00056 std::string endTag_t;
00057
00058 std::list<std::string> data_Vt;
00059
00060 private:
00061
00062 void _reset();
00063 void _datareset();
00064
00065 static streamoff readLine( istream & stream_fr, std::string & cline_tr );
00066 static bool tagOnLine( const std::string & cline_tr, std::string & tag_tr, std::string::size_type & delim_ir );
00067
00068 public:
00069
00070 TagParser();
00071 virtual ~TagParser();
00072
00073 static const streamoff nopos;
00074
00075 streamoff lookupStart() const { return lookupStart_i; }
00076
00077 streamoff posStartTag() const { return startTag_i; }
00078 const std::string & startTag() const { return startTag_t; }
00079
00080 streamoff posEndTag() const { return endTag_i; }
00081 const std::string & endTag() const { return endTag_t; }
00082
00083 public:
00084
00085 streamoff posDataStart()const { return startData_i; }
00086 streamoff posDataEnd() const { return endData_i; }
00087 unsigned dataLength() const { return endData_i - startData_i; }
00088 unsigned dataLines() const { return data_Vt.size(); }
00089
00090 const std::list<std::string> & data() const { return data_Vt; }
00091
00092 public:
00093
00094
00095
00096 bool lookupTag( istream & stream_fr, const std::string & stag_tr = "" );
00097
00098
00099 bool parseData( istream & stream_fr, const std::string & etag_tr );
00100
00101 static bool retrieveData( istream & stream_fr,
00102 streamoff startData_ir, streamoff endData_ir,
00103 std::string & data_tr );
00104 static bool retrieveData( istream & stream_fr,
00105 streamoff startData_ir, streamoff endData_ir,
00106 std::list<std::string> & data_Vtr );
00107 static std::string data2string( const std::list<std::string> & data_Vtr );
00108 static vector<std::string> split2words( const std::string & line_tr, const std::string & sepchars_tr = " \t\n" );
00109 };
00110
00112
00114
00115
00116
00117
00118
00119 #if 0
00120 class TagSet {
00121
00122 friend std::ostream & operator<<( std::ostream & str, const TagSet & obj );
00123
00124 private:
00125
00126 map<std::string,unsigned> lookupStart_V;
00127 vector<std::string> lookupEnd_V;
00128
00129 public:
00130
00131 static const unsigned unknowntag = (unsigned)-1;
00132
00133 TagSet() {}
00134 virtual ~TagSet() {}
00135
00136 void addTag( const std::string & start_tr, const std::string & end_tr = "" );
00137
00138 unsigned parseData( istream & in_Fr, TagParser & ctag_Cr ) const;
00139 };
00140
00142
00143 extern std::ostream & operator<<( std::ostream & str, const TagParser & obj );
00144 extern std::ostream & operator<<( std::ostream & str, const TagSet & obj );
00145
00147 #endif // #if 0
00148
00149 #endif // TagParser_h
00150
00151