3 #ifndef INCLUDE_NN_NLIB_TAGGEDTEXTPARSER_H_
4 #define INCLUDE_NN_NLIB_TAGGEDTEXTPARSER_H_
23 m_Cur =
reinterpret_cast<unsigned char*
>(taggedText);
26 m_IsEmptyElemTag =
false;
34 NLIB_TAGGEDTEXTPARSER_NEXT:
35 if (m_IsEmptyElemTag) {
36 m_IsEmptyElemTag =
false;
49 if (m_Chr ==
'\0')
return END_DOCUMENT;
51 unsigned char* p = m_Cur;
53 if (c ==
'?' || c ==
'!') {
56 unsigned char* p2 = GotoGT(p);
57 if (*p2 ==
'\0')
goto NLIB_TAGGEDTEXTPARSER_ERROR;
60 m_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 m_Text =
reinterpret_cast<const char*
>(p);
75 m_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 m_IsEmptyElemTag =
true;
91 m_Text =
reinterpret_cast<const char*
>(p);
94 m_Cur = *p3 !=
'\0' ? p3 + 1 : p3;
99 unsigned char* p = m_Cur - 1;
102 if (c ==
'<' || c ==
'\0') {
103 m_Text =
reinterpret_cast<const char*
>(m_Cur - 1);
105 m_Cur = (m_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;
164 unsigned char* m_Cur;
166 bool m_IsEmptyElemTag;
171 #endif // INCLUDE_NN_NLIB_TAGGEDTEXTPARSER_H_
const char * GetText() const
GetNext()で取得した文字データへのポインタを返します。
#define NLIB_FINAL
利用可能であればfinalが定義されます。そうでない場合は空文字列です。
TaggedTextParser(char *taggedText)
コンストラクタです。
Event Next()
次の要素やテキストを取得します。
XML風タグ付きテキストをパースする簡単なパーサーです。