1562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project/*
2562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Projectwww.sourceforge.net/projects/tinyxml
3562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source ProjectOriginal code (2.0 and earlier )copyright (c) 2000-2002 Lee Thomason (www.grinninglizard.com)
4562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
5562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source ProjectThis software is provided 'as-is', without any express or implied
6562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Projectwarranty. In no event will the authors be held liable for any
7562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Projectdamages arising from the use of this software.
8562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
9562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source ProjectPermission is granted to anyone to use this software for any
10562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Projectpurpose, including commercial applications, and to alter it and
11562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Projectredistribute it freely, subject to the following restrictions:
12562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
13562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project1. The origin of this software must not be misrepresented; you must
14562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Projectnot claim that you wrote the original software. If you use this
15562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Projectsoftware in a product, an acknowledgment in the product documentation
16562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Projectwould be appreciated but is not required.
17562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
18562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project2. Altered source versions must be plainly marked as such, and
19562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Projectmust not be misrepresented as being the original software.
20562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
21562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project3. This notice may not be removed or altered from any source
22562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Projectdistribution.
23562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project*/
24562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
25562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project#include "tinyxml.h"
26562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project#include <ctype.h>
27562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project#include <stddef.h>
28562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
29562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project//#define DEBUG_PARSER
30562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
31562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project// Note tha "PutString" hardcodes the same list. This
32562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project// is less flexible than it appears. Changing the entries
33562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project// or order will break putstring.
34562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source ProjectTiXmlBase::Entity TiXmlBase::entity[ NUM_ENTITY ] =
35562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project{
36562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{ "&amp;",  5, '&' },
37562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{ "&lt;",   4, '<' },
38562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{ "&gt;",   4, '>' },
39562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{ "&quot;", 6, '\"' },
40562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{ "&apos;", 6, '\'' }
41562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project};
42562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
43562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project// Bunch of unicode info at:
44562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project//		http://www.unicode.org/faq/utf_bom.html
45562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project// Including the basic of this table, which determines the #bytes in the
46562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project// sequence from the lead byte. 1 placed for invalid sequences --
47562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project// although the result will be junk, pass it through as much as possible.
48562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project// Beware of the non-characters in UTF-8:
49562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project//				ef bb bf (Microsoft "lead bytes")
50562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project//				ef bf be
51562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project//				ef bf bf
52562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
53562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Projectconst unsigned char TIXML_UTF_LEAD_0 = 0xefU;
54562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Projectconst unsigned char TIXML_UTF_LEAD_1 = 0xbbU;
55562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Projectconst unsigned char TIXML_UTF_LEAD_2 = 0xbfU;
56562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
57562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Projectconst int TiXmlBase::utf8ByteTable[256] =
58562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project{
59562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	//	0	1	2	3	4	5	6	7	8	9	a	b	c	d	e	f
60562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	// 0x00
61562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	// 0x10
62562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	// 0x20
63562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	// 0x30
64562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	// 0x40
65562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	// 0x50
66562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	// 0x60
67562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	// 0x70	End of ASCII range
68562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	// 0x80 0x80 to 0xc1 invalid
69562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	// 0x90
70562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	// 0xa0
71562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	// 0xb0
72562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		1,	1,	2,	2,	2,	2,	2,	2,	2,	2,	2,	2,	2,	2,	2,	2,	// 0xc0 0xc2 to 0xdf 2 byte
73562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		2,	2,	2,	2,	2,	2,	2,	2,	2,	2,	2,	2,	2,	2,	2,	2,	// 0xd0
74562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		3,	3,	3,	3,	3,	3,	3,	3,	3,	3,	3,	3,	3,	3,	3,	3,	// 0xe0 0xe0 to 0xef 3 byte
75562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		4,	4,	4,	4,	4,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1	// 0xf0 0xf0 to 0xf4 4 byte, 0xf5 and higher invalid
76562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project};
77562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
78562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
79562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Projectvoid TiXmlBase::ConvertUTF32ToUTF8( unsigned long input, char* output, int* length )
80562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project{
81562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	const unsigned long BYTE_MASK = 0xBF;
82562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	const unsigned long BYTE_MARK = 0x80;
83562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	const unsigned long FIRST_BYTE_MARK[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
84562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
85562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	if (input < 0x80)
86562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		*length = 1;
87562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	else if ( input < 0x800 )
88562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		*length = 2;
89562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	else if ( input < 0x10000 )
90562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		*length = 3;
91562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	else if ( input < 0x200000 )
92562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		*length = 4;
93562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	else
94562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		{ *length = 0; return; }	// This code won't covert this correctly anyway.
95562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
96562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	output += *length;
97562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
98562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	// Scary scary fall throughs.
99562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	switch (*length)
100562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
101562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		case 4:
102562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			--output;
103562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			*output = (char)((input | BYTE_MARK) & BYTE_MASK);
104562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			input >>= 6;
105562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		case 3:
106562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			--output;
107562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			*output = (char)((input | BYTE_MARK) & BYTE_MASK);
108562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			input >>= 6;
109562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		case 2:
110562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			--output;
111562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			*output = (char)((input | BYTE_MARK) & BYTE_MASK);
112562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			input >>= 6;
113562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		case 1:
114562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			--output;
115562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			*output = (char)(input | FIRST_BYTE_MARK[*length]);
116562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
117562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project}
118562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
119562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
120562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project/*static*/ int TiXmlBase::IsAlpha( unsigned char anyByte, TiXmlEncoding /*encoding*/ )
121562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project{
122562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	// This will only work for low-ascii, everything else is assumed to be a valid
123562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	// letter. I'm not sure this is the best approach, but it is quite tricky trying
124562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	// to figure out alhabetical vs. not across encoding. So take a very
125562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	// conservative approach.
126562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
127562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project//	if ( encoding == TIXML_ENCODING_UTF8 )
128562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project//	{
129562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		if ( anyByte < 127 )
130562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			return isalpha( anyByte );
131562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		else
132562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			return 1;	// What else to do? The unicode set is huge...get the english ones right.
133562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project//	}
134562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project//	else
135562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project//	{
136562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project//		return isalpha( anyByte );
137562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project//	}
138562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project}
139562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
140562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
141562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project/*static*/ int TiXmlBase::IsAlphaNum( unsigned char anyByte, TiXmlEncoding /*encoding*/ )
142562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project{
143562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	// This will only work for low-ascii, everything else is assumed to be a valid
144562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	// letter. I'm not sure this is the best approach, but it is quite tricky trying
145562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	// to figure out alhabetical vs. not across encoding. So take a very
146562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	// conservative approach.
147562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
148562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project//	if ( encoding == TIXML_ENCODING_UTF8 )
149562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project//	{
150562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		if ( anyByte < 127 )
151562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			return isalnum( anyByte );
152562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		else
153562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			return 1;	// What else to do? The unicode set is huge...get the english ones right.
154562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project//	}
155562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project//	else
156562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project//	{
157562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project//		return isalnum( anyByte );
158562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project//	}
159562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project}
160562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
161562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
162562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Projectclass TiXmlParsingData
163562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project{
164562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	friend class TiXmlDocument;
165562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project  public:
166562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	void Stamp( const char* now, TiXmlEncoding encoding );
167562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
168562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	const TiXmlCursor& Cursor()	{ return cursor; }
169562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
170562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project  private:
171562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	// Only used by the document!
172562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	TiXmlParsingData( const char* start, int _tabsize, int row, int col )
173562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
174562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		assert( start );
175562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		stamp = start;
176562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		tabsize = _tabsize;
177562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		cursor.row = row;
178562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		cursor.col = col;
179562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
180562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
181562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	TiXmlCursor		cursor;
182562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	const char*		stamp;
183562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	int				tabsize;
184562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project};
185562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
186562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
187562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Projectvoid TiXmlParsingData::Stamp( const char* now, TiXmlEncoding encoding )
188562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project{
189562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	assert( now );
190562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
191562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	// Do nothing if the tabsize is 0.
192562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	if ( tabsize < 1 )
193562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
194562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		return;
195562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
196562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
197562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	// Get the current row, column.
198562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	int row = cursor.row;
199562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	int col = cursor.col;
200562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	const char* p = stamp;
201562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	assert( p );
202562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
203562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	while ( p < now )
204562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
205562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		// Treat p as unsigned, so we have a happy compiler.
206562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		const unsigned char* pU = (const unsigned char*)p;
207562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
208562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		// Code contributed by Fletcher Dunn: (modified by lee)
209562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		switch (*pU) {
210562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			case 0:
211562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				// We *should* never get here, but in case we do, don't
212562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				// advance past the terminating null character, ever
213562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				return;
214562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
215562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			case '\r':
216562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				// bump down to the next line
217562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				++row;
218562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				col = 0;
219562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				// Eat the character
220562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				++p;
221562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
222562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				// Check for \r\n sequence, and treat this as a single character
223562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				if (*p == '\n') {
224562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project					++p;
225562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				}
226562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				break;
227562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
228562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			case '\n':
229562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				// bump down to the next line
230562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				++row;
231562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				col = 0;
232562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
233562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				// Eat the character
234562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				++p;
235562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
236562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				// Check for \n\r sequence, and treat this as a single
237562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				// character.  (Yes, this bizarre thing does occur still
238562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				// on some arcane platforms...)
239562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				if (*p == '\r') {
240562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project					++p;
241562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				}
242562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				break;
243562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
244562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			case '\t':
245562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				// Eat the character
246562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				++p;
247562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
248562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				// Skip to next tab stop
249562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				col = (col / tabsize + 1) * tabsize;
250562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				break;
251562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
252562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			case TIXML_UTF_LEAD_0:
253562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				if ( encoding == TIXML_ENCODING_UTF8 )
254562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				{
255562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project					if ( *(p+1) && *(p+2) )
256562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project					{
257562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project						// In these cases, don't advance the column. These are
258562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project						// 0-width spaces.
259562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project						if ( *(pU+1)==TIXML_UTF_LEAD_1 && *(pU+2)==TIXML_UTF_LEAD_2 )
260562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project							p += 3;
261562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project						else if ( *(pU+1)==0xbfU && *(pU+2)==0xbeU )
262562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project							p += 3;
263562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project						else if ( *(pU+1)==0xbfU && *(pU+2)==0xbfU )
264562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project							p += 3;
265562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project						else
266562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project							{ p +=3; ++col; }	// A normal character.
267562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project					}
268562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				}
269562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				else
270562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				{
271562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project					++p;
272562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project					++col;
273562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				}
274562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				break;
275562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
276562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			default:
277562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				if ( encoding == TIXML_ENCODING_UTF8 )
278562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				{
279562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project					// Eat the 1 to 4 byte utf8 character.
280562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project					int step = TiXmlBase::utf8ByteTable[*((unsigned char*)p)];
281562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project					if ( step == 0 )
282562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project						step = 1;		// Error case from bad encoding, but handle gracefully.
283562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project					p += step;
284562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
285562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project					// Just advance one column, of course.
286562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project					++col;
287562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				}
288562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				else
289562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				{
290562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project					++p;
291562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project					++col;
292562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				}
293562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				break;
294562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		}
295562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
296562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	cursor.row = row;
297562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	cursor.col = col;
298562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	assert( cursor.row >= -1 );
299562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	assert( cursor.col >= -1 );
300562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	stamp = p;
301562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	assert( stamp );
302562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project}
303562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
304562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
305562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Projectconst char* TiXmlBase::SkipWhiteSpace( const char* p, TiXmlEncoding encoding )
306562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project{
307562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	if ( !p || !*p )
308562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
309562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		return 0;
310562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
311562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	if ( encoding == TIXML_ENCODING_UTF8 )
312562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
313562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		while ( *p )
314562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		{
315562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			const unsigned char* pU = (const unsigned char*)p;
316562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
317562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			// Skip the stupid Microsoft UTF-8 Byte order marks
318562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			if (	*(pU+0)==TIXML_UTF_LEAD_0
319562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				 && *(pU+1)==TIXML_UTF_LEAD_1
320562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				 && *(pU+2)==TIXML_UTF_LEAD_2 )
321562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			{
322562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				p += 3;
323562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				continue;
324562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			}
325562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			else if(*(pU+0)==TIXML_UTF_LEAD_0
326562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				 && *(pU+1)==0xbfU
327562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				 && *(pU+2)==0xbeU )
328562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			{
329562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				p += 3;
330562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				continue;
331562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			}
332562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			else if(*(pU+0)==TIXML_UTF_LEAD_0
333562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				 && *(pU+1)==0xbfU
334562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				 && *(pU+2)==0xbfU )
335562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			{
336562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				p += 3;
337562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				continue;
338562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			}
339562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
340562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			if ( IsWhiteSpace( *p ) || *p == '\n' || *p =='\r' )		// Still using old rules for white space.
341562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				++p;
342562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			else
343562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				break;
344562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		}
345562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
346562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	else
347562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
348562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		while ( *p && IsWhiteSpace( *p ) || *p == '\n' || *p =='\r' )
349562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			++p;
350562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
351562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
352562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	return p;
353562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project}
354562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
355562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project#ifdef TIXML_USE_STL
356562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project/*static*/ bool TiXmlBase::StreamWhiteSpace( TIXML_ISTREAM * in, TIXML_STRING * tag )
357562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project{
358562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	for( ;; )
359562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
360562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		if ( !in->good() ) return false;
361562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
362562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		int c = in->peek();
363562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		// At this scope, we can't get to a document. So fail silently.
364562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		if ( !IsWhiteSpace( c ) || c <= 0 )
365562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			return true;
366562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
367562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		*tag += (char) in->get();
368562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
369562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project}
370562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
371562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project/*static*/ bool TiXmlBase::StreamTo( TIXML_ISTREAM * in, int character, TIXML_STRING * tag )
372562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project{
373562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	//assert( character > 0 && character < 128 );	// else it won't work in utf-8
374562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	while ( in->good() )
375562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
376562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		int c = in->peek();
377562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		if ( c == character )
378562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			return true;
379562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		if ( c <= 0 )		// Silent failure: can't get document at this scope
380562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			return false;
381562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
382562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		in->get();
383562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		*tag += (char) c;
384562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
385562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	return false;
386562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project}
387562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project#endif
388562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
389562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Projectconst char* TiXmlBase::ReadName( const char* p, TIXML_STRING * name, TiXmlEncoding encoding )
390562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project{
391562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	*name = "";
392562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	assert( p );
393562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
394562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	// Names start with letters or underscores.
395562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	// Of course, in unicode, tinyxml has no idea what a letter *is*. The
396562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	// algorithm is generous.
397562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	//
398562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	// After that, they can be letters, underscores, numbers,
399562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	// hyphens, or colons. (Colons are valid ony for namespaces,
400562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	// but tinyxml can't tell namespaces from names.)
401562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	if (    p && *p
402562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		 && ( IsAlpha( (unsigned char) *p, encoding ) || *p == '_' ) )
403562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
404562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		while(		p && *p
405562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				&&	(		IsAlphaNum( (unsigned char ) *p, encoding )
406562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project						 || *p == '_'
407562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project						 || *p == '-'
408562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project						 || *p == '.'
409562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project						 || *p == ':' ) )
410562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		{
411562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			(*name) += *p;
412562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			++p;
413562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		}
414562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		return p;
415562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
416562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	return 0;
417562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project}
418562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
419562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Projectconst char* TiXmlBase::GetEntity( const char* p, char* value, int* length, TiXmlEncoding encoding )
420562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project{
421562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	// Presume an entity, and pull it out.
422562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project    TIXML_STRING ent;
423562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	int i;
424562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	*length = 0;
425562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
426562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	if ( *(p+1) && *(p+1) == '#' && *(p+2) )
427562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
428562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		unsigned long ucs = 0;
429562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		ptrdiff_t delta = 0;
430562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		unsigned mult = 1;
431562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
432562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		if ( *(p+2) == 'x' )
433562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		{
434562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			// Hexadecimal.
435562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			if ( !*(p+3) ) return 0;
436562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
437562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			const char* q = p+3;
438562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			q = strchr( q, ';' );
439562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
440562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			if ( !q || !*q ) return 0;
441562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
442562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			delta = q-p;
443562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			--q;
444562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
445562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			while ( *q != 'x' )
446562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			{
447562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				if ( *q >= '0' && *q <= '9' )
448562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project					ucs += mult * (*q - '0');
449562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				else if ( *q >= 'a' && *q <= 'f' )
450562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project					ucs += mult * (*q - 'a' + 10);
451562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				else if ( *q >= 'A' && *q <= 'F' )
452562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project					ucs += mult * (*q - 'A' + 10 );
453562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				else
454562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project					return 0;
455562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				mult *= 16;
456562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				--q;
457562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			}
458562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		}
459562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		else
460562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		{
461562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			// Decimal.
462562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			if ( !*(p+2) ) return 0;
463562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
464562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			const char* q = p+2;
465562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			q = strchr( q, ';' );
466562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
467562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			if ( !q || !*q ) return 0;
468562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
469562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			delta = q-p;
470562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			--q;
471562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
472562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			while ( *q != '#' )
473562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			{
474562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				if ( *q >= '0' && *q <= '9' )
475562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project					ucs += mult * (*q - '0');
476562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				else
477562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project					return 0;
478562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				mult *= 10;
479562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				--q;
480562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			}
481562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		}
482562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		if ( encoding == TIXML_ENCODING_UTF8 )
483562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		{
484562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			// convert the UCS to UTF-8
485562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			ConvertUTF32ToUTF8( ucs, value, length );
486562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		}
487562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		else
488562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		{
489562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			*value = (char)ucs;
490562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			*length = 1;
491562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		}
492562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		return p + delta + 1;
493562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
494562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
495562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	// Now try to match it.
496562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	for( i=0; i<NUM_ENTITY; ++i )
497562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
498562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		if ( strncmp( entity[i].str, p, entity[i].strLength ) == 0 )
499562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		{
500562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			assert( strlen( entity[i].str ) == entity[i].strLength );
501562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			*value = entity[i].chr;
502562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			*length = 1;
503562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			return ( p + entity[i].strLength );
504562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		}
505562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
506562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
507562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	// So it wasn't an entity, its unrecognized, or something like that.
508562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	*value = *p;	// Don't put back the last one, since we return it!
509562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	return p+1;
510562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project}
511562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
512562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
513562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Projectbool TiXmlBase::StringEqual( const char* p,
514562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project							 const char* tag,
515562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project							 bool ignoreCase,
516562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project							 TiXmlEncoding encoding )
517562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project{
518562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	assert( p );
519562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	assert( tag );
520562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	if ( !p || !*p )
521562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
522562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		assert( 0 );
523562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		return false;
524562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
525562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
526562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	const char* q = p;
527562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
528562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	if ( ignoreCase )
529562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
530562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		while ( *q && *tag && ToLower( *q, encoding ) == ToLower( *tag, encoding ) )
531562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		{
532562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			++q;
533562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			++tag;
534562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		}
535562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
536562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		if ( *tag == 0 )
537562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			return true;
538562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
539562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	else
540562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
541562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		while ( *q && *tag && *q == *tag )
542562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		{
543562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			++q;
544562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			++tag;
545562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		}
546562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
547562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		if ( *tag == 0 )		// Have we found the end of the tag, and everything equal?
548562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			return true;
549562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
550562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	return false;
551562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project}
552562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
553562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Projectconst char* TiXmlBase::ReadText(	const char* p,
554562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project									TIXML_STRING * text,
555562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project									bool trimWhiteSpace,
556562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project									const char* endTag,
557562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project									bool caseInsensitive,
558562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project									TiXmlEncoding encoding )
559562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project{
560562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project    *text = "";
561562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	if (    !trimWhiteSpace			// certain tags always keep whitespace
562562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		 || !condenseWhiteSpace )	// if true, whitespace is always kept
563562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
564562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		// Keep all the white space.
565562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		while (	   p && *p
566562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				&& !StringEqual( p, endTag, caseInsensitive, encoding )
567562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			  )
568562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		{
569562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			int len;
570562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			char cArr[4] = { 0, 0, 0, 0 };
571562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			p = GetChar( p, cArr, &len, encoding );
572562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			text->append( cArr, len );
573562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		}
574562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
575562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	else
576562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
577562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		bool whitespace = false;
578562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
579562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		// Remove leading white space:
580562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		p = SkipWhiteSpace( p, encoding );
581562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		while (	   p && *p
582562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				&& !StringEqual( p, endTag, caseInsensitive, encoding ) )
583562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		{
584562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			if ( *p == '\r' || *p == '\n' )
585562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			{
586562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				whitespace = true;
587562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				++p;
588562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			}
589562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			else if ( IsWhiteSpace( *p ) )
590562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			{
591562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				whitespace = true;
592562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				++p;
593562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			}
594562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			else
595562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			{
596562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				// If we've found whitespace, add it before the
597562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				// new character. Any whitespace just becomes a space.
598562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				if ( whitespace )
599562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				{
600562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project					(*text) += ' ';
601562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project					whitespace = false;
602562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				}
603562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				int len;
604562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				char cArr[4] = { 0, 0, 0, 0 };
605562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				p = GetChar( p, cArr, &len, encoding );
606562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				if ( len == 1 )
607562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project					(*text) += cArr[0];	// more efficient
608562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				else
609562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project					text->append( cArr, len );
610562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			}
611562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		}
612562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
613562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	return p + strlen( endTag );
614562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project}
615562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
616562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project#ifdef TIXML_USE_STL
617562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
618562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Projectvoid TiXmlDocument::StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag )
619562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project{
620562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	// The basic issue with a document is that we don't know what we're
621562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	// streaming. Read something presumed to be a tag (and hope), then
622562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	// identify it, and call the appropriate stream method on the tag.
623562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	//
624562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	// This "pre-streaming" will never read the closing ">" so the
625562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	// sub-tag can orient itself.
626562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
627562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	if ( !StreamTo( in, '<', tag ) )
628562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
629562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		SetError( TIXML_ERROR_PARSING_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN );
630562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		return;
631562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
632562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
633562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	while ( in->good() )
634562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
635562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		int tagIndex = (int) tag->length();
636562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		while ( in->good() && in->peek() != '>' )
637562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		{
638562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			int c = in->get();
639562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			if ( c <= 0 )
640562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			{
641562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN );
642562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				break;
643562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			}
644562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			(*tag) += (char) c;
645562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		}
646562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
647562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		if ( in->good() )
648562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		{
649562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			// We now have something we presume to be a node of
650562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			// some sort. Identify it, and call the node to
651562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			// continue streaming.
652562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			TiXmlNode* node = Identify( tag->c_str() + tagIndex, TIXML_DEFAULT_ENCODING );
653562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
654562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			if ( node )
655562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			{
656562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				node->StreamIn( in, tag );
657562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				bool isElement = node->ToElement() != 0;
658562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				delete node;
659562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				node = 0;
660562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
661562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				// If this is the root element, we're done. Parsing will be
662562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				// done by the >> operator.
663562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				if ( isElement )
664562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				{
665562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project					return;
666562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				}
667562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			}
668562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			else
669562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			{
670562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				SetError( TIXML_ERROR, 0, 0, TIXML_ENCODING_UNKNOWN );
671562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				return;
672562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			}
673562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		}
674562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
675562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	// We should have returned sooner.
676562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	SetError( TIXML_ERROR, 0, 0, TIXML_ENCODING_UNKNOWN );
677562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project}
678562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
679562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project#endif
680562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
681562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Projectconst char* TiXmlDocument::Parse( const char* p, TiXmlParsingData* prevData, TiXmlEncoding encoding )
682562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project{
683562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	ClearError();
684562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
685562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	// Parse away, at the document level. Since a document
686562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	// contains nothing but other tags, most of what happens
687562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	// here is skipping white space.
688562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	if ( !p || !*p )
689562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
690562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN );
691562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		return 0;
692562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
693562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
694562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	// Note that, for a document, this needs to come
695562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	// before the while space skip, so that parsing
696562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	// starts from the pointer we are given.
697562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	location.Clear();
698562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	if ( prevData )
699562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
700562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		location.row = prevData->cursor.row;
701562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		location.col = prevData->cursor.col;
702562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
703562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	else
704562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
705562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		location.row = 0;
706562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		location.col = 0;
707562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
708562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	TiXmlParsingData data( p, TabSize(), location.row, location.col );
709562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	location = data.Cursor();
710562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
711562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	if ( encoding == TIXML_ENCODING_UNKNOWN )
712562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
713562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		// Check for the Microsoft UTF-8 lead bytes.
714562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		const unsigned char* pU = (const unsigned char*)p;
715562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		if (	*(pU+0) && *(pU+0) == TIXML_UTF_LEAD_0
716562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			 && *(pU+1) && *(pU+1) == TIXML_UTF_LEAD_1
717562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			 && *(pU+2) && *(pU+2) == TIXML_UTF_LEAD_2 )
718562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		{
719562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			encoding = TIXML_ENCODING_UTF8;
720562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			useMicrosoftBOM = true;
721562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		}
722562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
723562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
724562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project    p = SkipWhiteSpace( p, encoding );
725562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	if ( !p )
726562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
727562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN );
728562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		return 0;
729562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
730562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
731562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	while ( p && *p )
732562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
733562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		TiXmlNode* node = Identify( p, encoding );
734562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		if ( node )
735562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		{
736562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			p = node->Parse( p, &data, encoding );
737562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			LinkEndChild( node );
738562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		}
739562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		else
740562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		{
741562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			break;
742562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		}
743562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
744562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		// Did we get encoding info?
745562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		if (    encoding == TIXML_ENCODING_UNKNOWN
746562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			 && node->ToDeclaration() )
747562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		{
748562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			TiXmlDeclaration* dec = node->ToDeclaration();
749562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			const char* enc = dec->Encoding();
750562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			assert( enc );
751562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
752562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			if ( *enc == 0 )
753562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				encoding = TIXML_ENCODING_UTF8;
754562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			else if ( StringEqual( enc, "UTF-8", true, TIXML_ENCODING_UNKNOWN ) )
755562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				encoding = TIXML_ENCODING_UTF8;
756562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			else if ( StringEqual( enc, "UTF8", true, TIXML_ENCODING_UNKNOWN ) )
757562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				encoding = TIXML_ENCODING_UTF8;	// incorrect, but be nice
758562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			else
759562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				encoding = TIXML_ENCODING_LEGACY;
760562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		}
761562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
762562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		p = SkipWhiteSpace( p, encoding );
763562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
764562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
765562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	// Was this empty?
766562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	if ( !firstChild ) {
767562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, encoding );
768562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		return 0;
769562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
770562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
771562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	// All is well.
772562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	return p;
773562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project}
774562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
775562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Projectvoid TiXmlDocument::SetError( int err, const char* pError, TiXmlParsingData* data, TiXmlEncoding encoding )
776562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project{
777562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	// The first error in a chain is more accurate - don't set again!
778562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	if ( error )
779562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		return;
780562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
781562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	assert( err > 0 && err < TIXML_ERROR_STRING_COUNT );
782562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	error   = true;
783562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	errorId = err;
784562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	errorDesc = errorString[ errorId ];
785562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
786562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	errorLocation.Clear();
787562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	if ( pError && data )
788562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
789562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		data->Stamp( pError, encoding );
790562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		errorLocation = data->Cursor();
791562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
792562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project}
793562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
794562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
795562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source ProjectTiXmlNode* TiXmlNode::Identify( const char* p, TiXmlEncoding encoding )
796562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project{
797562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	TiXmlNode* returnNode = 0;
798562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
799562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	p = SkipWhiteSpace( p, encoding );
800562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	if( !p || !*p || *p != '<' )
801562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
802562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		return 0;
803562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
804562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
805562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	TiXmlDocument* doc = GetDocument();
806562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	p = SkipWhiteSpace( p, encoding );
807562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
808562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	if ( !p || !*p )
809562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
810562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		return 0;
811562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
812562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
813562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	// What is this thing?
814562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	// - Elements start with a letter or underscore, but xml is reserved.
815562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	// - Comments: <!--
816562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	// - Decleration: <?xml
817562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	// - Everthing else is unknown to tinyxml.
818562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	//
819562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
820562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	const char* xmlHeader = { "<?xml" };
821562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	const char* commentHeader = { "<!--" };
822562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	const char* dtdHeader = { "<!" };
823562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	const char* cdataHeader = { "<![CDATA[" };
824562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
825562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	if ( StringEqual( p, xmlHeader, true, encoding ) )
826562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
827562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		#ifdef DEBUG_PARSER
828562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			TIXML_LOG( "XML parsing Declaration\n" );
829562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		#endif
830562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		returnNode = new TiXmlDeclaration();
831562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
832562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	else if ( StringEqual( p, commentHeader, false, encoding ) )
833562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
834562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		#ifdef DEBUG_PARSER
835562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			TIXML_LOG( "XML parsing Comment\n" );
836562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		#endif
837562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		returnNode = new TiXmlComment();
838562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
839562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	else if ( StringEqual( p, cdataHeader, false, encoding ) )
840562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
841562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		#ifdef DEBUG_PARSER
842562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			TIXML_LOG( "XML parsing CDATA\n" );
843562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		#endif
844562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		TiXmlText* text = new TiXmlText( "" );
845562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		text->SetCDATA( true );
846562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		returnNode = text;
847562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
848562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	else if ( StringEqual( p, dtdHeader, false, encoding ) )
849562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
850562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		#ifdef DEBUG_PARSER
851562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			TIXML_LOG( "XML parsing Unknown(1)\n" );
852562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		#endif
853562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		returnNode = new TiXmlUnknown();
854562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
855562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	else if (    IsAlpha( *(p+1), encoding )
856562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			  || *(p+1) == '_' )
857562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
858562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		#ifdef DEBUG_PARSER
859562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			TIXML_LOG( "XML parsing Element\n" );
860562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		#endif
861562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		returnNode = new TiXmlElement( "" );
862562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
863562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	else
864562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
865562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		#ifdef DEBUG_PARSER
866562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			TIXML_LOG( "XML parsing Unknown(2)\n" );
867562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		#endif
868562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		returnNode = new TiXmlUnknown();
869562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
870562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
871562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	if ( returnNode )
872562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
873562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		// Set the parent, so it can report errors
874562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		returnNode->parent = this;
875562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
876562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	else
877562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
878562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		if ( doc )
879562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			doc->SetError( TIXML_ERROR_OUT_OF_MEMORY, 0, 0, TIXML_ENCODING_UNKNOWN );
880562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
881562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	return returnNode;
882562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project}
883562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
884562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project#ifdef TIXML_USE_STL
885562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
886562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Projectvoid TiXmlElement::StreamIn (TIXML_ISTREAM * in, TIXML_STRING * tag)
887562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project{
888562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	// We're called with some amount of pre-parsing. That is, some of "this"
889562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	// element is in "tag". Go ahead and stream to the closing ">"
890562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	while( in->good() )
891562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
892562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		int c = in->get();
893562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		if ( c <= 0 )
894562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		{
895562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			TiXmlDocument* document = GetDocument();
896562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			if ( document )
897562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				document->SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN );
898562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			return;
899562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		}
900562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		(*tag) += (char) c ;
901562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
902562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		if ( c == '>' )
903562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			break;
904562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
905562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
906562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	if ( tag->length() < 3 ) return;
907562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
908562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	// Okay...if we are a "/>" tag, then we're done. We've read a complete tag.
909562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	// If not, identify and stream.
910562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
911562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	if (    tag->at( tag->length() - 1 ) == '>'
912562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		 && tag->at( tag->length() - 2 ) == '/' )
913562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
914562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		// All good!
915562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		return;
916562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
917562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	else if ( tag->at( tag->length() - 1 ) == '>' )
918562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
919562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		// There is more. Could be:
920562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		//		text
921562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		//		closing tag
922562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		//		another node.
923562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		for ( ;; )
924562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		{
925562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			StreamWhiteSpace( in, tag );
926562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
927562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			// Do we have text?
928562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			if ( in->good() && in->peek() != '<' )
929562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			{
930562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				// Yep, text.
931562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				TiXmlText text( "" );
932562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				text.StreamIn( in, tag );
933562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
934562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				// What follows text is a closing tag or another node.
935562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				// Go around again and figure it out.
936562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				continue;
937562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			}
938562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
939562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			// We now have either a closing tag...or another node.
940562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			// We should be at a "<", regardless.
941562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			if ( !in->good() ) return;
942562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			assert( in->peek() == '<' );
943562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			int tagIndex = (int) tag->length();
944562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
945562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			bool closingTag = false;
946562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			bool firstCharFound = false;
947562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
948562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			for( ;; )
949562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			{
950562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				if ( !in->good() )
951562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project					return;
952562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
953562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				int c = in->peek();
954562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				if ( c <= 0 )
955562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				{
956562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project					TiXmlDocument* document = GetDocument();
957562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project					if ( document )
958562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project						document->SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN );
959562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project					return;
960562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				}
961562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
962562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				if ( c == '>' )
963562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project					break;
964562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
965562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				*tag += (char) c;
966562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				in->get();
967562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
968562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				if ( !firstCharFound && c != '<' && !IsWhiteSpace( c ) )
969562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				{
970562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project					firstCharFound = true;
971562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project					if ( c == '/' )
972562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project						closingTag = true;
973562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				}
974562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			}
975562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			// If it was a closing tag, then read in the closing '>' to clean up the input stream.
976562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			// If it was not, the streaming will be done by the tag.
977562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			if ( closingTag )
978562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			{
979562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				if ( !in->good() )
980562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project					return;
981562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
982562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				int c = in->get();
983562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				if ( c <= 0 )
984562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				{
985562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project					TiXmlDocument* document = GetDocument();
986562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project					if ( document )
987562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project						document->SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN );
988562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project					return;
989562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				}
990562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				assert( c == '>' );
991562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				*tag += (char) c;
992562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
993562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				// We are done, once we've found our closing tag.
994562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				return;
995562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			}
996562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			else
997562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			{
998562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				// If not a closing tag, id it, and stream.
999562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				const char* tagloc = tag->c_str() + tagIndex;
1000562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				TiXmlNode* node = Identify( tagloc, TIXML_DEFAULT_ENCODING );
1001562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				if ( !node )
1002562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project					return;
1003562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				node->StreamIn( in, tag );
1004562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				delete node;
1005562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				node = 0;
1006562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1007562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				// No return: go around from the beginning: text, closing tag, or node.
1008562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			}
1009562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		}
1010562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
1011562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project}
1012562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project#endif
1013562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1014562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Projectconst char* TiXmlElement::Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding )
1015562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project{
1016562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	p = SkipWhiteSpace( p, encoding );
1017562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	TiXmlDocument* document = GetDocument();
1018562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1019562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	if ( !p || !*p )
1020562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
1021562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		if ( document ) document->SetError( TIXML_ERROR_PARSING_ELEMENT, 0, 0, encoding );
1022562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		return 0;
1023562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
1024562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1025562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	if ( data )
1026562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
1027562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		data->Stamp( p, encoding );
1028562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		location = data->Cursor();
1029562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
1030562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1031562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	if ( *p != '<' )
1032562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
1033562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		if ( document ) document->SetError( TIXML_ERROR_PARSING_ELEMENT, p, data, encoding );
1034562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		return 0;
1035562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
1036562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1037562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	p = SkipWhiteSpace( p+1, encoding );
1038562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1039562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	// Read the name.
1040562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	const char* pErr = p;
1041562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1042562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project    p = ReadName( p, &value, encoding );
1043562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	if ( !p || !*p )
1044562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
1045562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		if ( document )	document->SetError( TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME, pErr, data, encoding );
1046562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		return 0;
1047562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
1048562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1049562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project    TIXML_STRING endTag ("</");
1050562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	endTag += value;
1051562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	endTag += ">";
1052562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1053562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	// Check for and read attributes. Also look for an empty
1054562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	// tag or an end tag.
1055562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	while ( p && *p )
1056562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
1057562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		pErr = p;
1058562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		p = SkipWhiteSpace( p, encoding );
1059562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		if ( !p || !*p )
1060562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		{
1061562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, pErr, data, encoding );
1062562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			return 0;
1063562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		}
1064562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		if ( *p == '/' )
1065562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		{
1066562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			++p;
1067562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			// Empty tag.
1068562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			if ( *p  != '>' )
1069562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			{
1070562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				if ( document ) document->SetError( TIXML_ERROR_PARSING_EMPTY, p, data, encoding );
1071562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				return 0;
1072562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			}
1073562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			return (p+1);
1074562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		}
1075562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		else if ( *p == '>' )
1076562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		{
1077562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			// Done with attributes (if there were any.)
1078562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			// Read the value -- which can include other
1079562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			// elements -- read the end tag, and return.
1080562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			++p;
1081562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			p = ReadValue( p, data, encoding );		// Note this is an Element method, and will set the error if one happens.
1082562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			if ( !p || !*p )
1083562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				return 0;
1084562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1085562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			// We should find the end tag now
1086562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			if ( StringEqual( p, endTag.c_str(), false, encoding ) )
1087562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			{
1088562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				p += endTag.length();
1089562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				return p;
1090562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			}
1091562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			else
1092562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			{
1093562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				if ( document ) document->SetError( TIXML_ERROR_READING_END_TAG, p, data, encoding );
1094562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				return 0;
1095562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			}
1096562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		}
1097562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		else
1098562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		{
1099562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			// Try to read an attribute:
1100562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			TiXmlAttribute* attrib = new TiXmlAttribute();
1101562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			if ( !attrib )
1102562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			{
1103562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				if ( document ) document->SetError( TIXML_ERROR_OUT_OF_MEMORY, pErr, data, encoding );
1104562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				return 0;
1105562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			}
1106562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1107562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			attrib->SetDocument( document );
1108562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			const char* pErr = p;
1109562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			p = attrib->Parse( p, data, encoding );
1110562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1111562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			if ( !p || !*p )
1112562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			{
1113562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				if ( document ) document->SetError( TIXML_ERROR_PARSING_ELEMENT, pErr, data, encoding );
1114562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				delete attrib;
1115562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				return 0;
1116562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			}
1117562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1118562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			// Handle the strange case of double attributes:
1119562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			TiXmlAttribute* node = attributeSet.Find( attrib->Name() );
1120562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			if ( node )
1121562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			{
1122562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				node->SetValue( attrib->Value() );
1123562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				delete attrib;
1124562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				return 0;
1125562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			}
1126562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1127562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			attributeSet.Add( attrib );
1128562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		}
1129562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
1130562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	return p;
1131562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project}
1132562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1133562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1134562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Projectconst char* TiXmlElement::ReadValue( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding )
1135562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project{
1136562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	TiXmlDocument* document = GetDocument();
1137562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1138562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	// Read in text and elements in any order.
1139562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	const char* pWithWhiteSpace = p;
1140562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	p = SkipWhiteSpace( p, encoding );
1141562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1142562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	while ( p && *p )
1143562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
1144562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		if ( *p != '<' )
1145562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		{
1146562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			// Take what we have, make a text element.
1147562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			TiXmlText* textNode = new TiXmlText( "" );
1148562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1149562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			if ( !textNode )
1150562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			{
1151562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				if ( document ) document->SetError( TIXML_ERROR_OUT_OF_MEMORY, 0, 0, encoding );
1152562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				    return 0;
1153562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			}
1154562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1155562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			if ( TiXmlBase::IsWhiteSpaceCondensed() )
1156562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			{
1157562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				p = textNode->Parse( p, data, encoding );
1158562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			}
1159562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			else
1160562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			{
1161562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				// Special case: we want to keep the white space
1162562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				// so that leading spaces aren't removed.
1163562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				p = textNode->Parse( pWithWhiteSpace, data, encoding );
1164562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			}
1165562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1166562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			if ( !textNode->Blank() )
1167562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				LinkEndChild( textNode );
1168562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			else
1169562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				delete textNode;
1170562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		}
1171562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		else
1172562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		{
1173562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			// We hit a '<'
1174562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			// Have we hit a new element or an end tag? This could also be
1175562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			// a TiXmlText in the "CDATA" style.
1176562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			if ( StringEqual( p, "</", false, encoding ) )
1177562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			{
1178562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				return p;
1179562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			}
1180562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			else
1181562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			{
1182562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				TiXmlNode* node = Identify( p, encoding );
1183562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				if ( node )
1184562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				{
1185562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project					p = node->Parse( p, data, encoding );
1186562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project					LinkEndChild( node );
1187562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				}
1188562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				else
1189562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				{
1190562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project					return 0;
1191562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				}
1192562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			}
1193562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		}
1194562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		pWithWhiteSpace = p;
1195562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		p = SkipWhiteSpace( p, encoding );
1196562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
1197562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1198562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	if ( !p )
1199562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
1200562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		if ( document ) document->SetError( TIXML_ERROR_READING_ELEMENT_VALUE, 0, 0, encoding );
1201562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
1202562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	return p;
1203562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project}
1204562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1205562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1206562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project#ifdef TIXML_USE_STL
1207562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Projectvoid TiXmlUnknown::StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag )
1208562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project{
1209562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	while ( in->good() )
1210562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
1211562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		int c = in->get();
1212562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		if ( c <= 0 )
1213562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		{
1214562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			TiXmlDocument* document = GetDocument();
1215562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			if ( document )
1216562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				document->SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN );
1217562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			return;
1218562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		}
1219562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		(*tag) += (char) c;
1220562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1221562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		if ( c == '>' )
1222562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		{
1223562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			// All is well.
1224562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			return;
1225562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		}
1226562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
1227562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project}
1228562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project#endif
1229562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1230562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1231562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Projectconst char* TiXmlUnknown::Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding )
1232562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project{
1233562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	TiXmlDocument* document = GetDocument();
1234562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	p = SkipWhiteSpace( p, encoding );
1235562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1236562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	if ( data )
1237562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
1238562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		data->Stamp( p, encoding );
1239562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		location = data->Cursor();
1240562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
1241562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	if ( !p || !*p || *p != '<' )
1242562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
1243562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		if ( document ) document->SetError( TIXML_ERROR_PARSING_UNKNOWN, p, data, encoding );
1244562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		return 0;
1245562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
1246562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	++p;
1247562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project    value = "";
1248562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1249562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	while ( p && *p && *p != '>' )
1250562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
1251562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		value += *p;
1252562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		++p;
1253562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
1254562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1255562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	if ( !p )
1256562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
1257562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		if ( document )	document->SetError( TIXML_ERROR_PARSING_UNKNOWN, 0, 0, encoding );
1258562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
1259562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	if ( *p == '>' )
1260562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		return p+1;
1261562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	return p;
1262562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project}
1263562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1264562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project#ifdef TIXML_USE_STL
1265562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Projectvoid TiXmlComment::StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag )
1266562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project{
1267562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	while ( in->good() )
1268562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
1269562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		int c = in->get();
1270562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		if ( c <= 0 )
1271562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		{
1272562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			TiXmlDocument* document = GetDocument();
1273562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			if ( document )
1274562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				document->SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN );
1275562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			return;
1276562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		}
1277562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1278562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		(*tag) += (char) c;
1279562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1280562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		if ( c == '>'
1281562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			 && tag->at( tag->length() - 2 ) == '-'
1282562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			 && tag->at( tag->length() - 3 ) == '-' )
1283562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		{
1284562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			// All is well.
1285562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			return;
1286562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		}
1287562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
1288562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project}
1289562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project#endif
1290562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1291562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1292562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Projectconst char* TiXmlComment::Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding )
1293562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project{
1294562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	TiXmlDocument* document = GetDocument();
1295562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	value = "";
1296562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1297562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	p = SkipWhiteSpace( p, encoding );
1298562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1299562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	if ( data )
1300562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
1301562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		data->Stamp( p, encoding );
1302562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		location = data->Cursor();
1303562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
1304562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	const char* startTag = "<!--";
1305562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	const char* endTag   = "-->";
1306562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1307562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	if ( !StringEqual( p, startTag, false, encoding ) )
1308562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
1309562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		document->SetError( TIXML_ERROR_PARSING_COMMENT, p, data, encoding );
1310562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		return 0;
1311562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
1312562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	p += strlen( startTag );
1313562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	p = ReadText( p, &value, false, endTag, false, encoding );
1314562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	return p;
1315562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project}
1316562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1317562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1318562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Projectconst char* TiXmlAttribute::Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding )
1319562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project{
1320562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	p = SkipWhiteSpace( p, encoding );
1321562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	if ( !p || !*p ) return 0;
1322562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1323562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	int tabsize = 4;
1324562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	if ( document )
1325562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		tabsize = document->TabSize();
1326562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1327562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	if ( data )
1328562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
1329562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		data->Stamp( p, encoding );
1330562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		location = data->Cursor();
1331562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
1332562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	// Read the name, the '=' and the value.
1333562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	const char* pErr = p;
1334562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	p = ReadName( p, &name, encoding );
1335562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	if ( !p || !*p )
1336562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
1337562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, pErr, data, encoding );
1338562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		return 0;
1339562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
1340562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	p = SkipWhiteSpace( p, encoding );
1341562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	if ( !p || !*p || *p != '=' )
1342562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
1343562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding );
1344562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		return 0;
1345562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
1346562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1347562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	++p;	// skip '='
1348562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	p = SkipWhiteSpace( p, encoding );
1349562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	if ( !p || !*p )
1350562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
1351562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding );
1352562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		return 0;
1353562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
1354562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1355562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	const char* end;
1356562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1357562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	if ( *p == '\'' )
1358562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
1359562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		++p;
1360562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		end = "\'";
1361562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		p = ReadText( p, &value, false, end, false, encoding );
1362562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
1363562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	else if ( *p == '"' )
1364562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
1365562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		++p;
1366562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		end = "\"";
1367562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		p = ReadText( p, &value, false, end, false, encoding );
1368562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
1369562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	else
1370562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
1371562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		// All attribute values should be in single or double quotes.
1372562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		// But this is such a common error that the parser will try
1373562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		// its best, even without them.
1374562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		value = "";
1375562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		while (    p && *p										// existence
1376562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				&& !IsWhiteSpace( *p ) && *p != '\n' && *p != '\r'	// whitespace
1377562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				&& *p != '/' && *p != '>' )						// tag end
1378562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		{
1379562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			value += *p;
1380562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			++p;
1381562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		}
1382562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
1383562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	return p;
1384562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project}
1385562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1386562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project#ifdef TIXML_USE_STL
1387562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Projectvoid TiXmlText::StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag )
1388562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project{
1389562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	if ( cdata )
1390562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
1391562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		int c = in->get();
1392562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		if ( c <= 0 )
1393562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		{
1394562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			TiXmlDocument* document = GetDocument();
1395562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			if ( document )
1396562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				document->SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN );
1397562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			return;
1398562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		}
1399562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1400562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		(*tag) += (char) c;
1401562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1402562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		if ( c == '>'
1403562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			 && tag->at( tag->length() - 2 ) == ']'
1404562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			 && tag->at( tag->length() - 3 ) == ']' )
1405562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		{
1406562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			// All is well.
1407562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			return;
1408562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		}
1409562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
1410562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	else
1411562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
1412562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		while ( in->good() )
1413562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		{
1414562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			int c = in->peek();
1415562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			if ( c == '<' )
1416562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				return;
1417562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			if ( c <= 0 )
1418562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			{
1419562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				TiXmlDocument* document = GetDocument();
1420562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				if ( document )
1421562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project					document->SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN );
1422562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				return;
1423562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			}
1424562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1425562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			(*tag) += (char) c;
1426562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			in->get();
1427562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		}
1428562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
1429562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project}
1430562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project#endif
1431562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1432562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Projectconst char* TiXmlText::Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding )
1433562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project{
1434562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	value = "";
1435562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	TiXmlDocument* document = GetDocument();
1436562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1437562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	if ( data )
1438562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
1439562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		data->Stamp( p, encoding );
1440562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		location = data->Cursor();
1441562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
1442562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1443562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	const char* const startTag = "<![CDATA[";
1444562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	const char* const endTag   = "]]>";
1445562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1446562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	if ( cdata || StringEqual( p, startTag, false, encoding ) )
1447562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
1448562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		cdata = true;
1449562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1450562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		if ( !StringEqual( p, startTag, false, encoding ) )
1451562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		{
1452562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			document->SetError( TIXML_ERROR_PARSING_CDATA, p, data, encoding );
1453562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			return 0;
1454562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		}
1455562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		p += strlen( startTag );
1456562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1457562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		// Keep all the white space, ignore the encoding, etc.
1458562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		while (	   p && *p
1459562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				&& !StringEqual( p, endTag, false, encoding )
1460562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			  )
1461562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		{
1462562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			value += *p;
1463562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			++p;
1464562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		}
1465562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1466562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		TIXML_STRING dummy;
1467562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		p = ReadText( p, &dummy, false, endTag, false, encoding );
1468562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		return p;
1469562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
1470562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	else
1471562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
1472562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		bool ignoreWhite = true;
1473562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1474562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		const char* end = "<";
1475562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		p = ReadText( p, &value, ignoreWhite, end, false, encoding );
1476562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		if ( p )
1477562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			return p-1;	// don't truncate the '<'
1478562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		return 0;
1479562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
1480562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project}
1481562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1482562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project#ifdef TIXML_USE_STL
1483562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Projectvoid TiXmlDeclaration::StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag )
1484562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project{
1485562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	while ( in->good() )
1486562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
1487562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		int c = in->get();
1488562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		if ( c <= 0 )
1489562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		{
1490562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			TiXmlDocument* document = GetDocument();
1491562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			if ( document )
1492562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				document->SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN );
1493562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			return;
1494562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		}
1495562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		(*tag) += (char) c;
1496562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1497562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		if ( c == '>' )
1498562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		{
1499562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			// All is well.
1500562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			return;
1501562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		}
1502562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
1503562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project}
1504562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project#endif
1505562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1506562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Projectconst char* TiXmlDeclaration::Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding _encoding )
1507562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project{
1508562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	p = SkipWhiteSpace( p, _encoding );
1509562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	// Find the beginning, find the end, and look for
1510562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	// the stuff in-between.
1511562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	TiXmlDocument* document = GetDocument();
1512562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	if ( !p || !*p || !StringEqual( p, "<?xml", true, _encoding ) )
1513562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
1514562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		if ( document ) document->SetError( TIXML_ERROR_PARSING_DECLARATION, 0, 0, _encoding );
1515562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		return 0;
1516562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
1517562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	if ( data )
1518562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
1519562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		data->Stamp( p, _encoding );
1520562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		location = data->Cursor();
1521562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
1522562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	p += 5;
1523562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1524562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	version = "";
1525562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	encoding = "";
1526562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	standalone = "";
1527562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1528562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	while ( p && *p )
1529562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	{
1530562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		if ( *p == '>' )
1531562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		{
1532562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			++p;
1533562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			return p;
1534562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		}
1535562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1536562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		p = SkipWhiteSpace( p, _encoding );
1537562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		if ( StringEqual( p, "version", true, _encoding ) )
1538562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		{
1539562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			TiXmlAttribute attrib;
1540562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			p = attrib.Parse( p, data, _encoding );
1541562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			version = attrib.Value();
1542562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		}
1543562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		else if ( StringEqual( p, "encoding", true, _encoding ) )
1544562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		{
1545562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			TiXmlAttribute attrib;
1546562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			p = attrib.Parse( p, data, _encoding );
1547562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			encoding = attrib.Value();
1548562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		}
1549562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		else if ( StringEqual( p, "standalone", true, _encoding ) )
1550562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		{
1551562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			TiXmlAttribute attrib;
1552562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			p = attrib.Parse( p, data, _encoding );
1553562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			standalone = attrib.Value();
1554562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		}
1555562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		else
1556562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		{
1557562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			// Read over whatever it is.
1558562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			while( p && *p && *p != '>' && !IsWhiteSpace( *p ) )
1559562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project				++p;
1560562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		}
1561562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	}
1562562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	return 0;
1563562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project}
1564562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1565562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Projectbool TiXmlText::Blank() const
1566562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project{
1567562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	for ( unsigned i=0; i<value.length(); i++ )
1568562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project		if ( !IsWhiteSpace( value[i] ) )
1569562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project			return false;
1570562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project	return true;
1571562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project}
1572562be06492c3ac43adf153f550abaede6bc18a44The Android Open Source Project
1573