174 Commits
3.0.0 ... 4.0.1

Author SHA1 Message Date
Lee Thomason
74d44acb17 fix compile issues on clang 2016-07-17 22:57:36 -07:00
Lee Thomason
c9445466de fix permissive casting. 2016-07-17 22:53:48 -07:00
Lee Thomason
5bf60e9dc6 try to fix the lld issue 2016-07-17 22:49:40 -07:00
Lee Thomason
6ba2a077ed upping the major version. lots of small (incompatible) changes, and the addition of int64 support. 2016-07-17 22:40:43 -07:00
Lee Thomason
af9bce1762 support user data 2016-07-17 22:35:52 -07:00
Lee Thomason
536a4cde37 Merge branch 'master' into int64support 2016-07-17 21:37:39 -07:00
Lee Thomason
098bd1f17a fix project file version 2016-07-17 21:35:10 -07:00
Lee Thomason
53b0727037 Merge pull request #453 from morinim/issue425
Fixes issue #425
2016-07-17 21:33:54 -07:00
Manlio Morini
0f45b2422f Fixes issue #425 2016-07-11 12:14:59 +02:00
Lee Thomason
d7e5f47524 Merge pull request #445 from kurylo/master
Add INCLUDE_DIRECTORIES on the targets for supported cmake versions.
2016-06-23 13:50:24 -07:00
Lukasz Kurylo
2818e67f31 Add INCLUDE_DIRECTORIES on the targets for supported cmake versions. 2016-06-22 19:22:57 +02:00
Lee Thomason
2fe47ead77 Merge pull request #443 from TheZoc/patch-1
Standardized static library output name
2016-06-09 16:25:14 -07:00
Felipe "Zoc" Silveira
04639a59a5 Standardized static library output name
Renamed ```tinyxml2.a``` to ```libtinyxml2.a```, to allow proper linking using the ```-l``` flag on gcc.
2016-06-08 19:11:37 -03:00
Lee Thomason
1889c3e679 try to make gcc happier 2016-06-04 20:22:57 -07:00
Lee Thomason
51c1271797 add int64 support 2016-06-04 20:18:49 -07:00
Lee Thomason
a572db13cf ps3 support 2016-06-04 19:16:24 -07:00
Lee Thomason
8553625730 one successful return type. simplify build on vs2015 2016-06-04 19:10:53 -07:00
Lee Thomason
df4ffc00d6 fix warning up from vs2015 2016-06-04 11:32:46 -07:00
Lee Thomason
41599e2583 Merge branch 'master' of git://github.com/TheZoc/tinyxml2 into TheZoc-master 2016-06-04 11:26:08 -07:00
Lee Thomason
ceb646812a Merge pull request #438 from TheZoc/osx-makefile
Updated Makefile to allow building TinyXML2 as a static library
2016-06-03 07:56:17 -07:00
Lee Thomason
d3f5c318ae remove unused XMLBase 2016-06-03 07:49:35 -07:00
Felipe "Zoc" Silveira
48daa2dd81 Updated Makefile to allow building TinyXML2 as a static library 2016-05-22 00:21:53 -03:00
Lee Thomason
31d6c877bd Merge pull request #435 from ongjunjie/master
minimize file copying on incremental builds
2016-05-14 10:46:04 -07:00
Felipe "Zoc" Silveira
1f16f9ddf5 Updated to VS 2015 2016-05-12 06:31:28 -03:00
Jun Jie
47f9931130 minimize file copying on incremental builds 2016-04-22 13:37:44 +08:00
Lee Thomason
bb4d246f7b update to VS 2013 2016-03-25 20:08:32 -07:00
Lee Thomason
97837e77f4 Merge pull request #428 from wvvelzen/WarningsFix
Fix 2 "Condition is always true" compiler warnings.
2016-03-25 07:41:51 -07:00
Lee Thomason
3d60e25c4a Merge pull request #427 from wvvelzen/bcb6fix
Fix for Borland C++ Builder 6
2016-03-25 07:41:05 -07:00
Wilfred van Velzen
0aeac18ad3 Fix 2 "Condition is always true" compiler warnings. 2016-03-25 14:14:03 +01:00
Wilfred van Velzen
67abee5610 Fix for Borland C++ Builder 6 2016-03-25 14:01:15 +01:00
Lee Thomason
fe5dbdb817 Merge pull request #414 from ReadmeCritic/master
Correct the capitalization of Xcode in README
2016-03-24 07:49:15 -07:00
Lee Thomason
d175e9de0b Merge pull request #413 from Darksun2010/master
space misses in the comment of CMakeLists.txt
2016-02-17 11:39:22 -08:00
ReadmeCritic
ff714133bc Correct the capitalization of Xcode in README 2016-02-17 09:24:03 -08:00
Darksun
6bf8a07587 space misses in the comment of CMakeLists.txt 2016-02-16 16:10:57 +08:00
Lee Thomason
c8dad95d44 Merge pull request #410 from Dmitry-Me/assertForFTellReturn
Assert to ensure ftell() behaves as expected by later code
2016-02-09 08:39:14 -08:00
Dmitry-Me
96b110d25e Assert to ensure ftell() behaves as expected by later code 2016-02-09 15:12:40 +03:00
Lee Thomason
9ff6654174 Merge pull request #407 from JarleStrand/fix-deletechild
Error fix DeleteChild
2016-01-04 07:40:22 -08:00
Jarle Strand
81abfd6d4c Error fix DeleteChild
Added call to Unlink in XMLNode::DeleteChild() so that references to
node are removed before memory is unallocated. This will ensure the
child is removed from parent and that no pointers are referring to the
unallocated memory. (Code is now aligned with the code in
XMLNode::DeleteChildren() )
2015-12-27 17:30:04 +01:00
Lee Thomason
9c8582c7c3 Merge pull request #401 from Dmitry-Me/assertForNonNullString
Assertion in StrPair::SetStr()
2015-12-09 11:36:59 -08:00
Dmitry-Me
0515fa9d27 Assertion in StrPair::SetStr() 2015-12-09 11:54:06 +03:00
Lee Thomason
f47b20f114 fix readme syntax 2015-10-19 22:55:32 -07:00
Lee Thomason
dffea5747b remove mystery comment 2015-10-19 22:51:49 -07:00
Lee Thomason
fe5b7a5cac Merge pull request #393 from Dmitry-Me/fixSetTextDescription
Fix SetText() description spelling
2015-10-19 17:13:45 -07:00
Dmitry-Me
9e9c85b3ae Fix SetText() description spelling 2015-10-19 18:04:46 +03:00
Lee Thomason
7bc9201322 remove static-assert accidentally checked in. 2015-10-09 14:45:08 -07:00
Lee Thomason
598a88d9fd used stdlib strncmp function 2015-10-09 14:42:12 -07:00
Lee Thomason
e4c0738318 Merge pull request #383 from Chocobo1/travis
CI improvements
2015-10-09 11:28:55 -07:00
Chocobo1
f2c6b118da readme.md: add CI build status badges 2015-10-02 22:09:12 +08:00
Chocobo1
a58de11b42 Add appveyor.yml 2015-10-02 18:08:48 +08:00
Chocobo1
87a8e71c20 TravisCI: support osx build 2015-10-02 17:53:31 +08:00
Lee Thomason
e4f8ba89d0 Merge pull request #381 from ya1gaurav/patch-1
Travis also support clang.
2015-09-29 19:50:14 -07:00
Lee Thomason
a589da416c Merge pull request #380 from Dmitry-Me/getRidOfWtypeLimits
Get rid of -Wtype-limits warning
2015-09-29 19:49:46 -07:00
Gaurav
60af433d31 Travis also support clang.
Add clang compiler to travis build support.
2015-09-28 13:32:30 +05:30
Dmitry-Me
901fed5f19 Get rid of -Wtype-limits warning 2015-09-25 10:29:51 +03:00
Lee Thomason
2aee5e1b37 Merge pull request #379 from renu555/renu555-patch-5
Build with travis CI on every pull request or commit
2015-09-24 10:31:39 -07:00
Lee Thomason
27eb078329 Merge pull request #372 from jasjuang/master
add in support for sudo make uninstall
2015-09-24 10:23:04 -07:00
renu555
d7f2cce11f Create .travis.yml 2015-09-24 14:02:02 +05:30
Lee Thomason
8ac308d433 Merge pull request #376 from renu555/renu555-patch-1
Build tinyxml2 as static library
2015-09-21 07:40:39 -07:00
renu555
871d72f3a8 Build tinyxml2 as static library
By Default shared libs are built
To build static library also configure  cmake with -DBUILD_STATIC_LIBS:BOOL=ON
To build only static library configure cmake with -DBILD_SHARED_LIBS:BOOL=OFF -DBUILD_STATIC_LIBS:BOOL=ON
2015-09-18 13:39:51 +05:30
Lee Thomason
b5d51e8f90 Merge pull request #371 from PKEuS/master
Declared *PRINTF wrappers as static
2015-08-20 07:37:00 -07:00
jasjuang
f6002e6a99 add in support for sudo make uninstall 2015-08-15 16:50:55 -07:00
PKEuS
cac75789ba Declared *PRINTF wrappers as static 2015-08-15 18:19:53 +02:00
Lee Thomason
2beb560a3e Merge pull request #367 from Dmitry-Me/preAssertsToEnsureNoBufferLeaks
Asserts to ensure old buffer is not leaked when allocating a new one
2015-08-14 13:57:53 -07:00
Dmitry-Me
96f38cca95 Asserts to ensure old buffer is not leaked when allocating a new one 2015-08-10 16:45:12 +03:00
Lee Thomason
bb8fd3c29c Merge pull request #364 from PKEuS/master
Moved include of <cstdarg> to cpp file
2015-08-07 15:51:02 -07:00
Lee Thomason
7ae888a601 Merge pull request #363 from Dmitry-Me/outputLengthAsserts
Asserts for formatted output length
2015-08-07 15:50:16 -07:00
Lee Thomason
d101a9b1a6 Merge pull request #366 from yang-le/master
add *.o to .gitignore
2015-08-07 15:46:51 -07:00
Yang Le
14d5490618 add *.o to .gitignore 2015-08-06 22:38:48 +08:00
Philipp Kloke
358202c77a Moved include of <cstdarg> to cpp file 2015-07-30 16:02:26 +02:00
Dmitry-Me
1d32e586d5 Asserts for formatted output length 2015-07-27 17:11:51 +03:00
Lee Thomason
78fca3db83 Merge pull request #361 from RossBencina/master
fix compiler warning (XCode 4.6.1 x86_64) tinyxml2.cpp:2146:77: Impli…
2015-07-23 17:00:05 -07:00
Lee Thomason
fd6ad7e3a7 Merge pull request #362 from Dmitry-Me/useElementName
Use "name" for element name
2015-07-23 16:59:20 -07:00
Dmitry-Me
886ad9787c Use "name" for element name 2015-07-22 11:00:51 +03:00
Ross Bencina
e7fa0e159e fix compiler warning (XCode 4.6.1 x86_64) tinyxml2.cpp:2146:77: Implicit conversion loses integer precision: 'const size_t' (aka 'const unsigned long') to 'const int' 2015-07-22 16:58:05 +10:00
Lee Thomason
eb89ef6f0d Merge pull request #360 from Dmitry-Me/documentConsistencyAsserts
Document consistency asserts
2015-07-21 16:20:12 -07:00
Dmitry-Me
66487eb8f9 Document consistency asserts 2015-07-20 18:21:04 +03:00
Lee Thomason
400e5b2d60 Merge pull request #358 from Dmitry-Me/betterDocumentWarningSuppression
Better document warning suppression code
2015-07-06 14:17:30 -07:00
Dmitry-Me
8dd493b268 Better document warning suppression code 2015-07-02 13:59:30 +03:00
Lee Thomason
4824e95bc0 Merge pull request #343 from Dmitry-Me/checkEntityWasPrinted
Ensure proper pattern was found and printed
2015-07-01 14:18:15 -07:00
Lee Thomason
70fd52a574 Merge pull request #354 from Dmitry-Me/properCapsVisualStudio
Proper capitalize Visual Studio in comment
2015-06-23 16:30:01 -07:00
Dmitry-Me
1ca593c4ca Proper capitalize Visual Studio in comment 2015-06-22 12:49:32 +03:00
Lee Thomason
aebaeea687 Merge pull request #353 from Dmitry-Me/unselessConst
Useless const
2015-06-19 16:55:19 -07:00
Lee Thomason
73f08a3185 Merge pull request #352 from Dmitry-Me/consistencyAsserts
Consistency asserts
2015-06-19 16:54:54 -07:00
Lee Thomason
aa8566b137 fix a macro version check 2015-06-19 16:52:40 -07:00
Dmitry-Me
7865aad09b Useless const 2015-06-19 16:23:35 +03:00
Dmitry-Me
2f5a103992 Consistency asserts 2015-06-18 16:40:09 +03:00
Lee Thomason
53db4a6cf4 move to cpp file. 2015-06-11 22:52:08 -07:00
pffang
1527cf4b2f Patch for Visual Studio 2003 and earlier.
This patch will be easy to extend in the future.
2015-06-09 13:57:11 +08:00
Lee Thomason
2b2649e1e4 Merge pull request #349 from Dmitry-Me/properHandleSmallBufferOnCe
Don't use -1 as buffer length
2015-06-08 17:14:14 -07:00
Dmitry-Me
687bf8211f Don't use -1 as buffer length 2015-06-08 18:06:44 +03:00
Dmitry-Me
39c399a0f2 Ensure proper pattern was found and printed 2015-05-28 15:32:27 +03:00
Lee Thomason
91f2dcfb5c Merge pull request #342 from Dmitry-Me/testErrorNames
Test error name is non-empty for the whole range
2015-05-26 11:09:12 -07:00
Lee Thomason
32de9f02f5 Merge pull request #341 from Dmitry-Me/cleanupComment
Remove redundant comment, fix typo and formatting
2015-05-26 09:18:55 -07:00
Dmitry-Me
a1beddf486 Test error name is non-empty for the whole range 2015-05-26 16:19:21 +03:00
Dmitry-Me
962083b9d1 Remove redundant comment, fix typo and formatting 2015-05-26 11:38:30 +03:00
Lee Thomason
735ce51124 Merge pull request #339 from Dmitry-Me/properFixGccSignCompare
Proper fix gcc -Wsign-compare
2015-05-25 10:40:45 -07:00
Dmitry-Me
ca86a0fa2a Proper fix gcc -Wsign-compare 2015-05-25 11:29:14 +03:00
Lee Thomason
c879a4d48c Merge pull request #338 from Dmitry-Me/removeAmbiguousEnumItems
Get rid of two distinct enum items with same same
2015-05-22 11:09:33 -07:00
Lee Thomason
949ae37e0a Merge pull request #337 from Dmitry-Me/checkEntityFoundExplicitly
Explicitly check entity was not found
2015-05-22 11:08:31 -07:00
Lee Thomason
03d0f4ea25 Merge branch 'SirR4T-assert-fires-when-calling-XMLDocument--Value' 2015-05-22 11:07:58 -07:00
Lee Thomason
8549202800 clean up Value of XMLDocument 2015-05-22 11:07:45 -07:00
Lee Thomason
c52aa55a86 Merge branch 'SirR4T-patch-1' 2015-05-22 11:00:59 -07:00
Lee Thomason
7a93b33160 tighten up the error checks 2015-05-22 11:00:32 -07:00
Lee Thomason
2ecc203835 Merge branch 'patch-1' of https://github.com/SirR4T/tinyxml2 into SirR4T-patch-1 2015-05-22 10:57:00 -07:00
Dmitry-Me
5420e547d3 Get rid of two distinct enum items with same same 2015-05-20 10:51:26 +03:00
Dmitry-Me
764545e02a Explicitly check entity was not found 2015-05-20 10:29:24 +03:00
Sarat Addepalli
3df007ef9d Fix and use correct pointers and types.
Should have been `XMLDeclaration* decl = ...` instead of `XMLElement* ele = ...`
2015-05-20 10:43:51 +05:30
Sarat Addepalli
96b4346660 Remove unnecessary cast in XMLNode::Value() 2015-05-20 10:36:06 +05:30
Sarat Addepalli
d608c561e0 Fix up xmltest.cpp
Fixed coding style in XMLTest(), and removed unused variable in testcase.
2015-05-20 10:19:00 +05:30
Lee Thomason
ff53d7172c Merge pull request #335 from SirR4T/SirR4T-add-DEBUG-macro-in-CMakeLists_txt
Define the `DEBUG` macro in CMakeLists.txt
2015-05-19 09:37:33 -07:00
Lee Thomason
1bf04fd755 Merge pull request #330 from Dmitry-Me/avoidUnneededPrinterCreation
Avoid unneeded printer object creation
2015-05-19 09:31:41 -07:00
Sarat Addepalli
9afd1d0ceb Clarify meaning of 'empty'
When `XMLDocument::Value()` is called, we intend to return NULL (`( const char* )0`). State that explicitly in the documentation, so as to disambiguate between "empty string" (`""`) and NULL.
2015-05-19 12:56:27 +05:30
Sarat Addepalli
9c3122b89b Bypass asserts for XMLDocument::Value()
When the node is an XMLDocument, bypass calling the `_value.GetStr()` function, since we know we have to return `( const char* )0` inevitably.

