| 283 | // ---------------------------------------------------------------------------------------- |
| 284 | |
| 285 | void xml_parser:: |
| 286 | parse ( |
| 287 | std::istream& in |
| 288 | ) |
| 289 | { |
| 290 | DLIB_CASSERT ( in.fail() == false , |
| 291 | "\tvoid xml_parser::parse" |
| 292 | << "\n\tthe input stream must not be in the fail state" |
| 293 | << "\n\tthis: " << this |
| 294 | ); |
| 295 | |
| 296 | |
| 297 | // save which exceptions in will throw and make it so it won't throw any |
| 298 | // for the life of this function |
| 299 | std::ios::iostate old_exceptions = in.exceptions(); |
| 300 | // set it to not throw anything |
| 301 | in.exceptions(std::ios::goodbit); |
| 302 | |
| 303 | |
| 304 | try |
| 305 | { |
| 306 | unsigned long line_number = 1; |
| 307 | |
| 308 | // skip any whitespace before the start of the document |
| 309 | while (in.peek() == ' ' || in.peek() == '\t' || in.peek() == '\n' || in.peek() == '\r' ) |
| 310 | { |
| 311 | if (in.peek() == '\n') |
| 312 | ++line_number; |
| 313 | in.get(); |
| 314 | } |
| 315 | |
| 316 | |
| 317 | |
| 318 | stack tags; // this stack contains the last start tag seen |
| 319 | bool seen_fatal_error = false; |
| 320 | bool seen_root_tag = false; // this is true after we have seen the root tag |
| 321 | |
| 322 | |
| 323 | |
| 324 | // notify all the document_handlers that we are about to being parsing |
| 325 | for (unsigned long i = 0; i < dh_list.size(); ++i) |
| 326 | { |
| 327 | dh_list[i]->start_document(); |
| 328 | } |
| 329 | |
| 330 | |
| 331 | std::string chars_buf; // used to collect chars data between consecutive |
| 332 | // chars and chars_cdata tokens so that |
| 333 | // document_handlers receive all chars data between |
| 334 | // tags in one call |
| 335 | |
| 336 | // variables to be used with the parsing functions |
| 337 | attrib_list atts; |
| 338 | std::string name; |
| 339 | std::string target; |
| 340 | std::string data; |
| 341 | |
| 342 |
nothing calls this directly
no test coverage detected