Ticket #1318: Make sure error ids are unique
This commit is contained in:
parent
f8cceface5
commit
c39f80d361
20
Makefile
20
Makefile
|
@ -60,7 +60,11 @@ TESTOBJ = test/testautovariables.o \
|
||||||
test/testtokenize.o \
|
test/testtokenize.o \
|
||||||
test/testunusedfunctions.o \
|
test/testunusedfunctions.o \
|
||||||
test/testunusedprivfunc.o \
|
test/testunusedprivfunc.o \
|
||||||
test/testunusedvar.o
|
test/testunusedvar.o \
|
||||||
|
test/tinyxml/tinystr.o \
|
||||||
|
test/tinyxml/tinyxml.o \
|
||||||
|
test/tinyxml/tinyxmlerror.o \
|
||||||
|
test/tinyxml/tinyxmlparser.o
|
||||||
|
|
||||||
|
|
||||||
###### Targets
|
###### Targets
|
||||||
|
@ -176,7 +180,7 @@ test/testclass.o: test/testclass.cpp lib/tokenize.h lib/classinfo.h lib/token.h
|
||||||
test/testconstructors.o: test/testconstructors.cpp lib/tokenize.h lib/classinfo.h lib/token.h lib/checkclass.h lib/check.h lib/settings.h lib/errorlogger.h test/testsuite.h
|
test/testconstructors.o: test/testconstructors.cpp lib/tokenize.h lib/classinfo.h lib/token.h lib/checkclass.h lib/check.h lib/settings.h lib/errorlogger.h test/testsuite.h
|
||||||
$(CXX) $(CXXFLAGS) -Ilib -c -o test/testconstructors.o test/testconstructors.cpp
|
$(CXX) $(CXXFLAGS) -Ilib -c -o test/testconstructors.o test/testconstructors.cpp
|
||||||
|
|
||||||
test/testcppcheck.o: test/testcppcheck.cpp lib/cppcheck.h lib/settings.h lib/errorlogger.h lib/checkunusedfunctions.h lib/check.h lib/token.h lib/tokenize.h lib/classinfo.h test/testsuite.h
|
test/testcppcheck.o: test/testcppcheck.cpp lib/cppcheck.h lib/settings.h lib/errorlogger.h lib/checkunusedfunctions.h lib/check.h lib/token.h lib/tokenize.h lib/classinfo.h test/testsuite.h test/tinyxml/tinyxml.h test/tinyxml/tinystr.h
|
||||||
$(CXX) $(CXXFLAGS) -Ilib -c -o test/testcppcheck.o test/testcppcheck.cpp
|
$(CXX) $(CXXFLAGS) -Ilib -c -o test/testcppcheck.o test/testcppcheck.cpp
|
||||||
|
|
||||||
test/testdangerousfunctions.o: test/testdangerousfunctions.cpp lib/tokenize.h lib/classinfo.h lib/token.h lib/checkdangerousfunctions.h lib/check.h lib/settings.h lib/errorlogger.h test/testsuite.h
|
test/testdangerousfunctions.o: test/testdangerousfunctions.cpp lib/tokenize.h lib/classinfo.h lib/token.h lib/checkdangerousfunctions.h lib/check.h lib/settings.h lib/errorlogger.h test/testsuite.h
|
||||||
|
@ -236,3 +240,15 @@ test/testunusedprivfunc.o: test/testunusedprivfunc.cpp lib/tokenize.h lib/classi
|
||||||
test/testunusedvar.o: test/testunusedvar.cpp test/testsuite.h lib/errorlogger.h lib/settings.h lib/tokenize.h lib/classinfo.h lib/token.h lib/checkother.h lib/check.h
|
test/testunusedvar.o: test/testunusedvar.cpp test/testsuite.h lib/errorlogger.h lib/settings.h lib/tokenize.h lib/classinfo.h lib/token.h lib/checkother.h lib/check.h
|
||||||
$(CXX) $(CXXFLAGS) -Ilib -c -o test/testunusedvar.o test/testunusedvar.cpp
|
$(CXX) $(CXXFLAGS) -Ilib -c -o test/testunusedvar.o test/testunusedvar.cpp
|
||||||
|
|
||||||
|
test/tinyxml/tinystr.o: test/tinyxml/tinystr.cpp test/tinyxml/tinystr.h
|
||||||
|
$(CXX) $(CXXFLAGS) -Ilib -c -o test/tinyxml/tinystr.o test/tinyxml/tinystr.cpp
|
||||||
|
|
||||||
|
test/tinyxml/tinyxml.o: test/tinyxml/tinyxml.cpp test/tinyxml/tinyxml.h test/tinyxml/tinystr.h
|
||||||
|
$(CXX) $(CXXFLAGS) -Ilib -c -o test/tinyxml/tinyxml.o test/tinyxml/tinyxml.cpp
|
||||||
|
|
||||||
|
test/tinyxml/tinyxmlerror.o: test/tinyxml/tinyxmlerror.cpp test/tinyxml/tinyxml.h test/tinyxml/tinystr.h
|
||||||
|
$(CXX) $(CXXFLAGS) -Ilib -c -o test/tinyxml/tinyxmlerror.o test/tinyxml/tinyxmlerror.cpp
|
||||||
|
|
||||||
|
test/tinyxml/tinyxmlparser.o: test/tinyxml/tinyxmlparser.cpp test/tinyxml/tinyxml.h test/tinyxml/tinystr.h
|
||||||
|
$(CXX) $(CXXFLAGS) -Ilib -c -o test/tinyxml/tinyxmlparser.o test/tinyxml/tinyxmlparser.cpp
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ CheckStl instance;
|
||||||
// Error message for bad iterator usage..
|
// Error message for bad iterator usage..
|
||||||
void CheckStl::invalidIteratorError(const Token *tok, const std::string &iteratorName)
|
void CheckStl::invalidIteratorError(const Token *tok, const std::string &iteratorName)
|
||||||
{
|
{
|
||||||
reportError(tok, Severity::error, "invalidIterator", "Invalid iterator: " + iteratorName);
|
reportError(tok, Severity::error, "invalidIterator1", "Invalid iterator: " + iteratorName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckStl::iteratorsError(const Token *tok, const std::string &container1, const std::string &container2)
|
void CheckStl::iteratorsError(const Token *tok, const std::string &container1, const std::string &container2)
|
||||||
|
@ -474,7 +474,7 @@ void CheckStl::pushback()
|
||||||
// Error message for bad iterator usage..
|
// Error message for bad iterator usage..
|
||||||
void CheckStl::invalidIteratorError(const Token *tok, const std::string &func, const std::string &iterator_name)
|
void CheckStl::invalidIteratorError(const Token *tok, const std::string &func, const std::string &iterator_name)
|
||||||
{
|
{
|
||||||
reportError(tok, Severity::error, "invalidIterator", "After " + func + ", the iterator '" + iterator_name + "' may be invalid");
|
reportError(tok, Severity::error, "invalidIterator2", "After " + func + ", the iterator '" + iterator_name + "' may be invalid");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -489,6 +489,7 @@ bool CppCheck::parseFromArgs(int argc, const char* const argv[])
|
||||||
else if (strcmp(argv[i], "--errorlist") == 0)
|
else if (strcmp(argv[i], "--errorlist") == 0)
|
||||||
{
|
{
|
||||||
getErrorMessages();
|
getErrorMessages();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentation..
|
// documentation..
|
||||||
|
|
|
@ -28,6 +28,9 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
|
// use tinyxml with STL
|
||||||
|
#include "tinyxml/tinyxml.h"
|
||||||
|
|
||||||
extern std::ostringstream errout;
|
extern std::ostringstream errout;
|
||||||
extern std::ostringstream output;
|
extern std::ostringstream output;
|
||||||
|
|
||||||
|
@ -72,6 +75,33 @@ private:
|
||||||
return cppCheck.parseFromArgs(argc, argv);
|
return cppCheck.parseFromArgs(argc, argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool argCheckWithCoutCerrRedirect(int argc, const char * argv[])
|
||||||
|
{
|
||||||
|
// redirect cout and cerr
|
||||||
|
std::stringstream out, err;
|
||||||
|
std::streambuf* oldCout, *oldCerr;
|
||||||
|
|
||||||
|
// flush all old output
|
||||||
|
std::cout.flush();
|
||||||
|
std::cerr.flush();
|
||||||
|
|
||||||
|
oldCout = std::cout.rdbuf(); // back up cout's streambuf
|
||||||
|
oldCerr = std::cerr.rdbuf(); // back up cerr's streambuf
|
||||||
|
|
||||||
|
std::cout.rdbuf(out.rdbuf()); // assign streambuf to cout
|
||||||
|
std::cerr.rdbuf(err.rdbuf()); // assign streambuf to cerr
|
||||||
|
|
||||||
|
bool result = argCheck(argc, argv);
|
||||||
|
|
||||||
|
std::cout.rdbuf(oldCout); // restore cout's original streambuf
|
||||||
|
std::cerr.rdbuf(oldCerr); // restore cerrs's original streambuf
|
||||||
|
|
||||||
|
errout << err.str();
|
||||||
|
output << out.str();
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
bool argCheckWithCheck(int argc, const char *argv[], const std::string &data)
|
bool argCheckWithCheck(int argc, const char *argv[], const std::string &data)
|
||||||
{
|
{
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
@ -147,8 +177,47 @@ private:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void parseErrorList(const char* xmlData)
|
||||||
|
{
|
||||||
|
TiXmlDocument doc;
|
||||||
|
doc.Parse(xmlData);
|
||||||
|
// parsing must be successfull
|
||||||
|
ASSERT_EQUALS(false, doc.Error());
|
||||||
|
// root element must be "results"
|
||||||
|
TiXmlElement* root = doc.FirstChildElement();
|
||||||
|
ASSERT_EQUALS("results", root->Value());
|
||||||
|
|
||||||
|
TiXmlElement* error = root->FirstChildElement();
|
||||||
|
std::list<std::string> idList;
|
||||||
|
|
||||||
|
while (error)
|
||||||
|
{
|
||||||
|
// only childs of type "error"
|
||||||
|
ASSERT_EQUALS("error", error->Value());
|
||||||
|
// attributes id, msg, severity
|
||||||
|
ASSERT_EQUALS(error->Attribute("msg") == NULL, false);
|
||||||
|
ASSERT_EQUALS(error->Attribute("severity") == NULL, false);
|
||||||
|
const char* id = error->Attribute("id");
|
||||||
|
ASSERT_EQUALS(id == NULL, false);
|
||||||
|
// no duplicate ids
|
||||||
|
std::stringstream msg;
|
||||||
|
msg << "Duplicate id " << id;
|
||||||
|
ASSERT_EQUALS_MSG(idList.end() == std::find(idList.begin(), idList.end(), id), true, msg.str());
|
||||||
|
idList.push_back(id);
|
||||||
|
error = error->NextSiblingElement();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void parseOutputtingArgs()
|
void parseOutputtingArgs()
|
||||||
{
|
{
|
||||||
|
{
|
||||||
|
const char *argv[] = { "cppcheck", "--errorlist" };
|
||||||
|
ASSERT_EQUALS(true, argCheckWithCoutCerrRedirect(2, argv));
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
parseErrorList(output.str().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const char *argv[] = {"cppcheck", "--help"};
|
const char *argv[] = {"cppcheck", "--help"};
|
||||||
ASSERT_EQUALS(true, argCheck(2, argv));
|
ASSERT_EQUALS(true, argCheck(2, argv));
|
||||||
|
|
|
@ -114,7 +114,7 @@ void TestFixture::assert(const char *filename, int linenr, bool condition)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestFixture::assertEquals(const char *filename, int linenr, const std::string &expected, const std::string &actual)
|
void TestFixture::assertEquals(const char *filename, int linenr, const std::string &expected, const std::string &actual, const std::string &msg)
|
||||||
{
|
{
|
||||||
if (expected != actual)
|
if (expected != actual)
|
||||||
{
|
{
|
||||||
|
@ -125,16 +125,19 @@ void TestFixture::assertEquals(const char *filename, int linenr, const std::stri
|
||||||
<< writestr(expected) << std::endl
|
<< writestr(expected) << std::endl
|
||||||
<< "Actual:" << std::endl
|
<< "Actual:" << std::endl
|
||||||
<< writestr(actual) << std::endl;
|
<< writestr(actual) << std::endl;
|
||||||
|
if (!msg.empty()) {
|
||||||
|
errmsg << msg << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestFixture::assertEquals(const char *filename, int linenr, double expected, double actual)
|
void TestFixture::assertEquals(const char *filename, int linenr, double expected, double actual, const std::string &msg)
|
||||||
{
|
{
|
||||||
std::ostringstream ostr1;
|
std::ostringstream ostr1;
|
||||||
ostr1 << expected;
|
ostr1 << expected;
|
||||||
std::ostringstream ostr2;
|
std::ostringstream ostr2;
|
||||||
ostr2 << actual;
|
ostr2 << actual;
|
||||||
assertEquals(filename, linenr, ostr1.str(), ostr2.str());
|
assertEquals(filename, linenr, ostr1.str(), ostr2.str(), msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestFixture::todoAssertEquals(const char *filename, int linenr, const std::string &expected, const std::string &actual)
|
void TestFixture::todoAssertEquals(const char *filename, int linenr, const std::string &expected, const std::string &actual)
|
||||||
|
@ -203,9 +206,12 @@ size_t TestFixture::runTests(const char cmd[])
|
||||||
|
|
||||||
std::cout << "\n\nTesting Complete\nNumber of tests: " << countTests << "\n";
|
std::cout << "\n\nTesting Complete\nNumber of tests: " << countTests << "\n";
|
||||||
std::cout << "Number of todos: " << todos_counter << "\n";
|
std::cout << "Number of todos: " << todos_counter << "\n";
|
||||||
|
// calling flush here, to do all output before the error messages (in case the output is buffered)
|
||||||
|
std::cout.flush();
|
||||||
|
|
||||||
|
std::cerr << "Tests failed: " << fails_counter << "\n";
|
||||||
std::cerr << errmsg.str();
|
std::cerr << errmsg.str();
|
||||||
|
std::cerr.flush();
|
||||||
return fails_counter;
|
return fails_counter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,11 +43,11 @@ protected:
|
||||||
|
|
||||||
void assert(const char *filename, int linenr, bool condition);
|
void assert(const char *filename, int linenr, bool condition);
|
||||||
|
|
||||||
void assertEquals(const char *filename, int linenr, const std::string &expected, const std::string &actual);
|
void assertEquals(const char *filename, int linenr, const std::string &expected, const std::string &actual, const std::string &msg = "");
|
||||||
|
|
||||||
// the vars expected and actual need to be of type double, in order to avoid overflow of unsigned int
|
// the vars expected and actual need to be of type double, in order to avoid overflow of unsigned int
|
||||||
// e.g: ASSERT_EQUALS(-100.0, MathLib::toDoubleNumber("-1.0E+2")); whould not work without this.
|
// e.g: ASSERT_EQUALS(-100.0, MathLib::toDoubleNumber("-1.0E+2")); whould not work without this.
|
||||||
void assertEquals(const char *filename, int linenr, double expected, double actual);
|
void assertEquals(const char *filename, int linenr, double expected, double actual, const std::string &msg="");
|
||||||
|
|
||||||
void todoAssertEquals(const char *filename, int linenr, const std::string &expected, const std::string &actual);
|
void todoAssertEquals(const char *filename, int linenr, const std::string &expected, const std::string &actual);
|
||||||
void todoAssertEquals(const char *filename, int linenr, unsigned int expected, unsigned int actual);
|
void todoAssertEquals(const char *filename, int linenr, unsigned int expected, unsigned int actual);
|
||||||
|
@ -70,6 +70,7 @@ public:
|
||||||
#define TEST_CASE( NAME ) if ( runTest(#NAME) ) NAME ();
|
#define TEST_CASE( NAME ) if ( runTest(#NAME) ) NAME ();
|
||||||
#define ASSERT( CONDITION ) assert(__FILE__, __LINE__, CONDITION)
|
#define ASSERT( CONDITION ) assert(__FILE__, __LINE__, CONDITION)
|
||||||
#define ASSERT_EQUALS( EXPECTED , ACTUAL ) assertEquals(__FILE__, __LINE__, EXPECTED, ACTUAL)
|
#define ASSERT_EQUALS( EXPECTED , ACTUAL ) assertEquals(__FILE__, __LINE__, EXPECTED, ACTUAL)
|
||||||
|
#define ASSERT_EQUALS_MSG( EXPECTED , ACTUAL, MSG ) assertEquals(__FILE__, __LINE__, EXPECTED, ACTUAL, MSG)
|
||||||
#define ASSERT_THROW( CMD, EXCEPTION ) try { CMD ; assertThrowFail(__FILE__, __LINE__); } catch (EXCEPTION &) { } catch (...) { assertThrowFail(__FILE__, __LINE__); }
|
#define ASSERT_THROW( CMD, EXCEPTION ) try { CMD ; assertThrowFail(__FILE__, __LINE__); } catch (EXCEPTION &) { } catch (...) { assertThrowFail(__FILE__, __LINE__); }
|
||||||
#define TODO_ASSERT_EQUALS( EXPECTED , ACTUAL ) todoAssertEquals(__FILE__, __LINE__, EXPECTED, ACTUAL)
|
#define TODO_ASSERT_EQUALS( EXPECTED , ACTUAL ) todoAssertEquals(__FILE__, __LINE__, EXPECTED, ACTUAL)
|
||||||
#define REGISTER_TEST( CLASSNAME ) namespace { CLASSNAME instance; }
|
#define REGISTER_TEST( CLASSNAME ) namespace { CLASSNAME instance; }
|
||||||
|
|
|
@ -0,0 +1,290 @@
|
||||||
|
Changes in version 1.0.1:
|
||||||
|
- Fixed comment tags which were outputing as '<?--' instead of
|
||||||
|
the correct '<!--'.
|
||||||
|
- Implemented the Next and Prev methods of the TiXmlAttribute class.
|
||||||
|
- Renamed 'LastAttribtute' to 'LastAttribute'
|
||||||
|
- Fixed bad pointer to 'isspace' that could occur while parsing text.
|
||||||
|
- Errors finding beginning and end of tags no longer throw it into an
|
||||||
|
infinite loop. (Hopefully.)
|
||||||
|
|
||||||
|
Changes in version 1.0.2
|
||||||
|
- Minor documentation fixes.
|
||||||
|
|
||||||
|
Changes in version 1.0.3
|
||||||
|
- After nodes are added to a document, they return a pointer
|
||||||
|
to the new node instead of a bool for success.
|
||||||
|
- Elements can be constructed with a value, which is the
|
||||||
|
element name. Every element must have a value or it will be
|
||||||
|
invalid, but the code changes to enforce this are not fully
|
||||||
|
in place.
|
||||||
|
|
||||||
|
Changes in version 1.1.0
|
||||||
|
- Added the TiXmlAttributeSet class to pull the attributes into
|
||||||
|
a seperate container.
|
||||||
|
- Moved the doubly liked list out of XmlBase. Now XmlBase only
|
||||||
|
requires the Print() function and defines some utility functions.
|
||||||
|
- Moved errors into a seperate file. (With the idea of internationalization
|
||||||
|
to the other latin-1 languages.)
|
||||||
|
- Added the "NodeType"
|
||||||
|
- Fixed white space parsing in text to conform with the standard.
|
||||||
|
Basically, all white space becomes just one space.
|
||||||
|
- Added the TiXmlDeclaration class to read xml declarations.
|
||||||
|
|
||||||
|
Changes in version 1.2.0
|
||||||
|
- Removed the factory. The factory was not really in the spirit
|
||||||
|
of small and simple, confused the code, and was of limited value.
|
||||||
|
- Added FirstChildElement and NextSiblingElement, because they
|
||||||
|
are such common functions.
|
||||||
|
- Re-wrote the example to test and demonstrate more functionality.
|
||||||
|
|
||||||
|
Changes in version 1.2.1
|
||||||
|
- Fixed a bug where comments couldn't be inside elements.
|
||||||
|
- Loading now clears out existing XML rather than appending.
|
||||||
|
- Added the "Clear" method on a node to delete all its children.
|
||||||
|
|
||||||
|
Changes in version 1.2.2
|
||||||
|
- Fixed TiXmlAttribute::Previous actually returning "next." Thanks
|
||||||
|
to Rickard Troedsson for the bug fix.
|
||||||
|
|
||||||
|
Changes in version 1.2.3
|
||||||
|
- Added the TIXML prefix to the error strings to resolve conflicts
|
||||||
|
with #defines in OS headers. Thanks to Steve Lhomme.
|
||||||
|
- Fixed a delete buf that should be a delete [] buf.
|
||||||
|
Thanks to Ephi Sinowitz.
|
||||||
|
|
||||||
|
Changes in version 1.2.4
|
||||||
|
- ReplaceChild() was almost guarenteed to fail. Should be fixed,
|
||||||
|
thanks to Joe Smith. Joe also pointed out that the Print() functions
|
||||||
|
should take stream references: I agree, and would like to overload
|
||||||
|
the Print() method to take either format, but I don't want to do
|
||||||
|
this in a dot release.
|
||||||
|
- Some compilers seem to need an extra <ctype.h> include. Thanks
|
||||||
|
to Steve Lhomme for that.
|
||||||
|
|
||||||
|
Changes in version 2.0.0 BETA
|
||||||
|
- Made the ToXXX() casts safe if 'this' is null.
|
||||||
|
When "LoadFile" is called with a filename, the value will correctly get set.
|
||||||
|
Thanks to Brian Yoder.
|
||||||
|
- Fixed bug where isalpha() and isalnum() would get called with a negative value for
|
||||||
|
high ascii numbers. Thanks to Alesky Aksenov.
|
||||||
|
- Fixed some errors codes that were not getting set.
|
||||||
|
- Made methods "const" that were not.
|
||||||
|
- Added a switch to enable or disable the ignoring of white space. ( TiXmlDocument::SetIgnoreWhiteSpace() )
|
||||||
|
- Greater standardization and code re-use in the parser.
|
||||||
|
- Added a stream out operator.
|
||||||
|
- Added a stream in operator.
|
||||||
|
- Entity support, of predefined entites. &#x entities are untouched by input or output.
|
||||||
|
- Improved text out formatting.
|
||||||
|
- Fixed ReplaceChild bug, thanks to Tao Chen.
|
||||||
|
|
||||||
|
Changes in version 2.0.1
|
||||||
|
- Fixed hanging on loading a 0 length file. Thanks to Jeff Scozzafava.
|
||||||
|
- Fixed crashing on InsertBeforeChild and InsertAfterChild. Also possibility of bad links being
|
||||||
|
created by same function. Thanks to Frank De prins.
|
||||||
|
- Added missing licence text. Thanks to Lars Willemsens.
|
||||||
|
- Added <ctype.h> include, at the suggestion of Steve Walters.
|
||||||
|
|
||||||
|
Changes in version 2.1.0
|
||||||
|
- Yves Berquin brings us the STL switch. The forum on SourceForge, and various emails to
|
||||||
|
me, have long debated all out STL vs. no STL at all. And now you can have it both ways.
|
||||||
|
TinyXml will compile either way.
|
||||||
|
|
||||||
|
Changes in version 2.1.1
|
||||||
|
- Compilation warnings.
|
||||||
|
|
||||||
|
Changes in version 2.1.2
|
||||||
|
- Uneeded code is not compiled in the STL case.
|
||||||
|
- Changed headers so that STL can be turned on or off in tinyxml.h
|
||||||
|
|
||||||
|
Changes in version 2.1.3
|
||||||
|
- Fixed non-const reference in API; now uses a pointer.
|
||||||
|
- Copy constructor of TiXmlString not checking for assignment to self.
|
||||||
|
- Nimrod Cohen found a truly evil bug in the STL implementation that occurs
|
||||||
|
when a string is converted to a c_str and then assigned to self. Search for
|
||||||
|
STL_STRING_BUG for a full description. I'm asserting this is a Microsoft STL
|
||||||
|
bug, since &string and string.c_str() should never be the same. Nevertheless,
|
||||||
|
the code works around it.
|
||||||
|
- Urivan Saaib pointed out a compiler conflict, where the C headers define
|
||||||
|
the isblank macro, which was wiping out the TiXmlString::isblank() method.
|
||||||
|
The method was unused and has been removed.
|
||||||
|
|
||||||
|
Changes in version 2.1.4
|
||||||
|
- Reworked the entity code. Entities were not correctly surving round trip input and output.
|
||||||
|
Will now automatically create entities for high ascii in output.
|
||||||
|
|
||||||
|
Changes in version 2.1.5
|
||||||
|
- Bug fix by kylotan : infinite loop on some input (tinyxmlparser.cpp rev 1.27)
|
||||||
|
- Contributed by Ivica Aracic (bytelord) : 1 new VC++ project to compile versions as static libraries (tinyxml_lib.dsp),
|
||||||
|
and an example usage in xmltest.dsp
|
||||||
|
(Patch request ID 678605)
|
||||||
|
- A suggestion by Ronald Fenner Jr (dormlock) to add #include <istream> and <ostream> for Apple's Project Builder
|
||||||
|
(Patch request ID 697642)
|
||||||
|
- A patch from ohommes that allows to parse correctly dots in element names and attribute names
|
||||||
|
(Patch request 602600 and kylotan 701728)
|
||||||
|
- A patch from hermitgeek ( James ) and wasteland for improper error reporting
|
||||||
|
- Reviewed by Lee, with the following changes:
|
||||||
|
- Got sick of fighting the STL/non-STL thing in the windows build. Broke
|
||||||
|
them out as seperate projects.
|
||||||
|
- I have too long not included the dsw. Added.
|
||||||
|
- TinyXmlText had a protected Print. Odd.
|
||||||
|
- Made LinkEndChild public, with docs and appropriate warnings.
|
||||||
|
- Updated the docs.
|
||||||
|
|
||||||
|
2.2.0
|
||||||
|
- Fixed an uninitialized pointer in the TiXmlAttributes
|
||||||
|
- Fixed STL compilation problem in MinGW (and gcc 3?) - thanks Brian Yoder for finding this one
|
||||||
|
- Fixed a syntax error in TiXmlDeclaration - thanks Brian Yoder
|
||||||
|
- Fletcher Dunn proposed and submitted new error handling that tracked the row and column. Lee
|
||||||
|
modified it to not have performance impact.
|
||||||
|
- General cleanup suggestions from Fletcher Dunn.
|
||||||
|
- In error handling, general errors will no longer clear the error state of specific ones.
|
||||||
|
- Fix error in documentation : comments starting with "<?--" instead of "<!--" (thanks ion_pulse)
|
||||||
|
- Added the TiXmlHandle. An easy, safe way to browse XML DOMs with less code.
|
||||||
|
- Added QueryAttribute calls which have better error messaging. (Proposed by Fletcher Dunn)
|
||||||
|
- Nodes and attributes can now print themselves to strings. (Yves suggestion)
|
||||||
|
- Fixed bug where entities with one character would confuse parser. (Thanks Roman)
|
||||||
|
|
||||||
|
2.2.1
|
||||||
|
- Additional testing (no more bugs found to be fixed in this release)
|
||||||
|
- Significant performance improvement to the cursor code.
|
||||||
|
|
||||||
|
2.3.0
|
||||||
|
- User Data are now defined in TiXmlBase instead of TiXmlNode
|
||||||
|
- Character Entities are now UCS-2
|
||||||
|
- Character Entities can be decimal or hexadecimal
|
||||||
|
- UTF-8 conversion.
|
||||||
|
- Fixed many, many bugs.
|
||||||
|
|
||||||
|
2.3.1
|
||||||
|
- Fixed bug in handling nulls embedded in the input.
|
||||||
|
- Make UTF-8 parser tolerant of bad text encoding.
|
||||||
|
- Added encoding detection.
|
||||||
|
- Many fixes and input from John-Philip Leonard Johansson (JP) and Ellers,
|
||||||
|
including UTF-8 feedback, bug reports, and patches. Thanks!
|
||||||
|
- Added version # constants - a suggestion from JP and Ellers.
|
||||||
|
- [ 979180 ] Missing ; in entity reference, fix from Rob Laveaux.
|
||||||
|
- Copy constructors and assignment have been a long time coming. Thanks to
|
||||||
|
Fokke and JP.
|
||||||
|
|
||||||
|
2.3.2
|
||||||
|
- Made the IsAlpha and IsAlphaNum much more tolerant of non-UTF-8 encodings. Thanks
|
||||||
|
Volker Boerchers for finding the issue.
|
||||||
|
- Ran the program though the magnificent Valgrind - http://valgrind.kde.org - to check
|
||||||
|
for memory errors. Fixed some minor issues.
|
||||||
|
|
||||||
|
2.3.3
|
||||||
|
- Fixed crash when test program was run from incorrect directory.
|
||||||
|
- Fixed bug 1070717 - empty document not returned correctly - thanks Katsuhisa Yuasa.
|
||||||
|
- Bug 1079301 resolved - deprecated stdlib calls. Thanks Adrian Boeing.
|
||||||
|
- Bug 1035218 fixed - documentation errors. Xunji Luo
|
||||||
|
- Other bug fixes have accumulated and been fixed on the way as well; my apologies to
|
||||||
|
authors not credited!
|
||||||
|
- Big fix / addition is to correctly return const values. TinyXml could basically
|
||||||
|
remove const in a method like this: TiXmlElement* Foo() const, where the returned element
|
||||||
|
was a pointer to internal data. That is now: const TiXmlElement* Foo() const and
|
||||||
|
TiXmlElement* Foo().
|
||||||
|
|
||||||
|
2.3.4
|
||||||
|
- Fixed additional const errors, thanks Kent Gibson.
|
||||||
|
- Correctly re-enable warnings after tinyxml header. Thanks Cory Nelson.
|
||||||
|
- Variety of type cleanup and warning fixes. Thanks Warren Stevens.
|
||||||
|
- Cleaned up unneeded constructor calls in TinyString - thanks to Geoff Carlton and
|
||||||
|
the discussion group on sourceforge.
|
||||||
|
|
||||||
|
2.4.0
|
||||||
|
- Improved string class, thanks Tyge Lovset (whose name gets mangled in English - sorry)
|
||||||
|
- Type cast compiler warning, thanks Rob van den Bogaard
|
||||||
|
- Added GetText() convenience function. Thanks Ilya Parniuk & Andrew Ellers for input.
|
||||||
|
- Many thanks to marlonism for finding an infinite loop in bad xml.
|
||||||
|
- A patch to cleanup warnings from Robert Gebis.
|
||||||
|
- Added ValueStr() to get the value of a node as a string.
|
||||||
|
- TiXmlText can now parse and output as CDATA
|
||||||
|
- Additional string improvement from James (z2895)
|
||||||
|
- Removed extraneous 'const', thanks David Aldrich
|
||||||
|
- First pass at switching to the "safe" stdlib functions. Many people have suggested and
|
||||||
|
pushed on this, but Warren Stevens put together the first proposal.
|
||||||
|
- TinyXml now will do EOL normalization before parsing, consistent with the W3C XML spec.
|
||||||
|
- Documents loaded with the UTF-8 BOM will now save with the UTF-8 BOM. Good suggestion
|
||||||
|
from 'instructor_'
|
||||||
|
- Ellers submitted his very popular tutorials, which have been added to the distribution.
|
||||||
|
|
||||||
|
2.4.1
|
||||||
|
- Fixed CDATA output formatting
|
||||||
|
- Fixed memory allocators in TinyString to work with overloaded new/delete
|
||||||
|
|
||||||
|
2.4.2
|
||||||
|
- solosnake pointed out that TIXML_LOG causes problems on an XBOX. The definition in the header
|
||||||
|
was superflous and was moved inside of DEBUG_PARSING
|
||||||
|
|
||||||
|
2.4.3
|
||||||
|
- Fixed a test bug that caused a crash in 'xmltest'. TinyXML was fine, but it isn't good
|
||||||
|
to ship with a broken test suite.
|
||||||
|
- Started converting some functions to not cast between std::string and const char*
|
||||||
|
quite as often.
|
||||||
|
- Added FILE* versions of the document loads - good suggestion from Wade Brainerd
|
||||||
|
- Empty documents might not always return the errors they should. [1398915] Thanks to igor v.
|
||||||
|
- Added some asserts for multiply adding a node, regardng bug [1391937] suggested by Paco Arjonilla.
|
||||||
|
|
||||||
|
2.4.4
|
||||||
|
- Bug find thanks to andre-gross found a memory leak that occured when a document failed to load.
|
||||||
|
- Bug find (and good analysis) by VirtualJim who found a case where attribute parsing
|
||||||
|
should be throwing an error and wasn't.
|
||||||
|
- Steve Hyatt suggested the QueryValueAttribute method, which is now implemented.
|
||||||
|
- DavidA identified a chunk of dead code.
|
||||||
|
- Andrew Baxter sent in some compiler warnings that were good clean up points.
|
||||||
|
|
||||||
|
2.5
|
||||||
|
- Added the Visit() API. Many thanks to both Andrew Ellerton and John-Philip for all their
|
||||||
|
work, code, suggestion, and just general pushing that it should be done.
|
||||||
|
- Removed existing streaming code and use TiXmlPrinter instead.
|
||||||
|
- [ tinyxml-Bugs-1527079 ] Compile error in tinystr.cpp fixed, thanks to Paul Suggs
|
||||||
|
- [ tinyxml-Bugs-1522890 ] SaveFile has no error checks fixed, thanks to Ivan Dobrokotov
|
||||||
|
- Ivan Dobrokotov also reported redundant memory allocation in the Attribute() method, which
|
||||||
|
upon investigation was a mess. The attribute should now be fixed for both const char* and
|
||||||
|
std::string, and the return types match the input parameters.
|
||||||
|
- Feature [ 1511105 ] Make TiXmlComment constructor accept a string / char*, implemented.
|
||||||
|
Thanks to Karl Itschen for the feedback.
|
||||||
|
- [ 1480108 ] Stream parsing fails when CDATA contains tags was found by Tobias Grimm, who also
|
||||||
|
submitted a test case and patch. A significant bug in CDATA streaming (operator>>) has now
|
||||||
|
been fixed.
|
||||||
|
|
||||||
|
2.5.2
|
||||||
|
- Lieven, and others, pointed out a missing const-cast that upset the Open Watcom compiler.
|
||||||
|
Should now be fixed.
|
||||||
|
- ErrorRow and ErrorCol should have been const, and weren't. Fixed thanks to Dmitry Polutov.
|
||||||
|
|
||||||
|
2.5.3
|
||||||
|
- zloe_zlo identified a missing string specialization for QueryValueAttribute() [ 1695429 ]. Worked
|
||||||
|
on this bug, but not sure how to fix it in a safe, cross-compiler way.
|
||||||
|
- increased warning level to 4 and turned on detect 64 bit portability issues for VC2005.
|
||||||
|
May address [ 1677737 ] VS2005: /Wp64 warnings
|
||||||
|
- grosheck identified several problems with the Document copy. Many thanks for [ 1660367 ]
|
||||||
|
- Nice catch, and suggested fix, be Gilad Novik on the Printer dropping entities.
|
||||||
|
"[ 1600650 ] Bug when printing xml text" is now fixed.
|
||||||
|
- A subtle fix from Nicos Gollan in the tinystring initializer:
|
||||||
|
[ 1581449 ] Fix initialiser of TiXmlString::nullrep_
|
||||||
|
- Great catch, although there isn't a submitter for the bug. [ 1475201 ] TinyXML parses entities in comments.
|
||||||
|
Comments should not, in fact, parse entities. Fixed the code path and added tests.
|
||||||
|
- We were not catching all the returns from ftell. Thanks to Bernard for catching that.
|
||||||
|
|
||||||
|
2.5.4
|
||||||
|
- A TiXMLDocument can't be a sub-node. Block this from happening in the 'replace'. Thanks Noam.
|
||||||
|
- [ 1714831 ] TiXmlBase::location is not copied by copy-ctors, fix reported and suggested by Nicola Civran.
|
||||||
|
- Fixed possible memory overrun in the comment reading code - thanks gcarlton77
|
||||||
|
|
||||||
|
2.5.5
|
||||||
|
- Alex van der Wal spotted incorrect types (lf) being used in print and scan. robertnestor pointed out some problems with the simple solution. Types updated.
|
||||||
|
- Johannes Hillert pointed out some bug typos.
|
||||||
|
- Christian Mueller identified inconsistent error handling with Attributes.
|
||||||
|
- olivier barthelemy also reported a problem with double truncation, also related to the %lf issue.
|
||||||
|
- zaelsius came up with a great (and simple) suggestion to fix QueryValueAttribute truncating strings.
|
||||||
|
- added some null pointer checks suggested by hansenk
|
||||||
|
- Sami Väisänen found a (rare) buffer overrun that could occur in parsing.
|
||||||
|
- vi tri filed a bug that led to a refactoring of the attribute setting mess (as well as adding a missing SetDoubleAttribute() )
|
||||||
|
- removed TIXML_ERROR_OUT_OF_MEMORY. TinyXML does not systematically address OOO, and the notion it does is misleading.
|
||||||
|
- vanneto, keithmarshall, others all reported the warning from IsWhiteSpace() usage. Cleaned this up - many thanks to everyone who reported this one.
|
||||||
|
- tibur found a bug in end tag parsing
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,116 @@
|
||||||
|
/*
|
||||||
|
www.sourceforge.net/projects/tinyxml
|
||||||
|
Original file by Yves Berquin.
|
||||||
|
|
||||||
|
This software is provided 'as-is', without any express or implied
|
||||||
|
warranty. In no event will the authors be held liable for any
|
||||||
|
damages arising from the use of this software.
|
||||||
|
|
||||||
|
Permission is granted to anyone to use this software for any
|
||||||
|
purpose, including commercial applications, and to alter it and
|
||||||
|
redistribute it freely, subject to the following restrictions:
|
||||||
|
|
||||||
|
1. The origin of this software must not be misrepresented; you must
|
||||||
|
not claim that you wrote the original software. If you use this
|
||||||
|
software in a product, an acknowledgment in the product documentation
|
||||||
|
would be appreciated but is not required.
|
||||||
|
|
||||||
|
2. Altered source versions must be plainly marked as such, and
|
||||||
|
must not be misrepresented as being the original software.
|
||||||
|
|
||||||
|
3. This notice may not be removed or altered from any source
|
||||||
|
distribution.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* THIS FILE WAS ALTERED BY Tyge Løvset, 7. April 2005.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef TIXML_USE_STL
|
||||||
|
|
||||||
|
#include "tinystr.h"
|
||||||
|
|
||||||
|
// Error value for find primitive
|
||||||
|
const TiXmlString::size_type TiXmlString::npos = static_cast< TiXmlString::size_type >(-1);
|
||||||
|
|
||||||
|
|
||||||
|
// Null rep.
|
||||||
|
TiXmlString::Rep TiXmlString::nullrep_ = { 0, 0, { '\0' } };
|
||||||
|
|
||||||
|
|
||||||
|
void TiXmlString::reserve (size_type cap)
|
||||||
|
{
|
||||||
|
if (cap > capacity())
|
||||||
|
{
|
||||||
|
TiXmlString tmp;
|
||||||
|
tmp.init(length(), cap);
|
||||||
|
memcpy(tmp.start(), data(), length());
|
||||||
|
swap(tmp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TiXmlString& TiXmlString::assign(const char* str, size_type len)
|
||||||
|
{
|
||||||
|
size_type cap = capacity();
|
||||||
|
if (len > cap || cap > 3*(len + 8))
|
||||||
|
{
|
||||||
|
TiXmlString tmp;
|
||||||
|
tmp.init(len);
|
||||||
|
memcpy(tmp.start(), str, len);
|
||||||
|
swap(tmp);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
memmove(start(), str, len);
|
||||||
|
set_size(len);
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TiXmlString& TiXmlString::append(const char* str, size_type len)
|
||||||
|
{
|
||||||
|
size_type newsize = length() + len;
|
||||||
|
if (newsize > capacity())
|
||||||
|
{
|
||||||
|
reserve (newsize + capacity());
|
||||||
|
}
|
||||||
|
memmove(finish(), str, len);
|
||||||
|
set_size(newsize);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TiXmlString operator + (const TiXmlString & a, const TiXmlString & b)
|
||||||
|
{
|
||||||
|
TiXmlString tmp;
|
||||||
|
tmp.reserve(a.length() + b.length());
|
||||||
|
tmp += a;
|
||||||
|
tmp += b;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
TiXmlString operator + (const TiXmlString & a, const char* b)
|
||||||
|
{
|
||||||
|
TiXmlString tmp;
|
||||||
|
TiXmlString::size_type b_len = static_cast<TiXmlString::size_type>( strlen(b) );
|
||||||
|
tmp.reserve(a.length() + b_len);
|
||||||
|
tmp += a;
|
||||||
|
tmp.append(b, b_len);
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
TiXmlString operator + (const char* a, const TiXmlString & b)
|
||||||
|
{
|
||||||
|
TiXmlString tmp;
|
||||||
|
TiXmlString::size_type a_len = static_cast<TiXmlString::size_type>( strlen(a) );
|
||||||
|
tmp.reserve(a_len + b.length());
|
||||||
|
tmp.append(a, a_len);
|
||||||
|
tmp += b;
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif // TIXML_USE_STL
|
|
@ -0,0 +1,319 @@
|
||||||
|
/*
|
||||||
|
www.sourceforge.net/projects/tinyxml
|
||||||
|
Original file by Yves Berquin.
|
||||||
|
|
||||||
|
This software is provided 'as-is', without any express or implied
|
||||||
|
warranty. In no event will the authors be held liable for any
|
||||||
|
damages arising from the use of this software.
|
||||||
|
|
||||||
|
Permission is granted to anyone to use this software for any
|
||||||
|
purpose, including commercial applications, and to alter it and
|
||||||
|
redistribute it freely, subject to the following restrictions:
|
||||||
|
|
||||||
|
1. The origin of this software must not be misrepresented; you must
|
||||||
|
not claim that you wrote the original software. If you use this
|
||||||
|
software in a product, an acknowledgment in the product documentation
|
||||||
|
would be appreciated but is not required.
|
||||||
|
|
||||||
|
2. Altered source versions must be plainly marked as such, and
|
||||||
|
must not be misrepresented as being the original software.
|
||||||
|
|
||||||
|
3. This notice may not be removed or altered from any source
|
||||||
|
distribution.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* THIS FILE WAS ALTERED BY Tyge Lovset, 7. April 2005.
|
||||||
|
*
|
||||||
|
* - completely rewritten. compact, clean, and fast implementation.
|
||||||
|
* - sizeof(TiXmlString) = pointer size (4 bytes on 32-bit systems)
|
||||||
|
* - fixed reserve() to work as per specification.
|
||||||
|
* - fixed buggy compares operator==(), operator<(), and operator>()
|
||||||
|
* - fixed operator+=() to take a const ref argument, following spec.
|
||||||
|
* - added "copy" constructor with length, and most compare operators.
|
||||||
|
* - added swap(), clear(), size(), capacity(), operator+().
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TIXML_USE_STL
|
||||||
|
|
||||||
|
#ifndef TIXML_STRING_INCLUDED
|
||||||
|
#define TIXML_STRING_INCLUDED
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
/* The support for explicit isn't that universal, and it isn't really
|
||||||
|
required - it is used to check that the TiXmlString class isn't incorrectly
|
||||||
|
used. Be nice to old compilers and macro it here:
|
||||||
|
*/
|
||||||
|
#if defined(_MSC_VER) && (_MSC_VER >= 1200 )
|
||||||
|
// Microsoft visual studio, version 6 and higher.
|
||||||
|
#define TIXML_EXPLICIT explicit
|
||||||
|
#elif defined(__GNUC__) && (__GNUC__ >= 3 )
|
||||||
|
// GCC version 3 and higher.s
|
||||||
|
#define TIXML_EXPLICIT explicit
|
||||||
|
#else
|
||||||
|
#define TIXML_EXPLICIT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
TiXmlString is an emulation of a subset of the std::string template.
|
||||||
|
Its purpose is to allow compiling TinyXML on compilers with no or poor STL support.
|
||||||
|
Only the member functions relevant to the TinyXML project have been implemented.
|
||||||
|
The buffer allocation is made by a simplistic power of 2 like mechanism : if we increase
|
||||||
|
a string and there's no more room, we allocate a buffer twice as big as we need.
|
||||||
|
*/
|
||||||
|
class TiXmlString
|
||||||
|
{
|
||||||
|
public :
|
||||||
|
// The size type used
|
||||||
|
typedef size_t size_type;
|
||||||
|
|
||||||
|
// Error value for find primitive
|
||||||
|
static const size_type npos; // = -1;
|
||||||
|
|
||||||
|
|
||||||
|
// TiXmlString empty constructor
|
||||||
|
TiXmlString () : rep_(&nullrep_)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// TiXmlString copy constructor
|
||||||
|
TiXmlString ( const TiXmlString & copy) : rep_(0)
|
||||||
|
{
|
||||||
|
init(copy.length());
|
||||||
|
memcpy(start(), copy.data(), length());
|
||||||
|
}
|
||||||
|
|
||||||
|
// TiXmlString constructor, based on a string
|
||||||
|
TIXML_EXPLICIT TiXmlString ( const char * copy) : rep_(0)
|
||||||
|
{
|
||||||
|
init( static_cast<size_type>( strlen(copy) ));
|
||||||
|
memcpy(start(), copy, length());
|
||||||
|
}
|
||||||
|
|
||||||
|
// TiXmlString constructor, based on a string
|
||||||
|
TIXML_EXPLICIT TiXmlString ( const char * str, size_type len) : rep_(0)
|
||||||
|
{
|
||||||
|
init(len);
|
||||||
|
memcpy(start(), str, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TiXmlString destructor
|
||||||
|
~TiXmlString ()
|
||||||
|
{
|
||||||
|
quit();
|
||||||
|
}
|
||||||
|
|
||||||
|
// = operator
|
||||||
|
TiXmlString& operator = (const char * copy)
|
||||||
|
{
|
||||||
|
return assign( copy, (size_type)strlen(copy));
|
||||||
|
}
|
||||||
|
|
||||||
|
// = operator
|
||||||
|
TiXmlString& operator = (const TiXmlString & copy)
|
||||||
|
{
|
||||||
|
return assign(copy.start(), copy.length());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// += operator. Maps to append
|
||||||
|
TiXmlString& operator += (const char * suffix)
|
||||||
|
{
|
||||||
|
return append(suffix, static_cast<size_type>( strlen(suffix) ));
|
||||||
|
}
|
||||||
|
|
||||||
|
// += operator. Maps to append
|
||||||
|
TiXmlString& operator += (char single)
|
||||||
|
{
|
||||||
|
return append(&single, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// += operator. Maps to append
|
||||||
|
TiXmlString& operator += (const TiXmlString & suffix)
|
||||||
|
{
|
||||||
|
return append(suffix.data(), suffix.length());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Convert a TiXmlString into a null-terminated char *
|
||||||
|
const char * c_str () const { return rep_->str; }
|
||||||
|
|
||||||
|
// Convert a TiXmlString into a char * (need not be null terminated).
|
||||||
|
const char * data () const { return rep_->str; }
|
||||||
|
|
||||||
|
// Return the length of a TiXmlString
|
||||||
|
size_type length () const { return rep_->size; }
|
||||||
|
|
||||||
|
// Alias for length()
|
||||||
|
size_type size () const { return rep_->size; }
|
||||||
|
|
||||||
|
// Checks if a TiXmlString is empty
|
||||||
|
bool empty () const { return rep_->size == 0; }
|
||||||
|
|
||||||
|
// Return capacity of string
|
||||||
|
size_type capacity () const { return rep_->capacity; }
|
||||||
|
|
||||||
|
|
||||||
|
// single char extraction
|
||||||
|
const char& at (size_type index) const
|
||||||
|
{
|
||||||
|
assert( index < length() );
|
||||||
|
return rep_->str[ index ];
|
||||||
|
}
|
||||||
|
|
||||||
|
// [] operator
|
||||||
|
char& operator [] (size_type index) const
|
||||||
|
{
|
||||||
|
assert( index < length() );
|
||||||
|
return rep_->str[ index ];
|
||||||
|
}
|
||||||
|
|
||||||
|
// find a char in a string. Return TiXmlString::npos if not found
|
||||||
|
size_type find (char lookup) const
|
||||||
|
{
|
||||||
|
return find(lookup, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// find a char in a string from an offset. Return TiXmlString::npos if not found
|
||||||
|
size_type find (char tofind, size_type offset) const
|
||||||
|
{
|
||||||
|
if (offset >= length()) return npos;
|
||||||
|
|
||||||
|
for (const char* p = c_str() + offset; *p != '\0'; ++p)
|
||||||
|
{
|
||||||
|
if (*p == tofind) return static_cast< size_type >( p - c_str() );
|
||||||
|
}
|
||||||
|
return npos;
|
||||||
|
}
|
||||||
|
|
||||||
|
void clear ()
|
||||||
|
{
|
||||||
|
//Lee:
|
||||||
|
//The original was just too strange, though correct:
|
||||||
|
// TiXmlString().swap(*this);
|
||||||
|
//Instead use the quit & re-init:
|
||||||
|
quit();
|
||||||
|
init(0,0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Function to reserve a big amount of data when we know we'll need it. Be aware that this
|
||||||
|
function DOES NOT clear the content of the TiXmlString if any exists.
|
||||||
|
*/
|
||||||
|
void reserve (size_type cap);
|
||||||
|
|
||||||
|
TiXmlString& assign (const char* str, size_type len);
|
||||||
|
|
||||||
|
TiXmlString& append (const char* str, size_type len);
|
||||||
|
|
||||||
|
void swap (TiXmlString& other)
|
||||||
|
{
|
||||||
|
Rep* r = rep_;
|
||||||
|
rep_ = other.rep_;
|
||||||
|
other.rep_ = r;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
void init(size_type sz) { init(sz, sz); }
|
||||||
|
void set_size(size_type sz) { rep_->str[ rep_->size = sz ] = '\0'; }
|
||||||
|
char* start() const { return rep_->str; }
|
||||||
|
char* finish() const { return rep_->str + rep_->size; }
|
||||||
|
|
||||||
|
struct Rep
|
||||||
|
{
|
||||||
|
size_type size, capacity;
|
||||||
|
char str[1];
|
||||||
|
};
|
||||||
|
|
||||||
|
void init(size_type sz, size_type cap)
|
||||||
|
{
|
||||||
|
if (cap)
|
||||||
|
{
|
||||||
|
// Lee: the original form:
|
||||||
|
// rep_ = static_cast<Rep*>(operator new(sizeof(Rep) + cap));
|
||||||
|
// doesn't work in some cases of new being overloaded. Switching
|
||||||
|
// to the normal allocation, although use an 'int' for systems
|
||||||
|
// that are overly picky about structure alignment.
|
||||||
|
const size_type bytesNeeded = sizeof(Rep) + cap;
|
||||||
|
const size_type intsNeeded = ( bytesNeeded + sizeof(int) - 1 ) / sizeof( int );
|
||||||
|
rep_ = reinterpret_cast<Rep*>( new int[ intsNeeded ] );
|
||||||
|
|
||||||
|
rep_->str[ rep_->size = sz ] = '\0';
|
||||||
|
rep_->capacity = cap;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rep_ = &nullrep_;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void quit()
|
||||||
|
{
|
||||||
|
if (rep_ != &nullrep_)
|
||||||
|
{
|
||||||
|
// The rep_ is really an array of ints. (see the allocator, above).
|
||||||
|
// Cast it back before delete, so the compiler won't incorrectly call destructors.
|
||||||
|
delete [] ( reinterpret_cast<int*>( rep_ ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Rep * rep_;
|
||||||
|
static Rep nullrep_;
|
||||||
|
|
||||||
|
} ;
|
||||||
|
|
||||||
|
|
||||||
|
inline bool operator == (const TiXmlString & a, const TiXmlString & b)
|
||||||
|
{
|
||||||
|
return ( a.length() == b.length() ) // optimization on some platforms
|
||||||
|
&& ( strcmp(a.c_str(), b.c_str()) == 0 ); // actual compare
|
||||||
|
}
|
||||||
|
inline bool operator < (const TiXmlString & a, const TiXmlString & b)
|
||||||
|
{
|
||||||
|
return strcmp(a.c_str(), b.c_str()) < 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool operator != (const TiXmlString & a, const TiXmlString & b) { return !(a == b); }
|
||||||
|
inline bool operator > (const TiXmlString & a, const TiXmlString & b) { return b < a; }
|
||||||
|
inline bool operator <= (const TiXmlString & a, const TiXmlString & b) { return !(b < a); }
|
||||||
|
inline bool operator >= (const TiXmlString & a, const TiXmlString & b) { return !(a < b); }
|
||||||
|
|
||||||
|
inline bool operator == (const TiXmlString & a, const char* b) { return strcmp(a.c_str(), b) == 0; }
|
||||||
|
inline bool operator == (const char* a, const TiXmlString & b) { return b == a; }
|
||||||
|
inline bool operator != (const TiXmlString & a, const char* b) { return !(a == b); }
|
||||||
|
inline bool operator != (const char* a, const TiXmlString & b) { return !(b == a); }
|
||||||
|
|
||||||
|
TiXmlString operator + (const TiXmlString & a, const TiXmlString & b);
|
||||||
|
TiXmlString operator + (const TiXmlString & a, const char* b);
|
||||||
|
TiXmlString operator + (const char* a, const TiXmlString & b);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
TiXmlOutStream is an emulation of std::ostream. It is based on TiXmlString.
|
||||||
|
Only the operators that we need for TinyXML have been developped.
|
||||||
|
*/
|
||||||
|
class TiXmlOutStream : public TiXmlString
|
||||||
|
{
|
||||||
|
public :
|
||||||
|
|
||||||
|
// TiXmlOutStream << operator.
|
||||||
|
TiXmlOutStream & operator << (const TiXmlString & in)
|
||||||
|
{
|
||||||
|
*this += in;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TiXmlOutStream << operator.
|
||||||
|
TiXmlOutStream & operator << (const char * in)
|
||||||
|
{
|
||||||
|
*this += in;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
} ;
|
||||||
|
|
||||||
|
#endif // TIXML_STRING_INCLUDED
|
||||||
|
#endif // TIXML_USE_STL
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,52 @@
|
||||||
|
/*
|
||||||
|
www.sourceforge.net/projects/tinyxml
|
||||||
|
Original code (2.0 and earlier )copyright (c) 2000-2006 Lee Thomason (www.grinninglizard.com)
|
||||||
|
|
||||||
|
This software is provided 'as-is', without any express or implied
|
||||||
|
warranty. In no event will the authors be held liable for any
|
||||||
|
damages arising from the use of this software.
|
||||||
|
|
||||||
|
Permission is granted to anyone to use this software for any
|
||||||
|
purpose, including commercial applications, and to alter it and
|
||||||
|
redistribute it freely, subject to the following restrictions:
|
||||||
|
|
||||||
|
1. The origin of this software must not be misrepresented; you must
|
||||||
|
not claim that you wrote the original software. If you use this
|
||||||
|
software in a product, an acknowledgment in the product documentation
|
||||||
|
would be appreciated but is not required.
|
||||||
|
|
||||||
|
2. Altered source versions must be plainly marked as such, and
|
||||||
|
must not be misrepresented as being the original software.
|
||||||
|
|
||||||
|
3. This notice may not be removed or altered from any source
|
||||||
|
distribution.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "tinyxml.h"
|
||||||
|
|
||||||
|
// The goal of the seperate error file is to make the first
|
||||||
|
// step towards localization. tinyxml (currently) only supports
|
||||||
|
// english error messages, but the could now be translated.
|
||||||
|
//
|
||||||
|
// It also cleans up the code a bit.
|
||||||
|
//
|
||||||
|
|
||||||
|
const char* TiXmlBase::errorString[ TIXML_ERROR_STRING_COUNT ] =
|
||||||
|
{
|
||||||
|
"No error",
|
||||||
|
"Error",
|
||||||
|
"Failed to open file",
|
||||||
|
"Error parsing Element.",
|
||||||
|
"Failed to read Element name",
|
||||||
|
"Error reading Element value.",
|
||||||
|
"Error reading Attributes.",
|
||||||
|
"Error: empty tag.",
|
||||||
|
"Error reading end tag.",
|
||||||
|
"Error parsing Unknown.",
|
||||||
|
"Error parsing Comment.",
|
||||||
|
"Error parsing Declaration.",
|
||||||
|
"Error document empty.",
|
||||||
|
"Error null (0) or unexpected EOF found in input stream.",
|
||||||
|
"Error parsing CDATA.",
|
||||||
|
"Error when TiXmlDocument added to document, because TiXmlDocument can only be at the root.",
|
||||||
|
};
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue