| 703 | #endif |
| 704 | |
| 705 | const char* TiXmlDocument::Parse( const char* p, TiXmlParsingData* prevData, TiXmlEncoding encoding ) |
| 706 | { |
| 707 | ClearError(); |
| 708 | |
| 709 | // Parse away, at the document level. Since a document |
| 710 | // contains nothing but other tags, most of what happens |
| 711 | // here is skipping white space. |
| 712 | if ( !p || !*p ) |
| 713 | { |
| 714 | SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN ); |
| 715 | return 0; |
| 716 | } |
| 717 | |
| 718 | // Note that, for a document, this needs to come |
| 719 | // before the while space skip, so that parsing |
| 720 | // starts from the pointer we are given. |
| 721 | location.Clear(); |
| 722 | if ( prevData ) |
| 723 | { |
| 724 | location.row = prevData->cursor.row; |
| 725 | location.col = prevData->cursor.col; |
| 726 | } |
| 727 | else |
| 728 | { |
| 729 | location.row = 0; |
| 730 | location.col = 0; |
| 731 | } |
| 732 | TiXmlParsingData data( p, TabSize(), location.row, location.col ); |
| 733 | location = data.Cursor(); |
| 734 | |
| 735 | if ( encoding == TIXML_ENCODING_UNKNOWN ) |
| 736 | { |
| 737 | // Check for the Microsoft UTF-8 lead bytes. |
| 738 | const unsigned char* pU = (const unsigned char*)p; |
| 739 | if ( *(pU+0) && *(pU+0) == TIXML_UTF_LEAD_0 |
| 740 | && *(pU+1) && *(pU+1) == TIXML_UTF_LEAD_1 |
| 741 | && *(pU+2) && *(pU+2) == TIXML_UTF_LEAD_2 ) |
| 742 | { |
| 743 | encoding = TIXML_ENCODING_UTF8; |
| 744 | useMicrosoftBOM = true; |
| 745 | } |
| 746 | } |
| 747 | |
| 748 | p = SkipWhiteSpace( p, encoding ); |
| 749 | if ( !p ) |
| 750 | { |
| 751 | SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN ); |
| 752 | return 0; |
| 753 | } |
| 754 | |
| 755 | while ( p && *p ) |
| 756 | { |
| 757 | TiXmlNode* node = Identify( p, encoding ); |
| 758 | if ( node ) |
| 759 | { |
| 760 | p = node->Parse( p, &data, encoding ); |
| 761 | LinkEndChild( node ); |
| 762 | } |