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