This fixes #323
2015-05-19 12:49:32 +05:30
Sarat Addepalli
13b2d73427 Add null-checks in XMLTest()
When either `expected` or `found` is `NULL`, `XMLTest()` will segfault on `strcmp()`.
This patch adds null-checks, and passes the test if both `expected` and `found` are `NULL`.
2015-05-19 12:44:57 +05:30
Sarat Addepalli
a7edb883f0 Add a test case for issue #323
When compiled in "debug mode", this test case verifies that an assert is fired, when `XMLDocument::Value()` is called.
2015-05-19 12:39:27 +05:30
Sarat Addepalli
39a77dd825 Define the DEBUG macro in CMakeLists.txt
Fixes #334
2015-05-19 12:27:59 +05:30
Sarat Addepalli
8e85afa406 Fix whitespaces in xmltest.cpp 2015-05-19 09:07:03 +05:30
Sarat Addepalli
2f0d173f94 Fix whitespaces in tinyxml2.cpp 2015-05-19 09:02:16 +05:30
Sarat Addepalli
a0f499dda1 Fix ParseDeep() to close issue #332
If the node to be added is an XML Declaration, then check if the document has any children already.
XML Declarations can only be the FirstChild() s of an XML Document.
2015-05-18 09:25:17 +05:30
Sarat Addepalli
2bb6bb5bee Add a test case for issue #332
XML Declarations can occur only at the beginning of an XML Document.
Parse() should throw an error, for not well-formed XML Documents.
2015-05-18 09:16:34 +05:30
Dmitry-Me
67c429e4b4 Avoid unneeded printer object creation 2015-05-08 18:08:18 +03:00
Lee Thomason
e5e5541af6 Merge pull request #328 from Dmitry-Me/firstCheckThenConvert
First check, then convert
2015-05-07 13:54:31 -07:00
Dmitry-Me
72801b8b20 First check, then convert 2015-05-07 09:41:39 +03:00
Lee Thomason
89df56c046 Merge pull request #327 from Dmitry-Me/ensureFileSizeFitsInSizeT
Ensure file contents fit into size_t range
2015-05-06 16:40:01 -07:00
Dmitry-Me
2a8b1f5789 Ensure file contents fit into size_t range 2015-04-30 14:58:57 +03:00
Lee Thomason
882e89e601 Merge pull request #326 from Dmitry-Me/cleanupPointersComparison
Unify pointers comparison, consistency asserts
2015-04-27 16:57:37 -07:00
Lee Thomason
a295da4302 Merge pull request #324 from Dmitry-Me/checkWithoutClangTautological
Range check without clang "always true" warning
2015-04-27 16:56:24 -07:00
Dmitry-Me
69d521d354 Unify pointers comparison, consistency asserts 2015-04-20 18:05:53 +03:00
Dmitry-Me
2ad4320339 Range check without clang "always true" warning 2015-04-16 12:18:58 +03:00
Lee Thomason
4f0c2ffcab fix 'always true' warning 2015-04-13 13:58:20 -07:00
Lee Thomason
70f2c740c0 Merge pull request #322 from Dmitry-Me/detectParsingErrorEarlier
Detect parsing error earlier when looking at end of tag
2015-04-13 13:43:07 -07:00
Dmitry-Me
ccd267a782 Detect parsing error earlier when looking at end of tag 2015-04-10 15:42:54 +03:00
Lee Thomason
9f24acd369 Merge pull request #321 from Dmitry-Me/dontLeakTheElement
Don't leak the element
2015-04-09 14:49:59 -07:00
Lee Thomason
e3932d6b7f Merge pull request #319 from Dmitry-Me/getRidOfNull
Get rid of NULL, cleanup formatting
2015-04-09 14:49:25 -07:00
Lee Thomason
5ea4f3cb77 Merge pull request #315 from Dmitry-Me/orderPatternsAsTheyAreSearched
Order patterns the same way they are searched
2015-04-09 14:48:44 -07:00
Lee Thomason
2d39158eaa Merge pull request #317 from Dmitry-Me/moreConsistencyAsserts
More consistency asserts
2015-04-09 14:48:18 -07:00
Dmitry-Me
5daa54cf2b Don't leak the element 2015-04-08 17:45:07 +03:00
Dmitry-Me
e76b8519d1 Get rid of NULL, cleanup formatting 2015-04-08 13:41:40 +03:00
Dmitry-Me
9614f8ff74 More consistency asserts 2015-04-08 10:06:06 +03:00
Lee Thomason
4a0392dd9d Merge pull request #314 from Dmitry-Me/ensureEnumIsPrintedProperly
Ensure enum is printed properly
2015-04-07 09:55:18 -07:00
Lee Thomason
0aa957a352 Merge pull request #313 from Dmitry-Me/shouldBeNoErrorInitially
Test there's no error initially, proper swap "found" and "expected"
2015-04-07 09:53:24 -07:00
Dmitry-Me
400f1199ea Ensure enum is printed properly 2015-04-07 11:51:21 +03:00
Dmitry-Me
32533ca9c2 Test there's no error initially, proper swap "found" and "expected" 2015-04-07 10:37:39 +03:00
Lee Thomason
a1a4a13825 Merge pull request #312 from Dmitry-Me/newDocumentMustBeEmpty
Document must be initially empty
2015-04-06 14:26:23 -07:00
Lee Thomason
4034395d1a Merge pull request #311 from Dmitry-Me/betterParameterName
Better parameter name
2015-04-06 14:25:57 -07:00
Lee Thomason
2a2ed16ce1 Merge pull request #310 from Dmitry-Me/moreConst
Const qualifiers where access is const, unify formatting
2015-04-06 14:25:37 -07:00
Lee Thomason
1881344cb6 Merge pull request #309 from Dmitry-Me/makeParseDeepProtected
Make ParseDeep() protected
2015-04-06 14:25:00 -07:00
Dmitry-Me
48b5df0b9b Document must be initially empty 2015-04-06 18:20:25 +03:00
Dmitry-Me
040092215d Better parameter name 2015-04-06 18:07:18 +03:00
Dmitry-Me
2667aab551 Const qualifiers where access is const, unify formatting 2015-04-03 10:56:59 +03:00
Dmitry-Me
9b0f17753d Make ParseDeep() protected 2015-04-03 10:37:31 +03:00
Lee Thomason
51b33321be Merge pull request #308 from Dmitry-Me/mergePrintCalls
Merge Print() calls
2015-04-02 13:27:50 -07:00
Lee Thomason
8c067ab730 Merge pull request #307 from Dmitry-Me/simplifyOverengineeredCode
Simplify overengineered code
2015-04-02 13:27:17 -07:00
Lee Thomason
fb33e99a77 Merge pull request #306 from Dmitry-Me/printSubstringEntirely
Print entire substring instead of each character
2015-04-02 13:26:50 -07:00
Dmitry-Me
6a79c17c87 Merge Print() calls 2015-03-31 12:18:17 +03:00
Dmitry-Me
8d4e0ec528 Simplify overengineered code 2015-03-30 12:58:28 +03:00
Dmitry-Me
c505e136da Order patterns the same way they are searched 2015-03-30 09:54:36 +03:00
Dmitry-Me
d95172ba47 Print entire substring instead of each character 2015-03-30 08:11:18 +03:00
Lee Thomason
28c7c8c14f Merge pull request #305 from Dmitry-Me/errorShouldBeClearedAfterLoad
If LoadFile() fails then subsequent successful LoadFile() must clear the error
2015-03-26 11:19:28 -07:00
Lee Thomason
55c7879352 Merge branch 'Haloric-Issue-302' 2015-03-26 11:18:42 -07:00
Lee Thomason
f657783cf2 merge fix for save file error 2015-03-26 11:18:21 -07:00
Dmitry-Me
d9852a53af If LoadFile() fails then subsequent successful LoadFile() must clear the error 2015-03-25 10:17:49 +03:00
Lee Thomason
ea21390f28 Merge branch 'Haloric-Issue299' 2015-03-24 11:18:12 -07:00
Lee Thomason
3ccb1cec29 minor formatting cleanup 2015-03-24 11:17:44 -07:00
Ant Mitchell
189198f19c Issue 302: clear any previous save error 2015-03-24 16:20:36 +00:00
Ant Mitchell
148cc1a0a5 Issue 299 - test for code changes 2015-03-24 15:12:35 +00:00
Ant Mitchell
7e744771ad Issue299 - Allow Accept() to work with element trees that are not
linked in to the owning document.
2015-03-24 14:33:28 +00:00
Lee Thomason
32cca51ac5 Merge pull request #300 from davidsanfal/master
Add biicode support to TinyXML-2
2015-03-20 21:29:37 -07:00
Lee Thomason
01969dcde2 Merge remote-tracking branch 'origin/master' 2015-03-17 21:31:57 -07:00
Lee Thomason
2b1e18185c Merge pull request #298 from Dmitry-Me/fixCommentTypo
Fix comment typo
2015-03-16 11:57:38 -07:00
Lee Thomason
5ea1cf33f3 Merge pull request #297 from Dmitry-Me/betterAssertsInParsing
Better asserts in parsing
2015-03-16 11:57:13 -07:00
David
4633c3aa27 add biicode support 2015-03-16 10:41:00 +01:00
Dmitry-Me
2f465c412a Fix comment typo 2015-03-16 11:08:23 +03:00
Dmitry-Me
3dc797b2a4 Better asserts in parsing 2015-03-16 11:06:46 +03:00
15 changed files with 822 additions and 280 deletions

