3 #ifndef INCLUDE_NN_NLIB_TAGGEDTEXTPARSER_H_ 4 #define INCLUDE_NN_NLIB_TAGGEDTEXTPARSER_H_ 23 cur_ =
reinterpret_cast<unsigned char*
>(tagged_text);
26 is_elemtag_empty_ =
false;
34 NLIB_TAGGEDTEXTPARSER_NEXT:
35 if (is_elemtag_empty_) {
36 is_elemtag_empty_ =
false;
49 if (chr_ ==
'\0')
return END_DOCUMENT;
51 unsigned char* p = cur_;
53 if (c ==
'?' || c ==
'!') {
56 unsigned char* p2 = GotoGT(p);
57 if (*p2 ==
'\0')
goto NLIB_TAGGEDTEXTPARSER_ERROR;
60 cur_ = *p2 !=
'\0' ? p2 + 1 : p2;
61 goto NLIB_TAGGEDTEXTPARSER_NEXT;
62 }
else if (c ==
'/') {
66 unsigned char* p2 = SpotName(p);
68 unsigned char* p3 = GotoGT(p2);
69 if (*p3 ==
'\0')
goto NLIB_TAGGEDTEXTPARSER_ERROR;
72 text_ =
reinterpret_cast<const char*
>(p);
75 cur_ = *p3 !=
'\0' ? p3 + 1 : p3;
79 unsigned char* p2 = SpotName(p);
81 unsigned char* p3 = GotoSlashGT(p2);
82 if (*p3 ==
'\0')
goto NLIB_TAGGEDTEXTPARSER_ERROR;
86 if (*p3 !=
'>')
goto NLIB_TAGGEDTEXTPARSER_ERROR;
87 is_elemtag_empty_ =
true;
91 text_ =
reinterpret_cast<const char*
>(p);
94 cur_ = *p3 !=
'\0' ? p3 + 1 : p3;
99 unsigned char* p = cur_ - 1;
102 if (c ==
'<' || c ==
'\0') {
103 text_ =
reinterpret_cast<const char*
>(cur_ - 1);
105 cur_ = (chr_ !=
'\0') ? p + 1 : p;
106 unsigned char* pp = p - 1;
107 while (IsSpc(*pp)) --pp;
114 NLIB_TAGGEDTEXTPARSER_ERROR:
122 static bool IsSpc(
int c) {
124 static const char table[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0,
125 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
127 return (c <= 0x20 && table[c] != 0);
129 static unsigned char* SpotName(
unsigned char* p) {
130 static const char table[] = {
131 1, 0, 0, 0, 0, 0, 0, 0, 0,
133 0, 0, 0, 0, 0, 0, 0, 0, 0,
135 1, 0, 0, 0, 0, 0, 0, 0, 0,
137 0, 0, 0, 0, 0, 0, 0, 0, 0,
143 if (c < 0x40 && table[c] != 0)
return p;
147 static unsigned char* GotoGT(
unsigned char* p) {
150 if (c ==
'>' || c ==
'\0')
return p;
154 static unsigned char* GotoSlashGT(
unsigned char* p) {
157 if (c ==
'/' || c ==
'>' || c ==
'\0')
return p;
166 bool is_elemtag_empty_;
171 #endif // INCLUDE_NN_NLIB_TAGGEDTEXTPARSER_H_ TaggedTextParser(char *tagged_text)
コンストラクタです。
const char * GetText() const
GetNext()で取得した文字データへのポインタを返します。
Event Next()
次の要素やテキストを取得します。
XML風タグ付きテキストをパースする簡単なパーサーです。
#define NLIB_FINAL
利用可能であればfinalが定義されます。そうでない場合は空文字列です。