16 #ifndef INCLUDE_NN_NLIB_TAGGEDTEXTPARSER_H_ 17 #define INCLUDE_NN_NLIB_TAGGEDTEXTPARSER_H_ 36 cur_ =
reinterpret_cast<unsigned char*
>(tagged_text);
39 is_elemtag_empty_ =
false;
47 NLIB_TAGGEDTEXTPARSER_NEXT:
48 if (is_elemtag_empty_) {
49 is_elemtag_empty_ =
false;
62 if (chr_ ==
'\0')
return kEndDocument;
64 unsigned char* p = cur_;
66 if (c ==
'?' || c ==
'!') {
69 unsigned char* p2 = GotoGT(p);
70 if (*p2 ==
'\0')
goto NLIB_TAGGEDTEXTPARSER_ERROR;
73 cur_ = *p2 !=
'\0' ? p2 + 1 : p2;
74 goto NLIB_TAGGEDTEXTPARSER_NEXT;
75 }
else if (c ==
'/') {
79 unsigned char* p2 = SpotName(p);
81 unsigned char* p3 = GotoGT(p2);
82 if (*p3 ==
'\0')
goto NLIB_TAGGEDTEXTPARSER_ERROR;
85 text_ =
reinterpret_cast<const char*
>(p);
88 cur_ = *p3 !=
'\0' ? p3 + 1 : p3;
92 unsigned char* p2 = SpotName(p);
94 unsigned char* p3 = GotoSlashGT(p2);
95 if (*p3 ==
'\0')
goto NLIB_TAGGEDTEXTPARSER_ERROR;
99 if (*p3 !=
'>')
goto NLIB_TAGGEDTEXTPARSER_ERROR;
100 is_elemtag_empty_ =
true;
104 text_ =
reinterpret_cast<const char*
>(p);
107 cur_ = *p3 !=
'\0' ? p3 + 1 : p3;
108 return kStartElement;
112 unsigned char* p = cur_ - 1;
115 if (c ==
'<' || c ==
'\0') {
116 text_ =
reinterpret_cast<const char*
>(cur_ - 1);
118 cur_ = (chr_ !=
'\0') ? p + 1 : p;
119 unsigned char* pp = p - 1;
120 while (IsSpc(*pp)) --pp;
127 NLIB_TAGGEDTEXTPARSER_ERROR:
135 static bool IsSpc(
int c) {
137 static const char table[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0,
138 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
140 return (c <= 0x20 && table[c] != 0);
142 static unsigned char* SpotName(
unsigned char* p) {
143 static const char table[] = {
144 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0,
145 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
146 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
147 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0
152 if (c < 0x40 && table[c] != 0)
return p;
156 static unsigned char* GotoGT(
unsigned char* p) {
159 if (c ==
'>' || c ==
'\0')
return p;
163 static unsigned char* GotoSlashGT(
unsigned char* p) {
166 if (c ==
'/' || c ==
'>' || c ==
'\0')
return p;
175 bool is_elemtag_empty_;
180 #endif // INCLUDE_NN_NLIB_TAGGEDTEXTPARSER_H_ TaggedTextParser(char *tagged_text)
Instantiates the object.
const char * GetText() const
Returns the pointer to the character data obtained by the GetNext function.
Event Next()
Gets the next element or text.
A simple parser for parsing XML-like tagged text.
A file that contains the configuration information for each development environment.
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.