3
.gitignore vendored
View File

@@ -10,4 +10,5 @@ tinyxml2/tinyxml2-cbp/obj/
*.opensdf
*.user
*.depend
*.layout
*.layout
*.o

15
.travis.yml Normal file
View File

@@ -0,0 +1,15 @@
language: cpp
os:
- linux
- osx
compiler:
- g++
- clang
before_script: cmake .
script:
- make -j3
- ./xmltest

View File

@@ -1,3 +1,10 @@
IF(BIICODE)
ADD_BIICODE_TARGETS()
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/resources)
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/resources DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
ENDIF()
RETURN()
ENDIF(BIICODE)
cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
cmake_policy(VERSION 2.6)
@@ -10,12 +17,12 @@ include(GNUInstallDirs)
################################
# set lib version here
set(GENERIC_LIB_VERSION "3.0.0")
set(GENERIC_LIB_SOVERSION "3")
set(GENERIC_LIB_VERSION "4.0.1")
set(GENERIC_LIB_SOVERSION "4")
################################
# Add common source
# Add common source
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/.")
@@ -23,19 +30,20 @@ include_directories("${CMAKE_CURRENT_SOURCE_DIR}/.")
# Add custom target to copy all data
set(TARGET_DATA_COPY DATA_COPY)
if(${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR})
add_custom_target(
${TARGET_DATA_COPY}
COMMAND ${CMAKE_COMMAND} -E echo "In source build")
else(${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR})
make_directory(${CMAKE_CURRENT_BINARY_DIR}/resources/)
add_custom_target(
${TARGET_DATA_COPY}
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/resources/dream.xml ${CMAKE_CURRENT_BINARY_DIR}/resources/
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/resources/empty.xml ${CMAKE_CURRENT_BINARY_DIR}/resources/
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/resources/utf8test.xml ${CMAKE_CURRENT_BINARY_DIR}/resources/
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/resources/utf8testverify.xml ${CMAKE_CURRENT_BINARY_DIR}/resources/)
endif(${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR})
set(DATA_COPY_FILES)
if(NOT ${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR})
foreach(data dream.xml empty.xml utf8test.xml utf8testverify.xml)
set(DATA_COPY_SRC ${CMAKE_CURRENT_SOURCE_DIR}/resources/${data})
set(DATA_COPY_DEST ${CMAKE_CURRENT_BINARY_DIR}/resources/${data})
add_custom_command(
OUTPUT ${DATA_COPY_DEST}
COMMAND ${CMAKE_COMMAND}
ARGS -E copy ${DATA_COPY_SRC} ${DATA_COPY_DEST}
DEPENDS ${DATA_COPY_SRC})
list(APPEND DATA_COPY_FILES ${DATA_COPY_DEST})
endforeach(data)
endif(NOT ${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR})
add_custom_target(${TARGET_DATA_COPY} DEPENDS ${DATA_COPY_FILES})
################################
# Add definitions
@@ -44,25 +52,65 @@ if(MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
endif(MSVC)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG")
################################
# Add targets
option(BUILD_SHARED_LIBS "build shared or static libraries" ON)
add_library(tinyxml2 tinyxml2.cpp tinyxml2.h)
# By Default shared libray is being built
# To build static libs also - Do cmake . -DBUILD_STATIC_LIBS:BOOL=ON
# User can choose not to build shared library by using cmake -BUILD_SHARED_LIBS:BOOL:OFF
# To build only static libs use cmake . -DBUILD_SHARED_LIBS:BOOL=OFF -DBUILD_STATIC_LIBS:BOOL=ON
option(BUILD_SHARED_LIBS "build as shared library" ON)
option(BUILD_STATIC_LIBS "build as static library" OFF)
if(BUILD_SHARED_LIBS)
add_library(tinyxml2 SHARED tinyxml2.cpp tinyxml2.h)
set_target_properties(tinyxml2 PROPERTIES
COMPILE_DEFINITIONS "TINYXML2_EXPORT"
VERSION "${GENERIC_LIB_VERSION}"
SOVERSION "${GENERIC_LIB_SOVERSION}")
add_executable(xmltest xmltest.cpp)
add_dependencies(xmltest tinyxml2)
add_dependencies(xmltest ${TARGET_DATA_COPY})
target_link_libraries(xmltest tinyxml2)
if(DEFINED CMAKE_VERSION AND NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11")
target_include_directories(tinyxml2 INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/.")
endif()
install(TARGETS tinyxml2
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
if(BUILD_STATIC_LIBS)
add_library(tinyxml2_static STATIC tinyxml2.cpp tinyxml2.h)
set_target_properties(tinyxml2_static PROPERTIES
COMPILE_DEFINITONS "TINYXML2_EXPORT"
VERSION "${GENERIC_LIB_VERSION}"
SOVERSION "${GENERIC_LIB_SOVERSION}")
set_target_properties( tinyxml2_static PROPERTIES OUTPUT_NAME tinyxml2 )
if(DEFINED CMAKE_VERSION AND NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11")
target_include_directories(tinyxml2_static INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/.")
endif()
install(TARGETS tinyxml2_static
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
add_executable(xmltest xmltest.cpp)
if(BUILD_SHARED_LIBS)
add_dependencies(xmltest tinyxml2)
add_dependencies(xmltest ${TARGET_DATA_COPY})
target_link_libraries(xmltest tinyxml2)
else(BUILD_STATIC_LIBS)
add_dependencies(xmltest tinyxml2_static)
add_dependencies(xmltest ${TARGET_DATA_COPY})
target_link_libraries(xmltest tinyxml2_static)
endif()
install(TARGETS DESTINATION ${CMAKE_INSTALL_BINDIR})
install(FILES tinyxml2.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
@@ -77,3 +125,12 @@ configure_file(tinyxml2.pc.in tinyxml2.pc @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/tinyxml2.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
#add_test(xmltest ${SAMPLE_NAME} COMMAND $<TARGET_FILE:${SAMPLE_NAME}>)
# uninstall target
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)

View File

@@ -1,6 +1,19 @@
all: xmltest
xmltest: xmltest.cpp tinyxml2.cpp tinyxml2.h
all: xmltest staticlib
rebuild: clean all
xmltest: xmltest.cpp libtinyxml2.a
clean:
$(RM) *.o xmltest libtinyxml2.a
test: clean xmltest
./xmltest
clean:
rm -f *.o xmltest
staticlib: libtinyxml2.a
libtinyxml2.a: tinyxml2.o
$(AR) $(ARFLAGS)s $@ $^
tinyxml2.o: tinyxml2.cpp tinyxml2.h

7
appveyor.yml Normal file
View File

@@ -0,0 +1,7 @@
before_build:
- cmake .
build_script:
- msbuild tinyxml2.sln /m /p:Configuration=Release /t:ALL_BUILD
- copy Release\xmltest.exe .\ && copy Release\tinyxml2.dll .\
- xmltest.exe

7
biicode.conf Normal file
View File

@@ -0,0 +1,7 @@
# Biicode configuration file
[paths]
/
[dependencies]
xmltest.cpp + resources/*.xml

21
cmake_uninstall.cmake.in Normal file
View File

@@ -0,0 +1,21 @@
if(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
message(FATAL_ERROR "Cannot find install manifest: @CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
endif(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files)
string(REGEX REPLACE "\n" ";" files "${files}")
foreach(file ${files})
message(STATUS "Uninstalling $ENV{DESTDIR}${file}")
if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
exec_program(
"@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\""
OUTPUT_VARIABLE rm_out
RETURN_VALUE rm_retval
)
if(NOT "${rm_retval}" STREQUAL 0)
message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}")
endif(NOT "${rm_retval}" STREQUAL 0)
else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
message(STATUS "File $ENV{DESTDIR}${file} does not exist.")
endif(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
endforeach(file)

View File

@@ -65,7 +65,7 @@ public:
protected:
virtual void CloseElement () {
if (_elementJustOpened && !isVoidElement (_stack.PeekTop())) {
SealElement();
SealElementIfJustOpened();
}
XMLPrinter::CloseElement();
}

2
dox
View File

@@ -38,7 +38,7 @@ PROJECT_NAME = "TinyXML-2"
# could be handy for archiving the generated documentation or if some version
# control system is used.
PROJECT_NUMBER = 3.0.0
PROJECT_NUMBER = 4.0.1
# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a

View File

@@ -1,4 +1,4 @@
TinyXML-2
TinyXML-2 [![TravisCI Status](https://travis-ci.org/leethomason/tinyxml2.svg?branch=master)](https://travis-ci.org/leethomason/tinyxml2) [![AppVeyor Status](https://ci.appveyor.com/api/projects/status/github/leethomason/tinyxml2?branch=master&svg=true)](https://ci.appveyor.com/project/leethomason/tinyxml2)
=========
![TinyXML-2 Logo](http://www.grinninglizard.com/tinyxml2/TinyXML2_small.png)
@@ -177,7 +177,7 @@ will have the Value() of "Far & Away" when queried from the XMLText object,
and will be written back to the XML stream/file as an ampersand.
Additionally, any character can be specified by its Unicode code point:
The syntax "&#xA0;" or "&#160;" are both to the non-breaking space characher.
The syntax `&#xA0;` or `&#160;` are both to the non-breaking space character.
This is called a 'numeric character reference'. Any numeric character reference
that isn't one of the special entities above, will be read, but written as a
regular code point. The output is correct, but the entity syntax isn't preserved.
@@ -264,8 +264,8 @@ There are 2 files in TinyXML-2:
And additionally a test file:
* xmltest.cpp
Simply compile and run. There is a visual studio 2010 project included, a simple Makefile,
an XCode project, a Code::Blocks project, and a cmake CMakeLists.txt included to help you.
Simply compile and run. There is a visual studio 2015 project included, a simple Makefile,
an Xcode project, a Code::Blocks project, and a cmake CMakeLists.txt included to help you.
The top of tinyxml.h even has a simple g++ command line if you are are *nix and don't want
to use a build system.

View File

@@ -24,12 +24,83 @@ distribution.
#include "tinyxml2.h"
#include <new> // yes, this one new style header, is in the Android SDK.
#if defined(ANDROID_NDK) || defined(__QNXNTO__)
#if defined(ANDROID_NDK) || defined(__BORLANDC__) || defined(__QNXNTO__)
# include <stddef.h>
# include <stdarg.h>
#else
# include <cstddef>
# include <cstdarg>
#endif
#if defined(_MSC_VER) && (_MSC_VER >= 1400 ) && (!defined WINCE)
// Microsoft Visual Studio, version 2005 and higher. Not WinCE.
/*int _snprintf_s(
char *buffer,
size_t sizeOfBuffer,
size_t count,
const char *format [,
argument] ...
);*/
static inline int TIXML_SNPRINTF( char* buffer, size_t size, const char* format, ... )
{
va_list va;
va_start( va, format );
int result = vsnprintf_s( buffer, size, _TRUNCATE, format, va );
va_end( va );
return result;
}
static inline int TIXML_VSNPRINTF( char* buffer, size_t size, const char* format, va_list va )
{
int result = vsnprintf_s( buffer, size, _TRUNCATE, format, va );
return result;
}
#define TIXML_VSCPRINTF _vscprintf
#define TIXML_SSCANF sscanf_s
#elif defined _MSC_VER
// Microsoft Visual Studio 2003 and earlier or WinCE
#define TIXML_SNPRINTF _snprintf
#define TIXML_VSNPRINTF _vsnprintf
#define TIXML_SSCANF sscanf
#if (_MSC_VER < 1400 ) && (!defined WINCE)
// Microsoft Visual Studio 2003 and not WinCE.
#define TIXML_VSCPRINTF _vscprintf // VS2003's C runtime has this, but VC6 C runtime or WinCE SDK doesn't have.
#else
// Microsoft Visual Studio 2003 and earlier or WinCE.
static inline int TIXML_VSCPRINTF( const char* format, va_list va )
{
int len = 512;
for (;;) {
len = len*2;
char* str = new char[len]();
const int required = _vsnprintf(str, len, format, va);
delete[] str;
if ( required != -1 ) {
TIXMLASSERT( required >= 0 );
len = required;
break;
}
}
TIXMLASSERT( len >= 0 );
return len;
}
#endif
#else
// GCC version 3 and higher
//#warning( "Using sn* functions." )
#define TIXML_SNPRINTF snprintf
#define TIXML_VSNPRINTF vsnprintf
static inline int TIXML_VSCPRINTF( const char* format, va_list va )
{
int len = vsnprintf( 0, 0, format, va );
TIXMLASSERT( len >= 0 );
return len;
}
#define TIXML_SSCANF sscanf
#endif
static const char LINE_FEED = (char)0x0a; // all line endings are normalized to LF
static const char LF = LINE_FEED;
static const char CARRIAGE_RETURN = (char)0x0d; // CR gets filtered out
@@ -106,8 +177,10 @@ void StrPair::Reset()
void StrPair::SetStr( const char* str, int flags )
{
TIXMLASSERT( str );
Reset();
size_t len = strlen( str );
TIXMLASSERT( _start == 0 );
_start = new char[ len+1 ];
memcpy( _start, str, len+1 );
_end = _start + len;
@@ -243,8 +316,8 @@ const char* StrPair::GetStr()
}
}
else {
int i=0;
for(; i<NUM_ENTITIES; ++i ) {
bool entityFound = false;
for( int i = 0; i < NUM_ENTITIES; ++i ) {
const Entity& entity = entities[i];
if ( strncmp( p + 1, entity.pattern, entity.length ) == 0
&& *( p + entity.length + 1 ) == ';' ) {
@@ -252,10 +325,11 @@ const char* StrPair::GetStr()
*q = entity.value;
++q;
p += entity.length + 2;
entityFound = true;
break;
}
}
if ( i == NUM_ENTITIES ) {
if ( !entityFound ) {
// fixme: treat as error?
++p;
++q;
@@ -272,7 +346,7 @@ const char* StrPair::GetStr()
}
// The loop below has plenty going on, and this
// is a less useful mode. Break it out.
if ( _flags & COLLAPSE_WHITESPACE ) {
if ( _flags & NEEDS_WHITESPACE_COLLAPSING ) {
CollapseWhitespace();
}
_flags = (_flags & NEEDS_DELETE);
@@ -323,7 +397,7 @@ void XMLUtil::ConvertUTF32ToUTF8( unsigned long input, char* output, int* length
*length = 4;
}
else {
*length = 0; // This code won't covert this correctly anyway.
*length = 0; // This code won't convert this correctly anyway.
return;
}
@@ -397,8 +471,8 @@ const char* XMLUtil::GetCharacterRef( const char* p, char* value, int* length )
else {
return 0;
}
TIXMLASSERT( digit < 16 );
TIXMLASSERT( digit == 0 || mult <= UINT_MAX / digit );
TIXMLASSERT( digit >= 0 && digit < 16);
const unsigned int digitScaled = mult * digit;
TIXMLASSERT( ucs <= ULONG_MAX - digitScaled );
ucs += digitScaled;
@@ -427,6 +501,7 @@ const char* XMLUtil::GetCharacterRef( const char* p, char* value, int* length )
while ( *q != '#' ) {
if ( *q >= '0' && *q <= '9' ) {
const unsigned int digit = *q - '0';
TIXMLASSERT( digit < 10 );
TIXMLASSERT( digit == 0 || mult <= UINT_MAX / digit );
const unsigned int digitScaled = mult * digit;
TIXMLASSERT( ucs <= ULONG_MAX - digitScaled );
@@ -481,6 +556,13 @@ void XMLUtil::ToStr( double v, char* buffer, int bufferSize )
}
void XMLUtil::ToStr(int64_t v, char* buffer, int bufferSize)
{
// horrible syntax trick to make the compiler happy about %lld
TIXML_SNPRINTF(buffer, bufferSize, "%lld", (long long)v);
}
bool XMLUtil::ToInt( const char* str, int* value )
{
if ( TIXML_SSCANF( str, "%d", value ) == 1 ) {
@@ -524,6 +606,7 @@ bool XMLUtil::ToFloat( const char* str, float* value )
return false;
}
bool XMLUtil::ToDouble( const char* str, double* value )
{
if ( TIXML_SSCANF( str, "%lf", value ) == 1 ) {
@@ -533,6 +616,17 @@ bool XMLUtil::ToDouble( const char* str, double* value )
}
bool XMLUtil::ToInt64(const char* str, int64_t* value)
{
long long v = 0; // horrible syntax trick to make the compiler happy about %lld
if (TIXML_SSCANF(str, "%lld", &v) == 1) {
*value = (int64_t)v;
return true;
}
return false;
}
char* XMLDocument::Identify( char* p, XMLNode** node )
{
TIXMLASSERT( node );
@@ -545,18 +639,17 @@ char* XMLDocument::Identify( char* p, XMLNode** node )
return p;
}
// What is this thing?
// These strings define the matching patters:
// These strings define the matching patterns:
static const char* xmlHeader = { "<?" };
static const char* commentHeader = { "<!--" };
static const char* dtdHeader = { "<!" };
static const char* cdataHeader = { "<![CDATA[" };
static const char* dtdHeader = { "<!" };
static const char* elementHeader = { "<" }; // and a header for everything else; check last.
static const int xmlHeaderLen = 2;
static const int commentHeaderLen = 4;
static const int dtdHeaderLen = 2;
static const int cdataHeaderLen = 9;
static const int dtdHeaderLen = 2;
static const int elementHeaderLen = 1;
TIXMLASSERT( sizeof( XMLComment ) == sizeof( XMLUnknown ) ); // use same memory pool
@@ -629,6 +722,7 @@ XMLNode::XMLNode( XMLDocument* doc ) :
_parent( 0 ),
_firstChild( 0 ), _lastChild( 0 ),
_prev( 0 ), _next( 0 ),
_userData( 0 ),
_memPool( 0 )
{
}
@@ -644,6 +738,9 @@ XMLNode::~XMLNode()
const char* XMLNode::Value() const
{
// Catch an edge case: XMLDocuments don't have a a Value. Carefully return nullptr.
if ( this->ToDocument() )
return 0;
return _value.GetStr();
}
@@ -661,6 +758,7 @@ void XMLNode::SetValue( const char* str, bool staticMem )
void XMLNode::DeleteChildren()
{
while( _firstChild ) {
TIXMLASSERT( _lastChild );
TIXMLASSERT( _firstChild->_document == _document );
XMLNode* node = _firstChild;
Unlink( node );
@@ -675,6 +773,7 @@ void XMLNode::Unlink( XMLNode* child )
{
TIXMLASSERT( child );
TIXMLASSERT( child->_document == _document );
TIXMLASSERT( child->_parent == this );
if ( child == _firstChild ) {
_firstChild = _firstChild->_next;
}
@@ -697,6 +796,7 @@ void XMLNode::DeleteChild( XMLNode* node )
TIXMLASSERT( node );
TIXMLASSERT( node->_document == _document );
TIXMLASSERT( node->_parent == this );
Unlink( node );
DeleteNode( node );
}
@@ -793,12 +893,12 @@ XMLNode* XMLNode::InsertAfterChild( XMLNode* afterThis, XMLNode* addThis )
const XMLElement* XMLNode::FirstChildElement( const char* value ) const
const XMLElement* XMLNode::FirstChildElement( const char* name ) const
{
for( XMLNode* node=_firstChild; node; node=node->_next ) {
XMLElement* element = node->ToElement();
for( const XMLNode* node = _firstChild; node; node = node->_next ) {
const XMLElement* element = node->ToElement();
if ( element ) {
if ( !value || XMLUtil::StringEqual( element->Name(), value ) ) {
if ( !name || XMLUtil::StringEqual( element->Name(), name ) ) {
return element;
}
}
@@ -807,12 +907,12 @@ const XMLElement* XMLNode::FirstChildElement( const char* value ) const
}
const XMLElement* XMLNode::LastChildElement( const char* value ) const
const XMLElement* XMLNode::LastChildElement( const char* name ) const
{
for( XMLNode* node=_lastChild; node; node=node->_prev ) {
XMLElement* element = node->ToElement();
for( const XMLNode* node = _lastChild; node; node = node->_prev ) {
const XMLElement* element = node->ToElement();
if ( element ) {
if ( !value || XMLUtil::StringEqual( element->Name(), value ) ) {
if ( !name || XMLUtil::StringEqual( element->Name(), name ) ) {
return element;
}
}
@@ -821,12 +921,12 @@ const XMLElement* XMLNode::LastChildElement( const char* value ) const
}
const XMLElement* XMLNode::NextSiblingElement( const char* value ) const
const XMLElement* XMLNode::NextSiblingElement( const char* name ) const
{
for( XMLNode* node=this->_next; node; node = node->_next ) {
for( const XMLNode* node = _next; node; node = node->_next ) {
const XMLElement* element = node->ToElement();
if ( element
&& (!value || XMLUtil::StringEqual( value, node->Value() ))) {
&& (!name || XMLUtil::StringEqual( name, element->Name() ))) {
return element;
}
}
@@ -834,12 +934,12 @@ const XMLElement* XMLNode::NextSiblingElement( const char* value ) const
}
const XMLElement* XMLNode::PreviousSiblingElement( const char* value ) const
const XMLElement* XMLNode::PreviousSiblingElement( const char* name ) const
{
for( XMLNode* node=_prev; node; node = node->_prev ) {
for( const XMLNode* node = _prev; node; node = node->_prev ) {
const XMLElement* element = node->ToElement();
if ( element
&& (!value || XMLUtil::StringEqual( value, node->Value() ))) {
&& (!name || XMLUtil::StringEqual( name, element->Name() ))) {
return element;
}
}
@@ -884,6 +984,17 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEnd )
break;
}
XMLDeclaration* decl = node->ToDeclaration();
if ( decl ) {
// A declaration can only be the first child of a document.
// Set error, if document already has children.
if ( !_document->NoChildren() ) {
_document->SetError( XML_ERROR_PARSING_DECLARATION, decl->Value(), 0);
DeleteNode( decl );
break;
}
}
XMLElement* ele = node->ToElement();
if ( ele ) {
// We read the end tag. Return it to the parent.
@@ -908,12 +1019,12 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEnd )
if ( ele->ClosingType() != XMLElement::OPEN ) {
mismatch = true;
}
else if ( !XMLUtil::StringEqual( endTag.GetStr(), node->Value() ) ) {
else if ( !XMLUtil::StringEqual( endTag.GetStr(), ele->Name() ) ) {
mismatch = true;
}
}
if ( mismatch ) {
_document->SetError( XML_ERROR_MISMATCHED_ELEMENT, node->Value(), 0 );
_document->SetError( XML_ERROR_MISMATCHED_ELEMENT, ele->Name(), 0 );
DeleteNode( node );
break;
}
@@ -958,7 +1069,7 @@ char* XMLText::ParseDeep( char* p, StrPair* )
else {
int flags = _document->ProcessEntities() ? StrPair::TEXT_ELEMENT : StrPair::TEXT_ELEMENT_LEAVE_ENTITIES;
if ( _document->WhitespaceMode() == COLLAPSE_WHITESPACE ) {
flags |= StrPair::COLLAPSE_WHITESPACE;
flags |= StrPair::NEEDS_WHITESPACE_COLLAPSING;
}
p = _value.ParseText( p, "<", flags );
@@ -1195,7 +1306,7 @@ void XMLAttribute::SetName( const char* n )
XMLError XMLAttribute::QueryIntValue( int* value ) const
{
if ( XMLUtil::ToInt( Value(), value )) {
return XML_NO_ERROR;
return XML_SUCCESS;
}
return XML_WRONG_ATTRIBUTE_TYPE;
}
@@ -1204,16 +1315,25 @@ XMLError XMLAttribute::QueryIntValue( int* value ) const
XMLError XMLAttribute::QueryUnsignedValue( unsigned int* value ) const
{
if ( XMLUtil::ToUnsigned( Value(), value )) {
return XML_NO_ERROR;
return XML_SUCCESS;
}
return XML_WRONG_ATTRIBUTE_TYPE;
}
XMLError XMLAttribute::QueryInt64Value(int64_t* value) const
{
if (XMLUtil::ToInt64(Value(), value)) {
return XML_SUCCESS;
}
return XML_WRONG_ATTRIBUTE_TYPE;
}
XMLError XMLAttribute::QueryBoolValue( bool* value ) const
{
if ( XMLUtil::ToBool( Value(), value )) {
return XML_NO_ERROR;
return XML_SUCCESS;
}
return XML_WRONG_ATTRIBUTE_TYPE;
}
@@ -1222,7 +1342,7 @@ XMLError XMLAttribute::QueryBoolValue( bool* value ) const
XMLError XMLAttribute::QueryFloatValue( float* value ) const
{
if ( XMLUtil::ToFloat( Value(), value )) {
return XML_NO_ERROR;
return XML_SUCCESS;
}
return XML_WRONG_ATTRIBUTE_TYPE;
}
@@ -1231,7 +1351,7 @@ XMLError XMLAttribute::QueryFloatValue( float* value ) const
XMLError XMLAttribute::QueryDoubleValue( double* value ) const
{
if ( XMLUtil::ToDouble( Value(), value )) {
return XML_NO_ERROR;
return XML_SUCCESS;
}
return XML_WRONG_ATTRIBUTE_TYPE;
}
@@ -1259,6 +1379,15 @@ void XMLAttribute::SetAttribute( unsigned v )
}
void XMLAttribute::SetAttribute(int64_t v)
{
char buf[BUF_SIZE];
XMLUtil::ToStr(v, buf, BUF_SIZE);
_value.SetStr(buf);
}
void XMLAttribute::SetAttribute( bool v )
{
char buf[BUF_SIZE];
@@ -1359,7 +1488,15 @@ void XMLElement::SetText( unsigned v )
}
void XMLElement::SetText( bool v )
void XMLElement::SetText(int64_t v)
{
char buf[BUF_SIZE];
XMLUtil::ToStr(v, buf, BUF_SIZE);
SetText(buf);
}
void XMLElement::SetText( bool v )
{
char buf[BUF_SIZE];
XMLUtil::ToStr( v, buf, BUF_SIZE );
@@ -1409,6 +1546,19 @@ XMLError XMLElement::QueryUnsignedText( unsigned* uval ) const
}
XMLError XMLElement::QueryInt64Text(int64_t* ival) const
{
if (FirstChild() && FirstChild()->ToText()) {
const char* t = FirstChild()->Value();
if (XMLUtil::ToInt64(t, ival)) {
return XML_SUCCESS;
}
return XML_CAN_NOT_CONVERT_TEXT;
}
return XML_NO_TEXT_NODE;
}
XMLError XMLElement::QueryBoolText( bool* bval ) const
{
if ( FirstChild() && FirstChild()->ToText() ) {
@@ -1536,15 +1686,15 @@ char* XMLElement::ParseAttributes( char* p )
prevAttribute = attrib;
}
// end of the tag
else if ( *p == '/' && *(p+1) == '>' ) {
_closingType = CLOSED;
return p+2; // done; sealed element.
}
// end of the tag
else if ( *p == '>' ) {
++p;
break;
}
// end of the tag
else if ( *p == '/' && *(p+1) == '>' ) {
_closingType = CLOSED;
return p+2; // done; sealed element.
}
else {
_document->SetError( XML_ERROR_PARSING_ELEMENT, start, p );
return 0;
@@ -1613,7 +1763,7 @@ bool XMLElement::ShallowEqual( const XMLNode* compare ) const
{
TIXMLASSERT( compare );
const XMLElement* other = compare->ToElement();
if ( other && XMLUtil::StringEqual( other->Value(), Value() )) {
if ( other && XMLUtil::StringEqual( other->Name(), Name() )) {
const XMLAttribute* a=FirstAttribute();
const XMLAttribute* b=other->FirstAttribute();
@@ -1680,13 +1830,14 @@ XMLDocument::XMLDocument( bool processEntities, Whitespace whitespace ) :
XMLNode( 0 ),
_writeBOM( false ),
_processEntities( processEntities ),
_errorID( XML_NO_ERROR ),
_errorID(XML_SUCCESS),
_whitespace( whitespace ),
_errorStr1( 0 ),
_errorStr2( 0 ),
_charBuffer( 0 )
{
_document = this; // avoid warning about 'this' in initializer list
// avoid VC++ C4355 warning about 'this' in initializer list (C4355 is off by default in VS2012+)
_document = this;
}
@@ -1703,7 +1854,7 @@ void XMLDocument::Clear()
#ifdef DEBUG
const bool hadError = Error();
#endif
_errorID = XML_NO_ERROR;
_errorID = XML_SUCCESS;
_errorStr1 = 0;
_errorStr2 = 0;
@@ -1824,6 +1975,28 @@ XMLError XMLDocument::LoadFile( const char* filename )
return _errorID;
}
// This is likely overengineered template art to have a check that unsigned long value incremented
// by one still fits into size_t. If size_t type is larger than unsigned long type
// (x86_64-w64-mingw32 target) then the check is redundant and gcc and clang emit
// -Wtype-limits warning. This piece makes the compiler select code with a check when a check
// is useful and code with no check when a check is redundant depending on how size_t and unsigned long
// types sizes relate to each other.
template
<bool = (sizeof(unsigned long) >= sizeof(size_t))>
struct LongFitsIntoSizeTMinusOne {
static bool Fits( unsigned long value )
{
return value < (size_t)-1;
}
};
template <>
struct LongFitsIntoSizeTMinusOne<false> {
static bool Fits( unsigned long )
{
return true;
}
};
XMLError XMLDocument::LoadFile( FILE* fp )
{
@@ -1842,13 +2015,21 @@ XMLError XMLDocument::LoadFile( FILE* fp )
SetError( XML_ERROR_FILE_READ_ERROR, 0, 0 );
return _errorID;
}
TIXMLASSERT( filelength >= 0 );
const size_t size = filelength;
if ( size == 0 ) {
if ( !LongFitsIntoSizeTMinusOne<>::Fits( filelength ) ) {
// Cannot handle files which won't fit in buffer together with null terminator
SetError( XML_ERROR_FILE_READ_ERROR, 0, 0 );
return _errorID;
}
if ( filelength == 0 ) {
SetError( XML_ERROR_EMPTY_DOCUMENT, 0, 0 );
return _errorID;
}
const size_t size = filelength;
TIXMLASSERT( _charBuffer == 0 );
_charBuffer = new char[size+1];
size_t read = fread( _charBuffer, 1, size, fp );
if ( read != size ) {
@@ -1878,6 +2059,9 @@ XMLError XMLDocument::SaveFile( const char* filename, bool compact )
XMLError XMLDocument::SaveFile( FILE* fp, bool compact )
{
// Clear any error from the last save, otherwise it will get reported
// for *this* call.
SetError(XML_SUCCESS, 0, 0);
XMLPrinter stream( fp, compact );
Print( &stream );
return _errorID;
@@ -1895,6 +2079,7 @@ XMLError XMLDocument::Parse( const char* p, size_t len )
if ( len == (size_t)(-1) ) {
len = strlen( p );
}
TIXMLASSERT( _charBuffer == 0 );
_charBuffer = new char[ len+1 ];
memcpy( _charBuffer, p, len );
_charBuffer[len] = 0;
@@ -1916,11 +2101,13 @@ XMLError XMLDocument::Parse( const char* p, size_t len )
void XMLDocument::Print( XMLPrinter* streamer ) const
{
XMLPrinter stdStreamer( stdout );
if ( !streamer ) {
streamer = &stdStreamer;
if ( streamer ) {
Accept( streamer );
}
else {
XMLPrinter stdoutStreamer( stdout );
Accept( &stdoutStreamer );
}
Accept( streamer );
}
@@ -1935,7 +2122,9 @@ void XMLDocument::SetError( XMLError error, const char* str1, const char* str2 )
const char* XMLDocument::ErrorName() const
{
TIXMLASSERT( _errorID >= 0 && _errorID < XML_ERROR_COUNT );
return _errorNames[_errorID];
const char* errorName = _errorNames[_errorID];
TIXMLASSERT( errorName && errorName[0] );
return errorName;
}
void XMLDocument::PrintError() const
@@ -1952,8 +2141,11 @@ void XMLDocument::PrintError() const
TIXML_SNPRINTF( buf2, LEN, "%s", _errorStr2 );
}
// Should check INT_MIN <= _errorID && _errorId <= INT_MAX, but that
// causes a clang "always true" -Wtautological-constant-out-of-range-compare warning
TIXMLASSERT( 0 <= _errorID && XML_ERROR_COUNT - 1 <= INT_MAX );
printf( "XMLDocument error id=%d '%s' str1=%s str2=%s\n",
_errorID, ErrorName(), buf1, buf2 );
static_cast<int>( _errorID ), ErrorName(), buf1, buf2 );
}
}
@@ -2005,35 +2197,14 @@ void XMLPrinter::Print( const char* format, ... )
vfprintf( _fp, format, va );
}
else {
#if defined(_MSC_VER) && (_MSC_VER >= 1400 )
#if defined(WINCE)
int len = 512;
do {
len = len*2;
char* str = new char[len]();
len = _vsnprintf(str, len, format, va);
delete[] str;
}while (len < 0);
#else
int len = _vscprintf( format, va );
#endif
#else
int len = vsnprintf( 0, 0, format, va );
#endif
const int len = TIXML_VSCPRINTF( format, va );
// Close out and re-start the va-args
va_end( va );
TIXMLASSERT( len >= 0 );
va_start( va, format );
TIXMLASSERT( _buffer.Size() > 0 && _buffer[_buffer.Size() - 1] == 0 );
char* p = _buffer.PushArr( len ) - 1; // back up over the null terminator.
#if defined(_MSC_VER) && (_MSC_VER >= 1400 )
#if defined(WINCE)
_vsnprintf( p, len+1, format, va );
#else
vsnprintf_s( p, len+1, _TRUNCATE, format, va );
#endif
#else
vsnprintf( p, len+1, format, va );
#endif
TIXML_VSNPRINTF( p, len+1, format, va );
}
va_end( va );
}
@@ -2055,6 +2226,7 @@ void XMLPrinter::PrintString( const char* p, bool restricted )
if ( _processEntities ) {
const bool* flag = restricted ? _restrictedEntityFlag : _entityFlag;
while ( *q ) {
TIXMLASSERT( p <= q );
// Remember, char is sometimes signed. (How many times has that bitten me?)
if ( *q > 0 && *q < ENTITY_RANGE ) {
// Check for entities. If one is found, flush
@@ -2062,24 +2234,35 @@ void XMLPrinter::PrintString( const char* p, bool restricted )
// entity, and keep looking.
if ( flag[(unsigned char)(*q)] ) {
while ( p < q ) {
Print( "%c", *p );
++p;
const size_t delta = q - p;
// %.*s accepts type int as "precision"
const int toPrint = ( INT_MAX < delta ) ? INT_MAX : (int)delta;
Print( "%.*s", toPrint, p );
p += toPrint;
}
bool entityPatternPrinted = false;
for( int i=0; i<NUM_ENTITIES; ++i ) {
if ( entities[i].value == *q ) {
Print( "&%s;", entities[i].pattern );
entityPatternPrinted = true;
break;
}
}
if ( !entityPatternPrinted ) {
// TIXMLASSERT( entityPatternPrinted ) causes gcc -Wunused-but-set-variable in release
TIXMLASSERT( false );
}
++p;
}
}
++q;
TIXMLASSERT( p <= q );
}
}
// Flush the remaining string. This will be the entire
// string if an entity wasn't found.
if ( !_processEntities || (q-p > 0) ) {
TIXMLASSERT( p <= q );
if ( !_processEntities || ( p < q ) ) {
Print( "%s", p );
}
}
@@ -2141,6 +2324,14 @@ void XMLPrinter::PushAttribute( const char* name, unsigned v )
}
void XMLPrinter::PushAttribute(const char* name, int64_t v)
{
char buf[BUF_SIZE];
XMLUtil::ToStr(v, buf, BUF_SIZE);
PushAttribute(name, buf);
}
void XMLPrinter::PushAttribute( const char* name, bool v )
{
char buf[BUF_SIZE];
@@ -2199,9 +2390,7 @@ void XMLPrinter::PushText( const char* text, bool cdata )
SealElementIfJustOpened();
if ( cdata ) {
Print( "<![CDATA[" );
Print( "%s", text );
Print( "]]>" );
Print( "<![CDATA[%s]]>", text );
}
else {
PrintString( text, true );
@@ -2296,8 +2485,11 @@ bool XMLPrinter::VisitEnter( const XMLDocument& doc )
bool XMLPrinter::VisitEnter( const XMLElement& element, const XMLAttribute* attribute )
{
const XMLElement* parentElem = element.Parent()->ToElement();
bool compactMode = parentElem ? CompactMode(*parentElem) : _compactMode;
const XMLElement* parentElem = 0;
if ( element.Parent() ) {
parentElem = element.Parent()->ToElement();
}
const bool compactMode = parentElem ? CompactMode( *parentElem ) : _compactMode;
OpenElement( element.Name(), compactMode );
while ( attribute ) {
PushAttribute( attribute->Name(), attribute->Value() );

View File

@@ -30,15 +30,17 @@ distribution.
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <stdarg.h>
# if defined(__PS3__)
# include <stddef.h>
# endif
#else
# include <cctype>
# include <climits>
# include <cstdio>
# include <cstdlib>
# include <cstring>
# include <cstdarg>
#endif
#include <stdint.h>
/*
TODO: intern strings instead of allocation.
@@ -78,7 +80,7 @@ distribution.
#if defined(DEBUG)
# if defined(_MSC_VER)
# // "(void)0," is for suppressing C4127 warning in "assert(false)", "assert(true)" and the like
# define TIXMLASSERT( x ) if ( !((void)0,(x))) { __debugbreak(); } //if ( !(x)) WinDebugBreak()
# define TIXMLASSERT( x ) if ( !((void)0,(x))) { __debugbreak(); }
# elif defined (ANDROID_NDK)
# include <android/log.h>
# define TIXMLASSERT( x ) if ( !(x)) { __android_log_assert( "assert", "grinliz", "ASSERT in '%s' at %d.", __FILE__, __LINE__ ); }
@@ -86,45 +88,17 @@ distribution.
# include <assert.h>
# define TIXMLASSERT assert
# endif
# else
# define TIXMLASSERT( x ) {}
#endif
#if defined(_MSC_VER) && (_MSC_VER >= 1400 ) && (!defined WINCE)
// Microsoft visual studio, version 2005 and higher.
/*int _snprintf_s(
char *buffer,
size_t sizeOfBuffer,
size_t count,
const char *format [,
argument] ...
);*/
inline int TIXML_SNPRINTF( char* buffer, size_t size, const char* format, ... )
{
va_list va;
va_start( va, format );
int result = vsnprintf_s( buffer, size, _TRUNCATE, format, va );
va_end( va );
return result;
}
#define TIXML_SSCANF sscanf_s
#elif defined WINCE
#define TIXML_SNPRINTF _snprintf
#define TIXML_SSCANF sscanf
#else
// GCC version 3 and higher
//#warning( "Using sn* functions." )
#define TIXML_SNPRINTF snprintf
#define TIXML_SSCANF sscanf
# define TIXMLASSERT( x ) {}
#endif
/* Versioning, past 1.0.14:
http://semver.org/
*/
static const int TIXML2_MAJOR_VERSION = 3;
static const int TIXML2_MINOR_VERSION = 0;
static const int TIXML2_PATCH_VERSION = 0;
static const int TIXML2_MAJOR_VERSION = 4;
static const int TIXML2_MINOR_VERSION = 0;
static const int TIXML2_PATCH_VERSION = 1;
namespace tinyxml2
{
@@ -149,7 +123,7 @@ public:
enum {
NEEDS_ENTITY_PROCESSING = 0x01,
NEEDS_NEWLINE_NORMALIZATION = 0x02,
COLLAPSE_WHITESPACE = 0x04,
NEEDS_WHITESPACE_COLLAPSING = 0x04,
TEXT_ELEMENT = NEEDS_ENTITY_PROCESSING | NEEDS_NEWLINE_NORMALIZATION,
TEXT_ELEMENT_LEAVE_ENTITIES = NEEDS_NEWLINE_NORMALIZATION,
@@ -196,7 +170,6 @@ private:
NEEDS_DELETE = 0x200
};
// After parsing, if *_end != 0, it can be set to zero.
int _flags;
char* _start;
char* _end;
@@ -211,13 +184,13 @@ private:
Has a small initial memory pool, so that low or no usage will not
cause a call to new/delete
*/
template <class T, int INIT>
template <class T, int INITIAL_SIZE>
class DynArray
{
public:
DynArray() {
_mem = _pool;
_allocated = INIT;
_allocated = INITIAL_SIZE;
_size = 0;
}
@@ -281,14 +254,17 @@ public:
}
int Capacity() const {
TIXMLASSERT( _allocated >= INITIAL_SIZE );
return _allocated;
}
const T* Mem() const {
TIXMLASSERT( _mem );
return _mem;
}
T* Mem() {
TIXMLASSERT( _mem );
return _mem;
}
@@ -312,7 +288,7 @@ private:
}
T* _mem;
T _pool[INIT];
T _pool[INITIAL_SIZE];
int _allocated; // objects allocated
int _size; // number objects in use
};
@@ -513,7 +489,6 @@ public:
// WARNING: must match XMLDocument::_errorNames[]
enum XMLError {
XML_SUCCESS = 0,
XML_NO_ERROR = 0,
XML_NO_ATTRIBUTE,
XML_WRONG_ATTRIBUTE_TYPE,
XML_ERROR_FILE_NOT_FOUND,
@@ -584,19 +559,10 @@ public:
if ( p == q ) {
return true;
}
int n = 0;
while( *p && *q && *p == *q && n<nChar ) {
++p;
++q;
++n;
}
if ( (n == nChar) || ( *p == 0 && *q == 0 ) ) {
return true;
}
return false;
return strncmp( p, q, nChar ) == 0;
}
inline static bool IsUTF8Continuation( const char p ) {
inline static bool IsUTF8Continuation( char p ) {
return ( p & 0x80 ) != 0;
}
@@ -612,6 +578,7 @@ public:
static void ToStr( bool v, char* buffer, int bufferSize );
static void ToStr( float v, char* buffer, int bufferSize );
static void ToStr( double v, char* buffer, int bufferSize );
static void ToStr(int64_t v, char* buffer, int bufferSize);
// converts strings to primitive types
static bool ToInt( const char* str, int* value );
@@ -619,6 +586,7 @@ public:
static bool ToBool( const char* str, bool* value );
static bool ToFloat( const char* str, float* value );
static bool ToDouble( const char* str, double* value );
static bool ToInt64(const char* str, int64_t* value);
};
@@ -655,10 +623,12 @@ public:
/// Get the XMLDocument that owns this XMLNode.
const XMLDocument* GetDocument() const {
TIXMLASSERT( _document );
return _document;
}
/// Get the XMLDocument that owns this XMLNode.
XMLDocument* GetDocument() {
TIXMLASSERT( _document );
return _document;
}
@@ -708,7 +678,7 @@ public:
/** The meaning of 'value' changes for the specific type.
@verbatim
Document: empty
Document: empty (NULL is returned, not an empty string)
Element: name of the element
Comment: the comment text
Unknown: the tag contents
@@ -748,10 +718,10 @@ public:
/** Get the first child element, or optionally the first child
element with the specified name.
*/
const XMLElement* FirstChildElement( const char* value=0 ) const;
const XMLElement* FirstChildElement( const char* name = 0 ) const;
XMLElement* FirstChildElement( const char* value=0 ) {
return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->FirstChildElement( value ));
XMLElement* FirstChildElement( const char* name = 0 ) {
return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->FirstChildElement( name ));
}
/// Get the last child node, or null if none exists.
@@ -760,16 +730,16 @@ public:
}
XMLNode* LastChild() {
return const_cast<XMLNode*>(const_cast<const XMLNode*>(this)->LastChild() );
return _lastChild;
}
/** Get the last child element or optionally the last child
element with the specified name.
*/
const XMLElement* LastChildElement( const char* value=0 ) const;
const XMLElement* LastChildElement( const char* name = 0 ) const;
XMLElement* LastChildElement( const char* value=0 ) {
return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->LastChildElement(value) );
XMLElement* LastChildElement( const char* name = 0 ) {
return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->LastChildElement(name) );
}
/// Get the previous (left) sibling node of this node.
@@ -782,10 +752,10 @@ public:
}
/// Get the previous (left) sibling element of this node, with an optionally supplied name.
const XMLElement* PreviousSiblingElement( const char* value=0 ) const ;
const XMLElement* PreviousSiblingElement( const char* name = 0 ) const ;
XMLElement* PreviousSiblingElement( const char* value=0 ) {
return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->PreviousSiblingElement( value ) );
XMLElement* PreviousSiblingElement( const char* name = 0 ) {
return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->PreviousSiblingElement( name ) );
}
/// Get the next (right) sibling node of this node.
@@ -798,10 +768,10 @@ public:
}
/// Get the next (right) sibling element of this node, with an optionally supplied name.
const XMLElement* NextSiblingElement( const char* value=0 ) const;
const XMLElement* NextSiblingElement( const char* name = 0 ) const;
XMLElement* NextSiblingElement( const char* value=0 ) {
return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->NextSiblingElement( value ) );
XMLElement* NextSiblingElement( const char* name = 0 ) {
return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->NextSiblingElement( name ) );
}
/**
@@ -887,13 +857,26 @@ public:
*/
virtual bool Accept( XMLVisitor* visitor ) const = 0;
// internal
virtual char* ParseDeep( char*, StrPair* );
/**
Set user data into the XMLNode. TinyXML-2 in
no way processes or interprets user data.
It is initially 0.
*/
void SetUserData(void* userData) { _userData = userData; }
/**
Get user data set into the XMLNode. TinyXML-2 in
no way processes or interprets user data.
It is initially 0.
*/
void* GetUserData() const { return _userData; }
protected:
XMLNode( XMLDocument* );
virtual ~XMLNode();
virtual char* ParseDeep( char*, StrPair* );
XMLDocument* _document;
XMLNode* _parent;
mutable StrPair _value;
@@ -904,6 +887,8 @@ protected:
XMLNode* _prev;
XMLNode* _next;
void* _userData;
private:
MemPool* _memPool;
void Unlink( XMLNode* child );
@@ -929,7 +914,6 @@ private:
*/
class TINYXML2_LIB XMLText : public XMLNode
{
friend class XMLBase;
friend class XMLDocument;
public:
virtual bool Accept( XMLVisitor* visitor ) const;
@@ -950,7 +934,6 @@ public:
return _isCData;
}
char* ParseDeep( char*, StrPair* endTag );
virtual XMLNode* ShallowClone( XMLDocument* document ) const;
virtual bool ShallowEqual( const XMLNode* compare ) const;
@@ -958,6 +941,8 @@ protected:
XMLText( XMLDocument* doc ) : XMLNode( doc ), _isCData( false ) {}
virtual ~XMLText() {}
char* ParseDeep( char*, StrPair* endTag );
private:
bool _isCData;
@@ -980,7 +965,6 @@ public:
virtual bool Accept( XMLVisitor* visitor ) const;
char* ParseDeep( char*, StrPair* endTag );
virtual XMLNode* ShallowClone( XMLDocument* document ) const;
virtual bool ShallowEqual( const XMLNode* compare ) const;
@@ -988,6 +972,8 @@ protected:
XMLComment( XMLDocument* doc );
virtual ~XMLComment();
char* ParseDeep( char*, StrPair* endTag );
private:
XMLComment( const XMLComment& ); // not supported
XMLComment& operator=( const XMLComment& ); // not supported
@@ -1018,7 +1004,6 @@ public:
virtual bool Accept( XMLVisitor* visitor ) const;
char* ParseDeep( char*, StrPair* endTag );
virtual XMLNode* ShallowClone( XMLDocument* document ) const;
virtual bool ShallowEqual( const XMLNode* compare ) const;
@@ -1026,6 +1011,8 @@ protected:
XMLDeclaration( XMLDocument* doc );
virtual ~XMLDeclaration();
char* ParseDeep( char*, StrPair* endTag );
private:
XMLDeclaration( const XMLDeclaration& ); // not supported
XMLDeclaration& operator=( const XMLDeclaration& ); // not supported
@@ -1052,7 +1039,6 @@ public:
virtual bool Accept( XMLVisitor* visitor ) const;
char* ParseDeep( char*, StrPair* endTag );
virtual XMLNode* ShallowClone( XMLDocument* document ) const;
virtual bool ShallowEqual( const XMLNode* compare ) const;
@@ -1060,6 +1046,8 @@ protected:
XMLUnknown( XMLDocument* doc );
virtual ~XMLUnknown();
char* ParseDeep( char*, StrPair* endTag );
private:
XMLUnknown( const XMLUnknown& ); // not supported
XMLUnknown& operator=( const XMLUnknown& ); // not supported
@@ -1092,11 +1080,18 @@ public:
If the value isn't an integer, 0 will be returned. There is no error checking;
use QueryIntValue() if you need error checking.
*/
int IntValue() const {
int i=0;
QueryIntValue( &i );
return i;
}
int IntValue() const {
int i = 0;
QueryIntValue(&i);
return i;
}
int64_t Int64Value() const {
int64_t i = 0;
QueryInt64Value(&i);
return i;
}
/// Query as an unsigned integer. See IntValue()
unsigned UnsignedValue() const {
unsigned i=0;
@@ -1129,7 +1124,9 @@ public:
XMLError QueryIntValue( int* value ) const;
/// See QueryIntValue
XMLError QueryUnsignedValue( unsigned int* value ) const;
/// See QueryIntValue
/// See QueryIntValue
XMLError QueryInt64Value(int64_t* value) const;
/// See QueryIntValue
XMLError QueryBoolValue( bool* value ) const;
/// See QueryIntValue
XMLError QueryDoubleValue( double* value ) const;
@@ -1142,7 +1139,9 @@ public:
void SetAttribute( int value );
/// Set the attribute to value.
void SetAttribute( unsigned value );
/// Set the attribute to value.
/// Set the attribute to value.
void SetAttribute(int64_t value);
/// Set the attribute to value.
void SetAttribute( bool value );
/// Set the attribute to value.
void SetAttribute( double value );
@@ -1174,7 +1173,6 @@ private:
*/
class TINYXML2_LIB XMLElement : public XMLNode
{
friend class XMLBase;
friend class XMLDocument;
public:
/// Get the name of an element (which is the Value() of the node.)
@@ -1229,26 +1227,35 @@ public:
QueryIntAttribute( name, &i );
return i;
}
/// See IntAttribute()
unsigned UnsignedAttribute( const char* name ) const {
unsigned i=0;
QueryUnsignedAttribute( name, &i );
return i;
}
/// See IntAttribute()
bool BoolAttribute( const char* name ) const {
/// See IntAttribute()
int64_t Int64Attribute(const char* name) const {
int64_t i = 0;
QueryInt64Attribute(name, &i);
return i;
}
/// See IntAttribute()
bool BoolAttribute( const char* name ) const {
bool b=false;
QueryBoolAttribute( name, &b );
return b;
}
/// See IntAttribute()
double DoubleAttribute( const char* name ) const {
double DoubleAttribute( const char* name ) const {
double d=0;
QueryDoubleAttribute( name, &d );
return d;
}
/// See IntAttribute()
float FloatAttribute( const char* name ) const {
float FloatAttribute( const char* name ) const {
float f=0;
QueryFloatAttribute( name, &f );
return f;
@@ -1274,7 +1281,8 @@ public:
}
return a->QueryIntValue( value );
}
/// See QueryIntAttribute()
/// See QueryIntAttribute()
XMLError QueryUnsignedAttribute( const char* name, unsigned int* value ) const {
const XMLAttribute* a = FindAttribute( name );
if ( !a ) {
@@ -1282,7 +1290,17 @@ public:
}
return a->QueryUnsignedValue( value );
}
/// See QueryIntAttribute()
/// See QueryIntAttribute()
XMLError QueryInt64Attribute(const char* name, int64_t* value) const {
const XMLAttribute* a = FindAttribute(name);
if (!a) {
return XML_NO_ATTRIBUTE;
}
return a->QueryInt64Value(value);
}
/// See QueryIntAttribute()
XMLError QueryBoolAttribute( const char* name, bool* value ) const {
const XMLAttribute* a = FindAttribute( name );
if ( !a ) {
@@ -1333,6 +1351,10 @@ public:
return QueryUnsignedAttribute( name, value );
}
int QueryAttribute(const char* name, int64_t* value) const {
return QueryInt64Attribute(name, value);
}
int QueryAttribute( const char* name, bool* value ) const {
return QueryBoolAttribute( name, value );
}
@@ -1360,7 +1382,14 @@ public:
XMLAttribute* a = FindOrCreateAttribute( name );
a->SetAttribute( value );
}
/// Sets the named attribute to value.
/// Sets the named attribute to value.
void SetAttribute(const char* name, int64_t value) {
XMLAttribute* a = FindOrCreateAttribute(name);
a->SetAttribute(value);
}
/// Sets the named attribute to value.
void SetAttribute( const char* name, bool value ) {
XMLAttribute* a = FindOrCreateAttribute( name );
a->SetAttribute( value );
@@ -1453,15 +1482,17 @@ public:
@endverbatim
*/
void SetText( const char* inText );
/// Convenience method for setting text inside and element. See SetText() for important limitations.
/// Convenience method for setting text inside an element. See SetText() for important limitations.
void SetText( int value );
/// Convenience method for setting text inside and element. See SetText() for important limitations.
/// Convenience method for setting text inside an element. See SetText() for important limitations.
void SetText( unsigned value );
/// Convenience method for setting text inside and element. See SetText() for important limitations.
/// Convenience method for setting text inside an element. See SetText() for important limitations.
void SetText(int64_t value);
/// Convenience method for setting text inside an element. See SetText() for important limitations.
void SetText( bool value );
/// Convenience method for setting text inside and element. See SetText() for important limitations.
/// Convenience method for setting text inside an element. See SetText() for important limitations.
void SetText( double value );
/// Convenience method for setting text inside and element. See SetText() for important limitations.
/// Convenience method for setting text inside an element. See SetText() for important limitations.
void SetText( float value );
/**
@@ -1493,7 +1524,9 @@ public:
XMLError QueryIntText( int* ival ) const;
/// See QueryIntText()
XMLError QueryUnsignedText( unsigned* uval ) const;
/// See QueryIntText()
/// See QueryIntText()
XMLError QueryInt64Text(int64_t* uval) const;
/// See QueryIntText()
XMLError QueryBoolText( bool* bval ) const;
/// See QueryIntText()
XMLError QueryDoubleText( double* dval ) const;
@@ -1509,10 +1542,12 @@ public:
int ClosingType() const {
return _closingType;
}
char* ParseDeep( char* p, StrPair* endTag );
virtual XMLNode* ShallowClone( XMLDocument* document ) const;
virtual bool ShallowEqual( const XMLNode* compare ) const;
protected:
char* ParseDeep( char* p, StrPair* endTag );
private:
XMLElement( XMLDocument* doc );
virtual ~XMLElement();
@@ -1556,9 +1591,11 @@ public:
~XMLDocument();
virtual XMLDocument* ToDocument() {
TIXMLASSERT( this == _document );
return this;
}
virtual const XMLDocument* ToDocument() const {
TIXMLASSERT( this == _document );
return this;
}
@@ -1703,7 +1740,7 @@ public:
/// Return true if there was an error parsing the document.
bool Error() const {
return _errorID != XML_NO_ERROR;
return _errorID != XML_SUCCESS;
}
/// Return the errorID.
XMLError ErrorID() const {
@@ -1839,32 +1876,32 @@ public:
return XMLHandle( _node ? _node->FirstChild() : 0 );
}
/// Get the first child element of this handle.
XMLHandle FirstChildElement( const char* value=0 ) {
return XMLHandle( _node ? _node->FirstChildElement( value ) : 0 );
XMLHandle FirstChildElement( const char* name = 0 ) {
return XMLHandle( _node ? _node->FirstChildElement( name ) : 0 );
}
/// Get the last child of this handle.
XMLHandle LastChild() {
return XMLHandle( _node ? _node->LastChild() : 0 );
}
/// Get the last child element of this handle.
XMLHandle LastChildElement( const char* _value=0 ) {
return XMLHandle( _node ? _node->LastChildElement( _value ) : 0 );
XMLHandle LastChildElement( const char* name = 0 ) {
return XMLHandle( _node ? _node->LastChildElement( name ) : 0 );
}
/// Get the previous sibling of this handle.
XMLHandle PreviousSibling() {
return XMLHandle( _node ? _node->PreviousSibling() : 0 );
}
/// Get the previous sibling element of this handle.
XMLHandle PreviousSiblingElement( const char* _value=0 ) {
return XMLHandle( _node ? _node->PreviousSiblingElement( _value ) : 0 );
XMLHandle PreviousSiblingElement( const char* name = 0 ) {
return XMLHandle( _node ? _node->PreviousSiblingElement( name ) : 0 );
}
/// Get the next sibling of this handle.
XMLHandle NextSibling() {
return XMLHandle( _node ? _node->NextSibling() : 0 );
}
/// Get the next sibling element of this handle.
XMLHandle NextSiblingElement( const char* _value=0 ) {
return XMLHandle( _node ? _node->NextSiblingElement( _value ) : 0 );
XMLHandle NextSiblingElement( const char* name = 0 ) {
return XMLHandle( _node ? _node->NextSiblingElement( name ) : 0 );
}
/// Safe cast to XMLNode. This can return null.
@@ -1918,26 +1955,26 @@ public:
const XMLConstHandle FirstChild() const {
return XMLConstHandle( _node ? _node->FirstChild() : 0 );
}
const XMLConstHandle FirstChildElement( const char* value=0 ) const {
return XMLConstHandle( _node ? _node->FirstChildElement( value ) : 0 );
const XMLConstHandle FirstChildElement( const char* name = 0 ) const {
return XMLConstHandle( _node ? _node->FirstChildElement( name ) : 0 );
}
const XMLConstHandle LastChild() const {
return XMLConstHandle( _node ? _node->LastChild() : 0 );
}
const XMLConstHandle LastChildElement( const char* _value=0 ) const {
return XMLConstHandle( _node ? _node->LastChildElement( _value ) : 0 );
const XMLConstHandle LastChildElement( const char* name = 0 ) const {
return XMLConstHandle( _node ? _node->LastChildElement( name ) : 0 );
}
const XMLConstHandle PreviousSibling() const {
return XMLConstHandle( _node ? _node->PreviousSibling() : 0 );
}
const XMLConstHandle PreviousSiblingElement( const char* _value=0 ) const {
return XMLConstHandle( _node ? _node->PreviousSiblingElement( _value ) : 0 );
const XMLConstHandle PreviousSiblingElement( const char* name = 0 ) const {
return XMLConstHandle( _node ? _node->PreviousSiblingElement( name ) : 0 );
}
const XMLConstHandle NextSibling() const {
return XMLConstHandle( _node ? _node->NextSibling() : 0 );
}
const XMLConstHandle NextSiblingElement( const char* _value=0 ) const {
return XMLConstHandle( _node ? _node->NextSiblingElement( _value ) : 0 );
const XMLConstHandle NextSiblingElement( const char* name = 0 ) const {
return XMLConstHandle( _node ? _node->NextSiblingElement( name ) : 0 );
}
@@ -2026,7 +2063,8 @@ public:
void PushAttribute( const char* name, const char* value );
void PushAttribute( const char* name, int value );
void PushAttribute( const char* name, unsigned value );
void PushAttribute( const char* name, bool value );
void PushAttribute(const char* name, int64_t value);
void PushAttribute( const char* name, bool value );
void PushAttribute( const char* name, double value );
/// If streaming, close the Element.
virtual void CloseElement( bool compactMode=false );
@@ -2037,7 +2075,9 @@ public:
void PushText( int value );
/// Add a text node from an unsigned.
void PushText( unsigned value );
/// Add a text node from a bool.
/// Add a text node from an unsigned.
void PushText(int64_t value);
/// Add a text node from a bool.
void PushText( bool value );
/// Add a text node from a float.
void PushText( float value );

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug-Dll|Win32">
<Configuration>Debug-Dll</Configuration>
@@ -37,51 +37,60 @@
<PropertyGroup Label="Globals">
<ProjectGuid>{E8FB2712-8666-4662-A5B8-2B5B0FB1A260}</ProjectGuid>
<RootNamespace>test</RootNamespace>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug-Lib|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug-Lib|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug-Dll|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug-Dll|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release-Lib|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release-Lib|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release-Dll|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release-Dll|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<CharacterSet>Unicode</CharacterSet>
@@ -125,29 +134,25 @@
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug-Dll|Win32'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug-Dll|Win32'">
<OutDir>$(SolutionDir)bin\$(Platform)-$(Configuration)\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug-Dll|Win32'">
<IntDir>$(SolutionDir)temp\$(Platform)-$(Configuration)\</IntDir>
<IntDir>$(SolutionDir)$(Configuration)\</IntDir>
<OutDir>$(SolutionDir)$(Configuration)\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug-Lib|Win32'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug-Lib|Win32'">
<OutDir>$(SolutionDir)bin\$(Platform)-$(Configuration)\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug-Lib|Win32'">
<IntDir>$(SolutionDir)temp\$(Platform)-$(Configuration)\</IntDir>
<IntDir>$(SolutionDir)$(Configuration)\</IntDir>
<OutDir>$(SolutionDir)$(Configuration)\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release-Dll|Win32'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release-Dll|Win32'">
<OutDir>$(SolutionDir)bin\$(Platform)-$(Configuration)\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release-Dll|Win32'">
<IntDir>$(SolutionDir)temp\$(Platform)-$(Configuration)\</IntDir>
<IntDir>$(SolutionDir)$(Configuration)\</IntDir>
<OutDir>$(SolutionDir)$(Configuration)\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release-Lib|Win32'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release-Lib|Win32'">
<OutDir>$(SolutionDir)bin\$(Platform)-$(Configuration)\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release-Lib|Win32'">
<IntDir>$(SolutionDir)temp\$(Platform)-$(Configuration)\</IntDir>
<IntDir>$(SolutionDir)$(Configuration)\</IntDir>
<OutDir>$(SolutionDir)$(Configuration)\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug-Dll|x64'">
<OutDir>$(SolutionDir)bin\$(Platform)-$(Configuration)\</OutDir>

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug-Dll|Win32">
<Configuration>Debug-Dll</Configuration>
@@ -38,51 +38,60 @@
<ProjectGuid>{D1C528B6-AA02-4D29-9D61-DC08E317A70D}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>tinyxml2</RootNamespace>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug-Lib|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug-Dll|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug-Lib|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug-Dll|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release-Lib|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release-Dll|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release-Lib|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release-Dll|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ConfigurationType>StaticLibrary</ConfigurationType>
@@ -132,13 +141,9 @@
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug-Lib|Win32'">
<LinkIncremental>true</LinkIncremental>
<OutDir>$(SolutionDir)bin\$(Platform)-$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)temp\$(Platform)-$(Configuration)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug-Dll|Win32'">
<LinkIncremental>true</LinkIncremental>
<OutDir>$(SolutionDir)bin\$(Platform)-$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)temp\$(Platform)-$(Configuration)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug-Lib|x64'">
<LinkIncremental>true</LinkIncremental>
@@ -152,13 +157,9 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release-Lib|Win32'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)bin\$(Platform)-$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)temp\$(Platform)-$(Configuration)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release-Dll|Win32'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)bin\$(Platform)-$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)temp\$(Platform)-$(Configuration)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release-Lib|x64'">
<LinkIncremental>false</LinkIncremental>

View File

@@ -30,7 +30,13 @@ int gFail = 0;
bool XMLTest (const char* testString, const char* expected, const char* found, bool echo=true, bool extraNL=false )
{
bool pass = !strcmp( expected, found );
bool pass;
if ( !expected && !found )
pass = true;
else if ( !expected || !found )
pass = false;
else
pass = !strcmp( expected, found );
if ( pass )
printf ("[pass]");
else
@@ -410,6 +416,7 @@ int main( int argc, const char ** argv )
}
element->InsertEndChild( sub[2] );
XMLNode* comment = element->InsertFirstChild( doc->NewComment( "comment" ) );
comment->SetUserData((void*)2);
element->InsertAfterChild( comment, sub[0] );
element->InsertAfterChild( sub[0], sub[1] );
sub[2]->InsertFirstChild( doc->NewText( "& Text!" ));
@@ -419,6 +426,7 @@ int main( int argc, const char ** argv )
XMLTest( "Programmatic DOM", 2, doc->FirstChildElement()->LastChildElement( "sub" )->IntAttribute( "attrib" ) );
XMLTest( "Programmatic DOM", "& Text!",
doc->FirstChildElement()->LastChildElement( "sub" )->FirstChild()->ToText()->Value() );
XMLTest("User data", (void*)2 == comment->GetUserData(), true, false);
// And now deletion:
element->DeleteChild( sub[2] );
@@ -507,13 +515,13 @@ int main( int argc, const char ** argv )
double dVal;
result = ele->QueryDoubleAttribute( "attr0", &dVal );
XMLTest( "Query attribute: int as double", result, (int)XML_NO_ERROR );
XMLTest( "Query attribute: int as double", result, (int)XML_SUCCESS);
XMLTest( "Query attribute: int as double", (int)dVal, 1 );
result = ele->QueryDoubleAttribute( "attr1", &dVal );
XMLTest( "Query attribute: double as double", result, (int)XML_NO_ERROR );
XMLTest( "Query attribute: double as double", result, (int)XML_SUCCESS);
XMLTest( "Query attribute: double as double", (int)dVal, 2 );
result = ele->QueryIntAttribute( "attr1", &iVal );
XMLTest( "Query attribute: double as int", result, (int)XML_NO_ERROR );
XMLTest( "Query attribute: double as int", result, (int)XML_SUCCESS);
XMLTest( "Query attribute: double as int", iVal, 2 );
result = ele->QueryIntAttribute( "attr2", &iVal );
XMLTest( "Query attribute: not a number", result, (int)XML_WRONG_ATTRIBUTE_TYPE );
@@ -680,6 +688,107 @@ int main( int argc, const char ** argv )
XMLTest( "SetText types", "1.5", element->GetText() );
}
// ---------- Attributes ---------
{
static const int64_t BIG = -123456789012345678;
XMLDocument doc;
XMLElement* element = doc.NewElement("element");
doc.InsertFirstChild(element);
{
element->SetAttribute("attrib", int(-100));
int v = 0;
element->QueryIntAttribute("attrib", &v);
XMLTest("Attribute: int", -100, v, true);
element->QueryAttribute("attrib", &v);
XMLTest("Attribute: int", -100, v, true);
}
{
element->SetAttribute("attrib", unsigned(100));
unsigned v = 0;
element->QueryUnsignedAttribute("attrib", &v);
XMLTest("Attribute: unsigned", unsigned(100), v, true);
element->QueryAttribute("attrib", &v);
XMLTest("Attribute: unsigned", unsigned(100), v, true);
}
{
element->SetAttribute("attrib", BIG);
int64_t v = 0;
element->QueryInt64Attribute("attrib", &v);
XMLTest("Attribute: int64_t", BIG, v, true);
element->QueryAttribute("attrib", &v);
XMLTest("Attribute: int64_t", BIG, v, true);
}
{
element->SetAttribute("attrib", true);
bool v = false;
element->QueryBoolAttribute("attrib", &v);
XMLTest("Attribute: bool", true, v, true);
element->QueryAttribute("attrib", &v);
XMLTest("Attribute: bool", true, v, true);
}
{
element->SetAttribute("attrib", 100.0);
double v = 0;
element->QueryDoubleAttribute("attrib", &v);
XMLTest("Attribute: double", 100.0, v, true);
element->QueryAttribute("attrib", &v);
XMLTest("Attribute: double", 100.0, v, true);
}
{
element->SetAttribute("attrib", 100.0f);
float v = 0;
element->QueryFloatAttribute("attrib", &v);
XMLTest("Attribute: float", 100.0f, v, true);
element->QueryAttribute("attrib", &v);
XMLTest("Attribute: float", 100.0f, v, true);
}
{
element->SetText(BIG);
int64_t v = 0;
element->QueryInt64Text(&v);
XMLTest("Element: int64_t", BIG, v, true);
}
}
// ---------- XMLPrinter stream mode ------
{
{
FILE* printerfp = fopen("resources/printer.xml", "w");
XMLPrinter printer(printerfp);
printer.OpenElement("foo");
printer.PushAttribute("attrib-text", "text");
printer.PushAttribute("attrib-int", int(1));
printer.PushAttribute("attrib-unsigned", unsigned(2));
printer.PushAttribute("attrib-int64", int64_t(3));
printer.PushAttribute("attrib-bool", true);
printer.PushAttribute("attrib-double", 4.0);
printer.CloseElement();
fclose(printerfp);
}
{
XMLDocument doc;
doc.LoadFile("resources/printer.xml");
XMLTest("XMLPrinter Stream mode: load", doc.ErrorID(), XML_SUCCESS, true);
const XMLDocument& cdoc = doc;
const XMLAttribute* attrib = cdoc.FirstChildElement("foo")->FindAttribute("attrib-text");
XMLTest("attrib-text", "text", attrib->Value(), true);
attrib = cdoc.FirstChildElement("foo")->FindAttribute("attrib-int");
XMLTest("attrib-int", int(1), attrib->IntValue(), true);
attrib = cdoc.FirstChildElement("foo")->FindAttribute("attrib-unsigned");
XMLTest("attrib-unsigned", unsigned(2), attrib->UnsignedValue(), true);
attrib = cdoc.FirstChildElement("foo")->FindAttribute("attrib-int64");
XMLTest("attrib-int64", int64_t(3), attrib->Int64Value(), true);
attrib = cdoc.FirstChildElement("foo")->FindAttribute("attrib-bool");
XMLTest("attrib-bool", true, attrib->BoolValue(), true);
attrib = cdoc.FirstChildElement("foo")->FindAttribute("attrib-double");
XMLTest("attrib-double", 4.0, attrib->DoubleValue(), true);
}
}
// ---------- CDATA ---------------
{
@@ -997,7 +1106,7 @@ int main( int argc, const char ** argv )
{
// This shouldn't crash.
XMLDocument doc;
if(XML_NO_ERROR != doc.LoadFile( "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" ))
if(XML_SUCCESS != doc.LoadFile( "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" ))
{
doc.PrintError();
}
@@ -1167,6 +1276,9 @@ int main( int argc, const char ** argv )
{
XMLDocument doc;
XMLTest( "Document is initially empty", doc.NoChildren(), true );
doc.Clear();
XMLTest( "Empty is empty after Clear()", doc.NoChildren(), true );
doc.LoadFile( "resources/dream.xml" );
XMLTest( "Document has something to Clear()", doc.NoChildren(), false );
doc.Clear();
@@ -1247,7 +1359,7 @@ int main( int argc, const char ** argv )
static const char* xml_bom_preservation = "\xef\xbb\xbf<element/>\n";
{
XMLDocument doc;
XMLTest( "BOM preservation (parse)", XML_NO_ERROR, doc.Parse( xml_bom_preservation ), false );
XMLTest( "BOM preservation (parse)", XML_SUCCESS, doc.Parse( xml_bom_preservation ), false );
XMLPrinter printer;
doc.Print( &printer );
@@ -1425,41 +1537,112 @@ int main( int argc, const char ** argv )
XMLPrinter printer;
doc.Print( &printer );
}
{
// Issue 299. Can print elements that are not linked in.
// Will crash if issue not fixed.
XMLDocument doc;
XMLElement* newElement = doc.NewElement( "printme" );
XMLPrinter printer;
newElement->Accept( &printer );
// Delete the node to avoid possible memory leak report in debug output
doc.DeleteNode( newElement );
}
{
// Issue 302. Clear errors from LoadFile/SaveFile
XMLDocument doc;
XMLTest( "Issue 302. Should be no error initially", "XML_SUCCESS", doc.ErrorName() );
doc.SaveFile( "./no/such/path/pretty.xml" );
XMLTest( "Issue 302. Fail to save", "XML_ERROR_FILE_COULD_NOT_BE_OPENED", doc.ErrorName() );
doc.SaveFile( "./resources/out/compact.xml", true );
XMLTest( "Issue 302. Subsequent success in saving", "XML_SUCCESS", doc.ErrorName() );
}
// ----------- Performance tracking --------------
{
// If a document fails to load then subsequent
// successful loads should clear the error
XMLDocument doc;
XMLTest( "Should be no error initially", false, doc.Error() );
doc.LoadFile( "resources/no-such-file.xml" );
XMLTest( "No such file - should fail", true, doc.Error() );
doc.LoadFile( "resources/dream.xml" );
XMLTest( "Error should be cleared", false, doc.Error() );
}
{
// Check that declarations are parsed only as the FirstChild
const char* xml0 = "<?xml version=\"1.0\" ?>"
" <!-- xml version=\"1.1\" -->"
"<first />";
const char* xml1 = "<?xml version=\"1.0\" ?>"
" <?xml version=\"1.1\" ?>"
"<first />";
const char* xml2 = "<first />"
"<?xml version=\"1.0\" ?>";
XMLDocument doc;
doc.Parse(xml0);
XMLTest("Test that the code changes do not affect normal parsing", doc.Error(), false);
doc.Parse(xml1);
XMLTest("Test that the second declaration throws an error", doc.ErrorID(), XML_ERROR_PARSING_DECLARATION);
doc.Parse(xml2);
XMLTest("Test that declaration after a child throws an error", doc.ErrorID(), XML_ERROR_PARSING_DECLARATION);
}
{
// No matter - before or after successfully parsing a text -
// calling XMLDocument::Value() causes an assert in debug.
const char* validXml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>"
"<first />"
"<second />";
XMLDocument* doc = new XMLDocument();
XMLTest( "XMLDocument::Value() returns null?", NULL, doc->Value() );
doc->Parse( validXml );
XMLTest( "XMLDocument::Value() returns null?", NULL, doc->Value() );
delete doc;
}
{
XMLDocument doc;
for( int i = 0; i < XML_ERROR_COUNT; i++ ) {
doc.SetError( (XMLError)i, 0, 0 );
doc.ErrorName();
}
}
// ----------- Performance tracking --------------
{
#if defined( _MSC_VER )
__int64 start, end, freq;
QueryPerformanceFrequency( (LARGE_INTEGER*) &freq );
QueryPerformanceFrequency((LARGE_INTEGER*)&freq);
#endif
FILE* fp = fopen( "resources/dream.xml", "r" );
fseek( fp, 0, SEEK_END );
long size = ftell( fp );
fseek( fp, 0, SEEK_SET );
FILE* perfFP = fopen("resources/dream.xml", "r");
fseek(perfFP, 0, SEEK_END);
long size = ftell(fp);
fseek(perfFP, 0, SEEK_SET);
char* mem = new char[size+1];
fread( mem, size, 1, fp );
fclose( fp );
char* mem = new char[size + 1];
fread(mem, size, 1, perfFP);
fclose(perfFP);
mem[size] = 0;
#if defined( _MSC_VER )
QueryPerformanceCounter( (LARGE_INTEGER*) &start );
QueryPerformanceCounter((LARGE_INTEGER*)&start);
#else
clock_t cstart = clock();
#endif
static const int COUNT = 10;
for( int i=0; i<COUNT; ++i ) {
for (int i = 0; i < COUNT; ++i) {
XMLDocument doc;
doc.Parse( mem );
doc.Parse(mem);
}
#if defined( _MSC_VER )
QueryPerformanceCounter( (LARGE_INTEGER*) &end );
QueryPerformanceCounter((LARGE_INTEGER*)&end);
#else
clock_t cend = clock();
#endif
delete [] mem;
delete[] mem;
static const char* note =
#ifdef DEBUG
@@ -1469,9 +1652,9 @@ int main( int argc, const char ** argv )
#endif
#if defined( _MSC_VER )
printf( "\nParsing %s of dream.xml: %.3f milli-seconds\n", note, 1000.0 * (double)(end-start) / ( (double)freq * (double)COUNT) );
printf("\nParsing %s of dream.xml: %.3f milli-seconds\n", note, 1000.0 * (double)(end - start) / ((double)freq * (double)COUNT));
#else
printf( "\nParsing %s of dream.xml: %.3f milli-seconds\n", note, (double)(cend - cstart)/(double)COUNT );
printf("\nParsing %s of dream.xml: %.3f milli-seconds\n", note, (double)(cend - cstart) / (double)COUNT);
#endif
}