| 675 | #endif |
| 676 | |
| 677 | const char* TiXmlDocument::Parse(const char* p, TiXmlParsingData* prevData, TiXmlEncoding encoding) |
| 678 | { |
| 679 | ClearError(); |
| 680 | |
| 681 | // Parse away, at the document level. Since a document |
| 682 | // contains nothing but other tags, most of what happens |
| 683 | // here is skipping white space. |
| 684 | if (!p || !*p) |
| 685 | { |
| 686 | SetError(TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN); |
| 687 | return 0; |
| 688 | } |
| 689 | |
| 690 | // Note that, for a document, this needs to come |
| 691 | // before the while space skip, so that parsing |
| 692 | // starts from the pointer we are given. |
| 693 | location.Clear(); |
| 694 | if (prevData) |
| 695 | { |
| 696 | location.row = prevData->cursor.row; |
| 697 | location.col = prevData->cursor.col; |
| 698 | } |
| 699 | else |
| 700 | { |
| 701 | location.row = 0; |
| 702 | location.col = 0; |
| 703 | } |
| 704 | TiXmlParsingData data(p, TabSize(), location.row, location.col); |
| 705 | location = data.Cursor(); |
| 706 | |
| 707 | if (encoding == TIXML_ENCODING_UNKNOWN) |
| 708 | { |
| 709 | // Check for the Microsoft UTF-8 lead bytes. |
| 710 | const unsigned char* pU = (const unsigned char*)p; |
| 711 | if (*(pU + 0) && *(pU + 0) == TIXML_UTF_LEAD_0 && *(pU + 1) && *(pU + 1) == TIXML_UTF_LEAD_1 && *(pU + 2) && *(pU + 2) == TIXML_UTF_LEAD_2) |
| 712 | { |
| 713 | encoding = TIXML_ENCODING_UTF8; |
| 714 | useMicrosoftBOM = true; |
| 715 | } |
| 716 | } |
| 717 | |
| 718 | p = SkipWhiteSpace(p, encoding); |
| 719 | if (!p) |
| 720 | { |
| 721 | SetError(TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN); |
| 722 | return 0; |
| 723 | } |
| 724 | |
| 725 | while (p && *p) |
| 726 | { |
| 727 | TiXmlNode* node = Identify(p, encoding); |
| 728 | if (node) |
| 729 | { |
| 730 | p = node->Parse(p, &data, encoding); |
| 731 | LinkEndChild(node); |
| 732 | } |
| 733 | else |
| 734 | { |
no test coverage detected