16 #ifndef INCLUDE_NN_NLIB_TAGGEDTEXTPARSER_H_ 17 #define INCLUDE_NN_NLIB_TAGGEDTEXTPARSER_H_ 33 START_ELEMENT = kStartElement,
34 END_ELEMENT = kEndElement,
35 CHARACTERS = kCharacters,
36 END_DOCUMENT = kEndDocument,
37 SYNTAX_ERROR = kSyntaxError
42 cur_ =
reinterpret_cast<unsigned char*
>(tagged_text);
45 is_elemtag_empty_ =
false;
53 NLIB_TAGGEDTEXTPARSER_NEXT:
54 if (is_elemtag_empty_) {
55 is_elemtag_empty_ =
false;
68 if (chr_ ==
'\0')
return kEndDocument;
70 unsigned char* p = cur_;
72 if (c ==
'?' || c ==
'!') {
75 unsigned char* p2 = GotoGT(p);
76 if (*p2 ==
'\0')
goto NLIB_TAGGEDTEXTPARSER_ERROR;
79 cur_ = *p2 !=
'\0' ? p2 + 1 : p2;
80 goto NLIB_TAGGEDTEXTPARSER_NEXT;
81 }
else if (c ==
'/') {
85 unsigned char* p2 = SpotName(p);
87 unsigned char* p3 = GotoGT(p2);
88 if (*p3 ==
'\0')
goto NLIB_TAGGEDTEXTPARSER_ERROR;
91 text_ =
reinterpret_cast<const char*
>(p);
94 cur_ = *p3 !=
'\0' ? p3 + 1 : p3;
98 unsigned char* p2 = SpotName(p);
100 unsigned char* p3 = GotoSlashGT(p2);
101 if (*p3 ==
'\0')
goto NLIB_TAGGEDTEXTPARSER_ERROR;
105 if (*p3 !=
'>')
goto NLIB_TAGGEDTEXTPARSER_ERROR;
106 is_elemtag_empty_ =
true;
110 text_ =
reinterpret_cast<const char*
>(p);
113 cur_ = *p3 !=
'\0' ? p3 + 1 : p3;
114 return kStartElement;
118 unsigned char* p = cur_ - 1;
121 if (c ==
'<' || c ==
'\0') {
122 text_ =
reinterpret_cast<const char*
>(cur_ - 1);
124 cur_ = (chr_ !=
'\0') ? p + 1 : p;
125 unsigned char* pp = p - 1;
126 while (IsSpc(*pp)) --pp;
133 NLIB_TAGGEDTEXTPARSER_ERROR:
141 static bool IsSpc(
int c) {
143 static const char table[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0,
144 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
146 return (c <= 0x20 && table[c] != 0);
148 static unsigned char* SpotName(
unsigned char* p) {
149 static const char table[] = {
150 1, 0, 0, 0, 0, 0, 0, 0, 0,
152 0, 0, 0, 0, 0, 0, 0, 0, 0,
154 1, 0, 0, 0, 0, 0, 0, 0, 0,
156 0, 0, 0, 0, 0, 0, 0, 0, 0,
162 if (c < 0x40 && table[c] != 0)
return p;
166 static unsigned char* GotoGT(
unsigned char* p) {
169 if (c ==
'>' || c ==
'\0')
return p;
173 static unsigned char* GotoSlashGT(
unsigned char* p) {
176 if (c ==
'/' || c ==
'>' || c ==
'\0')
return p;
185 bool is_elemtag_empty_;
190 #endif // INCLUDE_NN_NLIB_TAGGEDTEXTPARSER_H_ TaggedTextParser(char *tagged_text)
コンストラクタです。
const char * GetText() const
GetNext()で取得した文字データへのポインタを返します。
Event Next()
次の要素やテキストを取得します。
XML風タグ付きテキストをパースする簡単なパーサーです。
#define NLIB_FINAL
利用可能であればfinalが定義されます。そうでない場合は空文字列です。