| 3218 | } |
| 3219 | |
| 3220 | char_t* parse_tree(char_t* s, xml_node_struct* root, unsigned int optmsk, char_t endch) |
| 3221 | { |
| 3222 | strconv_attribute_t strconv_attribute = get_strconv_attribute(optmsk); |
| 3223 | strconv_pcdata_t strconv_pcdata = get_strconv_pcdata(optmsk); |
| 3224 | |
| 3225 | char_t ch = 0; |
| 3226 | xml_node_struct* cursor = root; |
| 3227 | char_t* mark = s; |
| 3228 | |
| 3229 | while (*s != 0) |
| 3230 | { |
| 3231 | if (*s == '<') |
| 3232 | { |
| 3233 | ++s; |
| 3234 | |
| 3235 | LOC_TAG: |
| 3236 | if (PUGI__IS_CHARTYPE(*s, ct_start_symbol)) // '<#...' |
| 3237 | { |
| 3238 | PUGI__PUSHNODE(node_element); // Append a new node to the tree. |
| 3239 | |
| 3240 | cursor->name = s; |
| 3241 | |
| 3242 | PUGI__SCANWHILE_UNROLL(PUGI__IS_CHARTYPE(ss, ct_symbol)); // Scan for a terminator. |
| 3243 | PUGI__ENDSEG(); // Save char in 'ch', terminate & step over. |
| 3244 | |
| 3245 | if (ch == '>') |
| 3246 | { |
| 3247 | // end of tag |
| 3248 | } |
| 3249 | else if (PUGI__IS_CHARTYPE(ch, ct_space)) |
| 3250 | { |
| 3251 | LOC_ATTRIBUTES: |
| 3252 | while (true) |
| 3253 | { |
| 3254 | PUGI__SKIPWS(); // Eat any whitespace. |
| 3255 | |
| 3256 | if (PUGI__IS_CHARTYPE(*s, ct_start_symbol)) // <... #... |
| 3257 | { |
| 3258 | xml_attribute_struct* a = append_new_attribute(cursor, *alloc); // Make space for this attribute. |
| 3259 | if (!a) PUGI__THROW_ERROR(status_out_of_memory, s); |
| 3260 | |
| 3261 | a->name = s; // Save the offset. |
| 3262 | |
| 3263 | PUGI__SCANWHILE_UNROLL(PUGI__IS_CHARTYPE(ss, ct_symbol)); // Scan for a terminator. |
| 3264 | PUGI__ENDSEG(); // Save char in 'ch', terminate & step over. |
| 3265 | |
| 3266 | if (PUGI__IS_CHARTYPE(ch, ct_space)) |
| 3267 | { |
| 3268 | PUGI__SKIPWS(); // Eat any whitespace. |
| 3269 | |
| 3270 | ch = *s; |
| 3271 | ++s; |
| 3272 | } |
| 3273 | |
| 3274 | if (ch == '=') // '<... #=...' |
| 3275 | { |
| 3276 | PUGI__SKIPWS(); // Eat any whitespace. |
| 3277 | |