mirror of https://github.com/AxioDL/tinyxml2.git
tweaks, clarification to line numbers
This commit is contained in:
parent
002713856b
commit
e90e901041
10
tinyxml2.cpp
10
tinyxml2.cpp
|
@ -193,6 +193,7 @@ char* StrPair::ParseText( char* p, const char* endTag, int strFlags, int* curLin
|
||||||
{
|
{
|
||||||
TIXMLASSERT( p );
|
TIXMLASSERT( p );
|
||||||
TIXMLASSERT( endTag && *endTag );
|
TIXMLASSERT( endTag && *endTag );
|
||||||
|
TIXMLASSERT(curLineNumPtr);
|
||||||
|
|
||||||
char* start = p;
|
char* start = p;
|
||||||
char endChar = *endTag;
|
char endChar = *endTag;
|
||||||
|
@ -238,8 +239,7 @@ void StrPair::CollapseWhitespace()
|
||||||
// Adjusting _start would cause undefined behavior on delete[]
|
// Adjusting _start would cause undefined behavior on delete[]
|
||||||
TIXMLASSERT( ( _flags & NEEDS_DELETE ) == 0 );
|
TIXMLASSERT( ( _flags & NEEDS_DELETE ) == 0 );
|
||||||
// Trim leading space.
|
// Trim leading space.
|
||||||
int unusedLineNum = 0;
|
_start = XMLUtil::SkipWhiteSpace( _start, 0 );
|
||||||
_start = XMLUtil::SkipWhiteSpace( _start, &unusedLineNum );
|
|
||||||
|
|
||||||
if ( *_start ) {
|
if ( *_start ) {
|
||||||
const char* p = _start; // the read pointer
|
const char* p = _start; // the read pointer
|
||||||
|
@ -247,7 +247,7 @@ void StrPair::CollapseWhitespace()
|
||||||
|
|
||||||
while( *p ) {
|
while( *p ) {
|
||||||
if ( XMLUtil::IsWhiteSpace( *p )) {
|
if ( XMLUtil::IsWhiteSpace( *p )) {
|
||||||
p = XMLUtil::SkipWhiteSpace( p, &unusedLineNum );
|
p = XMLUtil::SkipWhiteSpace( p, 0 );
|
||||||
if ( *p == 0 ) {
|
if ( *p == 0 ) {
|
||||||
break; // don't write to q; this trims the trailing space.
|
break; // don't write to q; this trims the trailing space.
|
||||||
}
|
}
|
||||||
|
@ -2247,7 +2247,7 @@ void XMLDocument::SetError( XMLError error, const char* str1, const char* str2,
|
||||||
_errorStr2.SetStr(str2);
|
_errorStr2.SetStr(str2);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* XMLDocument::ErrorName(XMLError errorID)
|
/*static*/ const char* XMLDocument::ErrorIDToName(XMLError errorID)
|
||||||
{
|
{
|
||||||
TIXMLASSERT( errorID >= 0 && errorID < XML_ERROR_COUNT );
|
TIXMLASSERT( errorID >= 0 && errorID < XML_ERROR_COUNT );
|
||||||
const char* errorName = _errorNames[errorID];
|
const char* errorName = _errorNames[errorID];
|
||||||
|
@ -2257,7 +2257,7 @@ const char* XMLDocument::ErrorName(XMLError errorID)
|
||||||
|
|
||||||
const char* XMLDocument::ErrorName() const
|
const char* XMLDocument::ErrorName() const
|
||||||
{
|
{
|
||||||
return ErrorName(_errorID);
|
return ErrorIDToName(_errorID);
|
||||||
}
|
}
|
||||||
|
|
||||||
void XMLDocument::PrintError() const
|
void XMLDocument::PrintError() const
|
||||||
|
|
|
@ -532,8 +532,9 @@ class XMLUtil
|
||||||
public:
|
public:
|
||||||
static const char* SkipWhiteSpace( const char* p, int* curLineNumPtr ) {
|
static const char* SkipWhiteSpace( const char* p, int* curLineNumPtr ) {
|
||||||
TIXMLASSERT( p );
|
TIXMLASSERT( p );
|
||||||
|
|
||||||
while( IsWhiteSpace(*p) ) {
|
while( IsWhiteSpace(*p) ) {
|
||||||
if (*p == '\n') {
|
if (curLineNumPtr && *p == '\n') {
|
||||||
++(*curLineNumPtr);
|
++(*curLineNumPtr);
|
||||||
}
|
}
|
||||||
++p;
|
++p;
|
||||||
|
@ -1765,7 +1766,7 @@ public:
|
||||||
return _errorID;
|
return _errorID;
|
||||||
}
|
}
|
||||||
const char* ErrorName() const;
|
const char* ErrorName() const;
|
||||||
static const char* ErrorName(XMLError errorID);
|
static const char* ErrorIDToName(XMLError errorID);
|
||||||
|
|
||||||
/// Return a possibly helpful diagnostic location or string.
|
/// Return a possibly helpful diagnostic location or string.
|
||||||
const char* GetErrorStr1() const {
|
const char* GetErrorStr1() const {
|
||||||
|
|
72
xmltest.cpp
72
xmltest.cpp
|
@ -65,7 +65,7 @@ bool XMLTest (const char* testString, const char* expected, const char* found, b
|
||||||
|
|
||||||
bool XMLTest(const char* testString, XMLError expected, XMLError found, bool echo = true, bool extraNL = false)
|
bool XMLTest(const char* testString, XMLError expected, XMLError found, bool echo = true, bool extraNL = false)
|
||||||
{
|
{
|
||||||
return XMLTest(testString, XMLDocument::ErrorName(expected), XMLDocument::ErrorName(found), echo, extraNL);
|
return XMLTest(testString, XMLDocument::ErrorIDToName(expected), XMLDocument::ErrorIDToName(found), echo, extraNL);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool XMLTest(const char* testString, bool expected, bool found, bool echo = true, bool extraNL = false)
|
bool XMLTest(const char* testString, bool expected, bool found, bool echo = true, bool extraNL = false)
|
||||||
|
@ -1647,7 +1647,7 @@ int main( int argc, const char ** argv )
|
||||||
|
|
||||||
// ----------- Line Number Tracking --------------
|
// ----------- Line Number Tracking --------------
|
||||||
{
|
{
|
||||||
struct Functor: XMLVisitor
|
struct TestUtil: XMLVisitor
|
||||||
{
|
{
|
||||||
void TestParseError(const char *testString, const char *docStr, XMLError expected_error, int expectedLine)
|
void TestParseError(const char *testString, const char *docStr, XMLError expected_error, int expectedLine)
|
||||||
{
|
{
|
||||||
|
@ -1725,46 +1725,50 @@ int main( int argc, const char ** argv )
|
||||||
str.Push(0);
|
str.Push(0);
|
||||||
XMLTest(testString, expectedLines, str.Mem());
|
XMLTest(testString, expectedLines, str.Mem());
|
||||||
}
|
}
|
||||||
} T;
|
} tester;
|
||||||
|
|
||||||
T.TestParseError("ErrorLine-Parsing", "\n<root>\n foo \n<unclosed/>", XML_ERROR_PARSING, 2);
|
tester.TestParseError("ErrorLine-Parsing", "\n<root>\n foo \n<unclosed/>", XML_ERROR_PARSING, 2);
|
||||||
T.TestParseError("ErrorLine-Declaration", "<root>\n<?xml version=\"1.0\"?>", XML_ERROR_PARSING_DECLARATION, 2);
|
tester.TestParseError("ErrorLine-Declaration", "<root>\n<?xml version=\"1.0\"?>", XML_ERROR_PARSING_DECLARATION, 2);
|
||||||
T.TestParseError("ErrorLine-Mismatch", "\n<root>\n</mismatch>", XML_ERROR_MISMATCHED_ELEMENT, 2);
|
tester.TestParseError("ErrorLine-Mismatch", "\n<root>\n</mismatch>", XML_ERROR_MISMATCHED_ELEMENT, 2);
|
||||||
T.TestParseError("ErrorLine-CData", "\n<root><![CDATA[ \n foo bar \n", XML_ERROR_PARSING_CDATA, 2);
|
tester.TestParseError("ErrorLine-CData", "\n<root><![CDATA[ \n foo bar \n", XML_ERROR_PARSING_CDATA, 2);
|
||||||
T.TestParseError("ErrorLine-Text", "\n<root>\n foo bar \n", XML_ERROR_PARSING_TEXT, 3);
|
tester.TestParseError("ErrorLine-Text", "\n<root>\n foo bar \n", XML_ERROR_PARSING_TEXT, 3);
|
||||||
T.TestParseError("ErrorLine-Comment", "\n<root>\n<!-- >\n", XML_ERROR_PARSING_COMMENT, 3);
|
tester.TestParseError("ErrorLine-Comment", "\n<root>\n<!-- >\n", XML_ERROR_PARSING_COMMENT, 3);
|
||||||
T.TestParseError("ErrorLine-Declaration", "\n<root>\n<? >\n", XML_ERROR_PARSING_DECLARATION, 3);
|
tester.TestParseError("ErrorLine-Declaration", "\n<root>\n<? >\n", XML_ERROR_PARSING_DECLARATION, 3);
|
||||||
T.TestParseError("ErrorLine-Unknown", "\n<root>\n<! \n", XML_ERROR_PARSING_UNKNOWN, 3);
|
tester.TestParseError("ErrorLine-Unknown", "\n<root>\n<! \n", XML_ERROR_PARSING_UNKNOWN, 3);
|
||||||
T.TestParseError("ErrorLine-Element", "\n<root>\n<unclosed \n", XML_ERROR_PARSING_ELEMENT, 3);
|
tester.TestParseError("ErrorLine-Element", "\n<root>\n<unclosed \n", XML_ERROR_PARSING_ELEMENT, 3);
|
||||||
T.TestParseError("ErrorLine-Attribute", "\n<root>\n<unclosed \n att\n", XML_ERROR_PARSING_ATTRIBUTE, 4);
|
tester.TestParseError("ErrorLine-Attribute", "\n<root>\n<unclosed \n att\n", XML_ERROR_PARSING_ATTRIBUTE, 4);
|
||||||
T.TestParseError("ErrorLine-ElementClose", "\n<root>\n<unclosed \n/unexpected", XML_ERROR_PARSING_ELEMENT, 3);
|
tester.TestParseError("ErrorLine-ElementClose", "\n<root>\n<unclosed \n/unexpected", XML_ERROR_PARSING_ELEMENT, 3);
|
||||||
|
|
||||||
T.TestStringLines(
|
tester.TestStringLines(
|
||||||
"LineNumbers-String",
|
"LineNumbers-String",
|
||||||
"<?xml version=\"1.0\"?>\n"
|
|
||||||
"<root a='b' \n"
|
"<?xml version=\"1.0\"?>\n" // 1 Doc, DecL
|
||||||
"c='d'> d <blah/> \n"
|
"<root a='b' \n" // 2 Element Attribute
|
||||||
"newline in text \n"
|
"c='d'> d <blah/> \n" // 3 Attribute Text Element
|
||||||
"and second <zxcv/><![CDATA[\n"
|
"newline in text \n" // 4 Text
|
||||||
" cdata test ]]><!-- comment -->\n"
|
"and second <zxcv/><![CDATA[\n" // 5 Element Text
|
||||||
"<! unknown></root>",
|
" cdata test ]]><!-- comment -->\n" // 6 Comment
|
||||||
|
"<! unknown></root>", // 7 Unknown
|
||||||
|
|
||||||
"D01L01E02A02A03T03E03T04E05T05C06U07");
|
"D01L01E02A02A03T03E03T04E05T05C06U07");
|
||||||
|
|
||||||
T.TestStringLines(
|
tester.TestStringLines(
|
||||||
"LineNumbers-CRLF",
|
"LineNumbers-CRLF",
|
||||||
"\r\n"
|
|
||||||
"<?xml version=\"1.0\"?>\n"
|
"\r\n" // 1 Doc (arguably should be line 2)
|
||||||
"<root>\r\n"
|
"<?xml version=\"1.0\"?>\n" // 2 DecL
|
||||||
"\n"
|
"<root>\r\n" // 3 Element
|
||||||
"text contining new line \n"
|
"\n" // 4
|
||||||
" and also containing crlf \r\n"
|
"text contining new line \n" // 5 Text
|
||||||
"<sub><![CDATA[\n"
|
" and also containing crlf \r\n" // 6
|
||||||
"cdata containing new line \n"
|
"<sub><![CDATA[\n" // 7 Element Text
|
||||||
" and also containing cflr\r\n"
|
"cdata containing new line \n" // 8
|
||||||
"]]></sub><sub2/></root>",
|
" and also containing cflr\r\n" // 9
|
||||||
|
"]]></sub><sub2/></root>", // 10 Element
|
||||||
|
|
||||||
"D01L02E03T05E07T07E10");
|
"D01L02E03T05E07T07E10");
|
||||||
|
|
||||||
T.TestFileLines(
|
tester.TestFileLines(
|
||||||
"LineNumbers-File",
|
"LineNumbers-File",
|
||||||
"resources/utf8test.xml",
|
"resources/utf8test.xml",
|
||||||
"D01L01E02E03A03A03T03E04A04A04T04E05A05A05T05E06A06A06T06E07A07A07T07E08A08A08T08E09T09E10T10");
|
"D01L01E02E03A03A03T03E04A04A04T04E05A05A05T05E06A06A06T06E07A07A07T07E08A08A08T08E09T09E10T10");
|
||||||
|
|
Loading…
Reference in New Issue