1
0
mirror of https://github.com/leethomason/tinyxml2.git synced 2026-07-22 19:52:59 +04:00

Compare commits

...

86 Commits

Author SHA1 Message Date
Lee Thomason 96a2dd3a43 Formally set version and testing to C++ 11 2026-05-23 17:55:51 -07:00
Lee Thomason 8224e427b6 Merge branch 'master' of github.com:leethomason/tinyxml2 2026-05-23 17:16:30 -07:00
Lee Thomason 935ddecc91 Null checks in test output (#1076)
Null checks in output.
2026-05-23 16:54:50 -07:00
Lee Thomason 88d678c39e Merge branch 'master' of github.com:leethomason/tinyxml2 2026-05-23 16:42:42 -07:00
Lee Thomason 999a21fa86 Dead platform removal (#1068)
Remove dead platforms.
2026-05-23 16:41:46 -07:00
Lee Thomason a737ecb2cb Fixes from security review (#1067)
Security fix
2026-05-23 16:36:17 -07:00
Lee Thomason 9901919829 Merge branch 'master' of github.com:leethomason/tinyxml2 2026-05-23 16:19:42 -07:00
Miko 63428c8852 Mark project constants depending on C++ version (#1056) 2026-05-23 16:19:24 -07:00
Miko beb16fbca0 Improve README formatting with highlighted blocks (#1055)
Improve README
2026-05-23 16:18:19 -07:00
Lee Thomason 26ab0bd591 Merge branch 'master' of github.com:leethomason/tinyxml2 2026-05-23 16:15:25 -07:00
Lee Thomason 8d8472fe1a Improved XMLNode::~XMLNode perfomance (#1075)
Improved XMLNode::~XMLNode perfomance (#1075)
2026-05-23 16:13:32 -07:00
Lee Thomason 3dcad8e3c3 fix merge (#1066) 2026-03-09 18:09:58 -07:00
Lee Thomason 418229dc5c fix bad merge 2026-03-09 18:02:29 -07:00
Lee Thomason 98137e6936 Merge branch 'master' of github.com:leethomason/tinyxml2 2026-03-09 17:53:04 -07:00
Lee Thomason 111f462dc4 remove old comments 2026-03-09 17:41:19 -07:00
zhthhh aba13c50bf Fix issue #1048: Add null pointer check in XMLDocument::DeleteNode (#1057)
- Add null pointer check in XMLDocument::DeleteNode() method
- Add test case to verify null pointer handling
- Prevents segmentation fault when calling DeleteNode(nullptr)
2026-03-09 17:32:22 -07:00
sbaluja e48a1310fe Add null check for format in TIXML_VSCPRINTF (#1064) 2026-03-09 17:31:36 -07:00
Lee Thomason 3324d04d58 minor readme fixes (#1054) 2025-11-22 16:26:53 -08:00
LuridHound c4e29afeaf Fix issue 1000 (#1040)
* fix compilation warnings produced by -Wold-style-cast

* remove incorrect cast
2025-11-22 16:08:17 -08:00
Lee Thomason 5c9a452c73 Merge fallthrough to cpp (#1052)
Fix warnings on merge fallthroughs
2025-11-22 16:02:49 -08:00
Lee Thomason 2722500313 Merge pull request #1043 from gruenich/feature/replace-c-style-casts
Replace C-style casts
2025-11-22 15:38:08 -08:00
Christoph Grüninger b5e767a6b9 Fix more warnings for C-style casts
Use static_cast or reinterpret_cast.
Found by g++ 15.
2025-07-26 23:08:21 +02:00
Lurend e186491558 fix compilation warnings produced by -Wold-style-cast 2025-07-26 14:26:04 +02:00
Lee Thomason 36ff404c34 Update yaml file
Update yaml file
2025-07-09 20:54:23 -07:00
Lee Thomason 302f4661a7 update yaml 2025-07-09 20:48:05 -07:00
Lee Thomason e6caeae857 Fix the build actions by increasing the ubuntu test version
Update ubuntu build version
2025-06-08 11:37:20 -07:00
Lee Thomason b765a210b3 grumble 2025-06-08 11:29:52 -07:00
Lee Thomason 6e246aec4d update ubuntu build version 2025-06-08 11:28:28 -07:00
Lee Thomason 30dee1efa0 Merge pull request #1021 from Malcohol/Malcohol/optionalAposHandling
Optional Apos escaping
2025-06-08 11:17:12 -07:00
Lee Thomason a93163d2f5 Merge pull request #1020 from lbatuska/master
Remove unnecessary assert >=0 on size_t
2025-06-08 11:08:25 -07:00
Malcolm Tyrrell f87d0e3077 Add test for new and default behaviour 2025-03-30 10:20:26 +01:00
Malcolm Tyrrell 487f42aa69 Optional apos escaping 2025-03-29 18:13:43 +00:00
Levente Batuska afff7bf328 fix: remove unnecessary assert 2025-03-20 02:06:08 +01:00
Lee Thomason 9148bdf719 setting the version to 11.0.0 2025-03-15 14:45:48 -07:00
Lee Thomason 57eea48c5b version to 10.1.0 2025-03-08 10:45:16 -08:00
Lee Thomason 198cb82c9b Merge pull request #1017 from luzpaz/typos-xmltest
fix typos in xmltest.cpp
2025-03-08 10:36:50 -08:00
Lee Thomason c6ab6d76e8 Merge pull request #1013 from AlbertHungGarmin/arm_compiler_error
Fix ARM Compiler build errors
2025-03-08 10:36:09 -08:00
luzpaz 008e32968f fix typos in xmltest.cpp
Found via `codespell -q 3 -S "./resources/dream.xml" -L currenty,ot,previousy,te,ue`
2025-01-25 09:51:29 -05:00
Albert Hung 0ca3584fa4 Fix ARM Compiler build errors
Fix build errors on ARM Compiler 5 (DS-5) by treating the compiler like QNX, Borland C, and the Android NDK for purposes of system header includes.
2024-12-17 10:13:57 +08:00
Lee Thomason 57ec94127b Merge pull request #1011 from leethomason/leethomason/charref2
Defensive check for UTF conversion
2024-12-09 21:47:05 -08:00
Lee Thomason 1fadaae0c9 another defensive check 2024-12-09 21:39:30 -08:00
Lee Thomason 4cbb25155c Merge pull request #1009 from leethomason/leethomason/charref
Fix the potential overflow in char refs
2024-12-09 21:21:42 -08:00
Lee Thomason ff48ea1bae improve fix 2024-12-09 21:17:33 -08:00
Lee Thomason 494735de30 fix the potential overflow in char refs 2024-12-04 18:07:15 -08:00
Lee Thomason d418ac22f2 Merge pull request #1007 from gruenich/feature/update-github-actions
update GitHub actions checkout and actions-setup-cmake
2024-12-04 17:49:04 -08:00
Lee Thomason d13a151c8d Merge pull request #1004 from bebuch/master
add CMake option to disable PkgConfig install
2024-12-04 17:46:06 -08:00
Lee Thomason 601a953b74 Merge pull request #1008 from AlbertHungGarmin/old-style-cast_warning
Fixed old-style-cast warnings
2024-12-04 17:44:31 -08:00
Albert Hung 162bd4e925 Fixed -Wold-style-cast warnings
Fixed old-style-cast warnings
2024-12-02 13:47:07 +08:00
Christoph Grüninger 1fdf653269 GitHub Actions: Update actions/checkout to v4
Fixes warnings regarding deprecated node12
2024-11-24 17:24:03 +01:00
Christoph Grüninger 86fe31c836 GitHub Actions: Update actions-setup-cmake to v2
Fixes warnings regarding deprecated node12
2024-11-24 17:21:49 +01:00
Benjamin Buch 20ecbb22d8 add CMake option to disable PkgConfig install 2024-11-20 16:22:20 +01:00
Lee Thomason 374292e9ba Merge pull request #998 from Sigmarik/master
Fix: typo in the `XMLNode::DeepClone` description
2024-09-02 09:33:10 -07:00
Lee Thomason 2ac336a253 Merge pull request #992 from ssmolov/namespace.comment.fix
fix tinyxml2 namespaces' ending comment
2024-09-02 09:32:55 -07:00
Lee Thomason 38894bfa7f Merge pull request #993 from jengelh/master
Make DocPrinter support DynArrays larger than 2G
2024-09-02 09:29:54 -07:00
sigmarik 780b16b5ae chore: fix typo in the XMLNode::DeepClone description 2024-08-31 19:34:27 +03:00
Jan Engelhardt 04bbc06cd0 Make DocPrinter support DynArrays larger than 2G
If the DynArray within an XMLPrinter object carries 2 gigabytes of
data or more, XMLPrinter::CStrSize returns a truncated result. If a
program casts this back to size_t without thought, sign extension
leads to bad things(tm).

```c++
int main()
{
	tinyxml2::XMLDocument doc;
	doc.InsertEndChild(doc.NewDeclaration());
	auto root = doc.NewElement("root");
	size_t sz = 0x80000002;
	auto blank = new char[sz];
	memset(blank, ' ', sz);
	blank[sz-1]='\0';
	root->SetText(blank);
	doc.InsertEndChild(root);
	tinyxml2::XMLPrinter printer(nullptr);
	doc.Print(&printer);
	std::string_view sv{printer.CStr(), static_cast<size_t>(printer.CStrSize())};
	// sv.size() is way too big, causing overflows on access
	std::string dup(sv); // boom
}
```

Fixes: 2.0.2-873-geb3ab0d
2024-08-14 15:28:42 +02:00
Sergey Smolov 62f6b14e91 fixup
Signed-off-by: Sergey Smolov <smolov@ispras.ru>
2024-08-12 19:22:22 +03:00
Sergey Smolov b25c39aaad fix tinyxml2 namespaces' ending comment
Signed-off-by: Sergey Smolov <smolov@ispras.ru>
2024-08-12 19:16:14 +03:00
Lee Thomason 8a519a556a Merge pull request #990 from jengelh/master
Avoid crashing when SetText is called with a 2GB large string
2024-07-06 12:41:55 -07:00
Lee Thomason c93b6f78d4 Revert "Merge pull request #983 from DiplomInformatikerFranzHoepfinger/feature/fix_32_bit_types"
This reverts commit 8e4bfebad5, reversing
changes made to a0f66fdf71.
2024-07-06 12:28:04 -07:00
Lee Thomason 8e4bfebad5 Merge pull request #983 from DiplomInformatikerFranzHoepfinger/feature/fix_32_bit_types
Update QueryIntValue and QueryUnsignedValue to use int32_t and uint32_t types for better consistency.
2024-07-06 12:00:24 -07:00
Jan Engelhardt eb3ab0df5d Make DynArray support objects larger than 1 gigabyte
The expression ``const int newAllocated = cap * 2;`` easily causes
overflow, as soon as the input is 1.0 GiB. This goes unnoticed because
release builds of tinyxml2 do not have active assertions.

The change in commit 9.0.0-20-g8fd6cc6 did not do anything useful;
the signed multiplication overflow (and thus undefined behavior)
still occurs.

Using ``int`` in this class is really archaic, because it limits the
class to a gigabyte even on 64-bit platforms.

The multiplication overflow check also needs to include sizeof(T),
otherwise you can run into unsigned multiplication overflow (defined,
but undesirable) in the memcpy() call.

testcase:

int main()
{
        tinyxml2::XMLDocument doc;
        doc.InsertEndChild(doc.NewDeclaration());
        auto root = doc.NewElement("root");
        size_t sz = 0x80000001;
        auto blank = new char[sz];
        memset(blank, ' ', sz);
        blank[sz-1]='\0';
        root->SetText(blank);
        doc.InsertEndChild(root);
        tinyxml2::XMLPrinter printer(nullptr);
        doc.Print(&printer);
}
2024-07-01 22:07:51 +02:00
Jan Engelhardt 3a893e5757 Remove extraneous +x bit from source files 2024-07-01 14:14:33 +02:00
Lee Thomason a0f66fdf71 Merge pull request #984 from Blake-Madden/master
Fix typo in comment
2024-06-13 08:29:51 -07:00
Lee Thomason a965e28c4f Merge pull request #978 from AlbertHungGarmin/fix-format-specifier
Fix format specifier mismatch in XMLUtil::ToStr
2024-06-13 08:17:16 -07:00
Blake-Madden 5b04868fee Fix typo in comment 2024-06-01 15:41:57 -04:00
Franz Höpfinger 8df9b25bb9 Update attribute handling to use int32_t and uint32_t types.
The commit changes the attribute handling in the code to utilize int32_t and uint32_t types for better consistency and compatibility.
2024-05-30 20:31:00 +02:00
Franz Höpfinger 53d8ec5573 Update attribute setting functions to use specific integer types
The commit updates attribute setting functions to use int32_t and uint32_t types for better clarity and consistency.
2024-05-30 20:28:46 +02:00
Franz Höpfinger 5e27269c04 Update attribute setting functions to use specific integer types
The commit changes the attribute setting functions in both the .cpp and .h files to use int32_t and uint32_t instead of int and unsigned for better type specificity.
2024-05-30 20:27:26 +02:00
Franz Höpfinger 693052afe4 Update integer types to int32_t and uint32_t for better clarity and consistency. 2024-05-30 20:19:13 +02:00
Franz Höpfinger 42875a9f60 Update data type in ToBool function for better clarity and consistency.
- Change int to int32_t in the ToBool function for improved data type clarity.
2024-05-30 20:16:20 +02:00
Franz Höpfinger afb8fabf58 Update integer parsing to use long type and unsigned parsing to use unsigned long type for better compatibility with different platforms.
Update integer parsing to use long type and unsigned parsing to use unsigned long type for better compatibility with different platforms. Alternatively, use the PRI Macros there.

alternatively use the PRI Macros there.
2024-05-30 20:13:48 +02:00
Franz Höpfinger a151353f3a Update integer to string conversion functions for different data types.
- Changed formatting from %d to %ld for int32_t.
- Changed formatting from %u to %lu for uint32_t.

alternatively use the PRI Macros there.
2024-05-30 20:08:50 +02:00
Franz Höpfinger ef185a8f85 Update PushText functions to use specific integer types
The commit changes the PushText functions in both the .cpp and .h files to utilize int32_t and uint32_t instead of int and unsigned for better type specificity.
2024-05-30 20:05:52 +02:00
Franz Höpfinger 8fed517e5d Update SetText method parameters to use int32_t and uint32_t.
This change updates the SetText method in both the .cpp and .h files to use int32_t and uint32_t types for better consistency and clarity.
2024-05-30 19:53:50 +02:00
Franz Höpfinger e269b2e91f Update QueryIntText and QueryUnsignedText functions to use int32_t and uint32_t types instead of int and unsigned in tinyxml2.cpp and tinyxml2.h. 2024-05-30 19:53:44 +02:00
Franz Höpfinger cd8c1a6322 Update ToStr functions to use int32_t and uint32_t types, and change corresponding function signatures in the header file. Update ToInt and ToUnsigned functions to use int32_t and uint32_t types respectively. 2024-05-30 19:34:59 +02:00
Franz Höpfinger 668fd81256 Update attribute types to int32_t and uint32_t for better consistency and clarity.
Update attribute types to int32_t and uint32_t for better consistency and clarity.

Changed attribute types to int32_t and uint32_t for IntAttribute and UnsignedAttribute methods in both .cpp and .h files.
2024-05-30 19:31:58 +02:00
Franz Höpfinger 095a8ffa42 Update IntValue and UnsignedValue to use int32_t and uint32_t types.
This change ensures consistent integer handling throughout the codebase.
2024-05-30 19:24:09 +02:00
Franz Höpfinger 574c760b7f Update attribute query functions to use int32_t and uint32_t types.
- Changed QueryAttribute parameter type from int* to int32_t*
- Changed QueryAttribute parameter type from unsigned int* to uint32_t*
2024-05-30 19:22:25 +02:00
Franz Höpfinger 5d219c893b Update attribute query functions to use int32_t and uint32_t types.
- Changed QueryIntAttribute parameter type from int* to int32_t*
- Changed QueryUnsignedAttribute parameter type from unsigned int* to uint32_t*
2024-05-30 19:21:27 +02:00
Franz Höpfinger fd26a5ee1f Update QueryIntValue and QueryUnsignedValue to use int32_t and uint32_t types for better consistency. 2024-05-30 19:15:52 +02:00
Albert Hung dded8bb2e9 Fix format specifier mismatch in XMLUtil::ToStr
In the XMLUtil::ToStr( uint64_t v, char* buffer, int bufferSize ) function, the format specifier %llu was used with a signed long long argument. This caused a type mismatch warning. The argument has been changed to unsigned long long to match the format specifier, resolving the warning.
2024-05-15 19:43:55 +08:00
Lee Thomason 312a809224 Merge pull request #976 from leethomason/AlbertHungGarmin-format_error
Albert hung garmin format error
2024-04-20 19:46:41 -07:00
Lee Thomason 0f9c021a44 Merge pull request #973 from davidoakley/fix-android-before-api24
Use fseek/ftell on Android when api level < 24
2024-04-20 19:34:58 -07:00
David Oakley dfc20c5f8f Android SDK<24 doesn’t support fseeko/ftello
Fall back to using fseek/ftell;
This was broken by https://github.com/leethomason/tinyxml2/pull/903/commits/d9fb8d34439be452c18b63713e2e0ae0e6028072
2024-04-08 12:58:12 +01:00
12 changed files with 686 additions and 546 deletions
+14 -14
View File
@@ -6,15 +6,15 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ windows-2019, macos-latest, ubuntu-20.04 ]
os: [ windows-latest, macos-latest, ubuntu-latest ]
cmake: [ 3.15, 3.x ]
include:
- os: windows-2019
- os: windows-latest
static_postfix: _static
tree: tree /F
CXX: cl
- os: ubuntu-20.04
- os: ubuntu-latest
tree: tree
- os: macos-latest
@@ -31,16 +31,16 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
# System set-up
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: ilammy/msvc-dev-cmd@v1
- uses: seanmiddleditch/gha-setup-ninja@master
- uses: jwlawson/actions-setup-cmake@v1.8
- uses: seanmiddleditch/gha-setup-ninja@v4
- uses: jwlawson/actions-setup-cmake@v2
with:
cmake-version: ${{ matrix.cmake }}
# Static Debug
- name: "Static Debug: Configure"
run: cmake -G Ninja -S . -B build-static-dbg -DCMAKE_BUILD_TYPE=Debug "-DCMAKE_DEBUG_POSTFIX=d${{matrix.static_postfix}}"
run: cmake -G Ninja -S . -B build-static-dbg -DCMAKE_BUILD_TYPE=Debug "-DCMAKE_DEBUG_POSTFIX=d${{matrix.static_postfix}}" -DCMAKE_CXX_STANDARD=11 -DCMAKE_CXX_STANDARD_REQUIRED=ON
- name: "Static Debug: Build"
run: cmake --build build-static-dbg
- name: "Static Debug: Test"
@@ -49,7 +49,7 @@ jobs:
# Shared Debug
- name: "Shared Debug: Configure"
run: cmake -G Ninja -S . -B build-shared-dbg -DCMAKE_BUILD_TYPE=Debug -DCMAKE_DEBUG_POSTFIX=d -DBUILD_SHARED_LIBS=ON
run: cmake -G Ninja -S . -B build-shared-dbg -DCMAKE_BUILD_TYPE=Debug -DCMAKE_DEBUG_POSTFIX=d -DBUILD_SHARED_LIBS=ON -DCMAKE_CXX_STANDARD=11 -DCMAKE_CXX_STANDARD_REQUIRED=ON
- name: "Shared Debug: Build"
run: cmake --build build-shared-dbg
- name: "Shared Debug: Test"
@@ -58,7 +58,7 @@ jobs:
# Static Release
- name: "Static Release: Configure"
run: cmake -G Ninja -S . -B build-static-rel -DCMAKE_BUILD_TYPE=Release "-DCMAKE_RELEASE_POSTFIX=${{matrix.static_postfix}}"
run: cmake -G Ninja -S . -B build-static-rel -DCMAKE_BUILD_TYPE=Release "-DCMAKE_RELEASE_POSTFIX=${{matrix.static_postfix}}" -DCMAKE_CXX_STANDARD=11 -DCMAKE_CXX_STANDARD_REQUIRED=ON
- name: "Static Release: Build"
run: cmake --build build-static-rel
- name: "Static Release: Test"
@@ -67,7 +67,7 @@ jobs:
# Shared Release
- name: "Shared Release: Configure"
run: cmake -G Ninja -S . -B build-shared-rel -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON
run: cmake -G Ninja -S . -B build-shared-rel -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DCMAKE_CXX_STANDARD=11 -DCMAKE_CXX_STANDARD_REQUIRED=ON
- name: "Shared Release: Build"
run: cmake --build build-shared-rel
- name: "Shared Release: Test"
@@ -89,23 +89,23 @@ jobs:
run: >-
ctest --build-and-test test test-static-dbg
--build-generator Ninja
--build-options -DCMAKE_BUILD_TYPE=Debug -Dtinyxml2_SHARED_LIBS=NO -DCMAKE_PREFIX_PATH=${{github.workspace}}/install
--build-options -DCMAKE_BUILD_TYPE=Debug -Dtinyxml2_SHARED_LIBS=NO -DCMAKE_PREFIX_PATH=${{github.workspace}}/install -DCMAKE_CXX_STANDARD=11 -DCMAKE_CXX_STANDARD_REQUIRED=ON
--test-command ctest --output-on-failure
- name: "Test find_package: Static Release"
run: >-
ctest --build-and-test test test-static-rel
--build-generator Ninja
--build-options -DCMAKE_BUILD_TYPE=Release -Dtinyxml2_SHARED_LIBS=NO -DCMAKE_PREFIX_PATH=${{github.workspace}}/install
--build-options -DCMAKE_BUILD_TYPE=Release -Dtinyxml2_SHARED_LIBS=NO -DCMAKE_PREFIX_PATH=${{github.workspace}}/install -DCMAKE_CXX_STANDARD=11 -DCMAKE_CXX_STANDARD_REQUIRED=ON
--test-command ctest --output-on-failure
- name: "Test find_package: Shared Debug"
run: >-
ctest --build-and-test test test-shared-dbg
--build-generator Ninja
--build-options -DCMAKE_BUILD_TYPE=Debug -Dtinyxml2_SHARED_LIBS=YES -DCMAKE_PREFIX_PATH=${{github.workspace}}/install
--build-options -DCMAKE_BUILD_TYPE=Debug -Dtinyxml2_SHARED_LIBS=YES -DCMAKE_PREFIX_PATH=${{github.workspace}}/install -DCMAKE_CXX_STANDARD=11 -DCMAKE_CXX_STANDARD_REQUIRED=ON
--test-command ctest --output-on-failure
- name: "Test find_package: Shared Release"
run: >-
ctest --build-and-test test test-shared-rel
--build-generator Ninja
--build-options -DCMAKE_BUILD_TYPE=Release -Dtinyxml2_SHARED_LIBS=YES -DCMAKE_PREFIX_PATH=${{github.workspace}}/install
--build-options -DCMAKE_BUILD_TYPE=Release -Dtinyxml2_SHARED_LIBS=YES -DCMAKE_PREFIX_PATH=${{github.workspace}}/install -DCMAKE_CXX_STANDARD=11 -DCMAKE_CXX_STANDARD_REQUIRED=ON
--test-command ctest --output-on-failure
+15 -11
View File
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.15)
project(tinyxml2 VERSION 10.0.0)
project(tinyxml2 VERSION 11.0.0)
include(CTest)
option(tinyxml2_BUILD_TESTING "Build tests for tinyxml2" "${BUILD_TESTING}")
@@ -22,8 +22,8 @@ set(CMAKE_VISIBILITY_INLINES_HIDDEN YES)
add_library(tinyxml2 tinyxml2.cpp tinyxml2.h)
add_library(tinyxml2::tinyxml2 ALIAS tinyxml2)
# Uncomment the following line to require C++11 (or greater) to use tinyxml2
# target_compile_features(tinyxml2 PUBLIC cxx_std_11)
# Require C++11 (or greater) to use tinyxml2
target_compile_features(tinyxml2 PUBLIC cxx_std_11)
target_include_directories(tinyxml2 PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>")
target_compile_definitions(
@@ -63,7 +63,9 @@ endif ()
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
## Custom locations
## Custom settings
option(tinyxml2_INSTALL_PKGCONFIG "Create and install pkgconfig files" ON)
set(tinyxml2_INSTALL_PKGCONFIGDIR "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
CACHE PATH "Directory for pkgconfig files")
@@ -121,10 +123,12 @@ install(
## pkg-config
configure_file(cmake/tinyxml2.pc.in tinyxml2.pc.gen @ONLY)
file(GENERATE OUTPUT tinyxml2.pc INPUT "${CMAKE_CURRENT_BINARY_DIR}/tinyxml2.pc.gen")
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/tinyxml2.pc"
DESTINATION "${tinyxml2_INSTALL_PKGCONFIGDIR}"
COMPONENT tinyxml2_development
)
if (tinyxml2_INSTALL_PKGCONFIG)
configure_file(cmake/tinyxml2.pc.in tinyxml2.pc.gen @ONLY)
file(GENERATE OUTPUT tinyxml2.pc INPUT "${CMAKE_CURRENT_BINARY_DIR}/tinyxml2.pc.gen")
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/tinyxml2.pc"
DESTINATION "${tinyxml2_INSTALL_PKGCONFIGDIR}"
COMPONENT tinyxml2_development
)
endif ()
+1 -1
View File
@@ -7,7 +7,7 @@
// In HTML5, there are 16 so-called "void" elements. "void elements" NEVER have
// inner content (but they MAY have attributes), and are assumed to be self-closing.
// An example of a self-closig HTML5 element is "<br/>" (line break)
// An example of a self-closing HTML5 element is "<br/>" (line break)
// All other elements are called "non-void" and MUST never self-close.
// Examples: "<div class='lolcats'></div>".
+1 -1
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 = 10.0.0
PROJECT_NUMBER = 11.0.0
# 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
+1 -1
View File
@@ -22,7 +22,7 @@
project(
'tinyxml2',
['cpp'],
version : '10.0.0',
version : '11.0.0',
meson_version : '>= 0.49.0',
)
+127 -110
View File
@@ -1,12 +1,13 @@
TinyXML-2
=========
# TinyXML-2
[![Test](https://github.com/leethomason/tinyxml2/actions/workflows/test.yml/badge.svg)](https://github.com/leethomason/tinyxml2/actions/workflows/test.yml)
TinyXML-2 is a simple, small, efficient, C++ XML parser that can be
easily integrated into other programs.
The master is hosted on github:
It is written in C++ 11 and does not use any Standard Library (std::) features.
The master is hosted on GitHub:
https://github.com/leethomason/tinyxml2
The online HTML version of these docs:
@@ -14,8 +15,7 @@ http://leethomason.github.io/tinyxml2/
Examples are in the "related pages" tab of the HTML docs.
What it does.
-------------
## What it does.
In brief, TinyXML-2 parses an XML document, and builds from that a
Document Object Model (DOM) that can be read, modified, and saved.
@@ -37,7 +37,7 @@ code without creating a document first.
TinyXML-2 is designed to be easy and fast to learn. It is one header and
one cpp file. Simply add these to your project and off you go.
There is an example file - xmltest.cpp - to get you started.
There is an example file - `xmltest.cpp` - to get you started.
TinyXML-2 is released under the ZLib license,
so you can use it in open source or commercial code. The details
@@ -45,10 +45,10 @@ of the license are at the top of every source file.
TinyXML-2 attempts to be a flexible parser, but with truly correct and
compliant XML output. TinyXML-2 should compile on any reasonably C++
compliant system. It does not rely on exceptions, RTTI, or the STL.
compliant system. It does not rely on exceptions, run-time type information,
or the C++ Standard Library.
What it doesn't do.
-------------------
## What it doesn't do.
TinyXML-2 doesn't parse or use DTDs (Document Type Definitions) or XSLs
(eXtensible Stylesheet Language.) There are other parsers out there
@@ -56,10 +56,9 @@ that are much more fully featured. But they are generally bigger and
more difficult to use. If you are working with
browsers or have more complete XML needs, TinyXML-2 is not the parser for you.
TinyXML-1 vs. TinyXML-2
-----------------------
## TinyXML-1 vs. TinyXML-2
TinyXML-2 long been the focus of all development. It is well tested
TinyXML-2 has long been the focus of all development. It is well tested
and should be used instead of TinyXML-1.
TinyXML-2 uses a similar API to TinyXML-1 and the same
@@ -67,10 +66,10 @@ rich test cases. But the implementation of the parser is completely re-written
to make it more appropriate for use in a game. It uses less memory, is faster,
and uses far fewer memory allocations.
TinyXML-2 has no requirement or support for STL.
TinyXML-2 has no dependency on the C++ Standard Library, and does not adapt or use any
of its collection types either.
Features
--------
## Features
### Code Page
@@ -81,17 +80,17 @@ Filenames for loading / saving are passed unchanged to the underlying OS.
### Memory Model
An XMLDocument is a C++ object like any other, that can be on the stack, or
new'd and deleted on the heap.
An `XMLDocument` is a C++ object like any other, that can be on the stack, or
`new`'d and `delete`d on the heap.
However, any sub-node of the Document, XMLElement, XMLText, etc, can only
be created by calling the appropriate XMLDocument::NewElement, NewText, etc.
However, any sub-node of the `XMLDocument`, `XMLElement`, `XMLText`, etc, can only
be created by calling the appropriate `XMLDocument::NewElement`, `XMLDocument::NewText`, etc.
method. Although you have pointers to these objects, they are still owned
by the Document. When the Document is deleted, so are all the nodes it contains.
by the `XMLDocument`. When the `XMLDocument` is `delete`d, so are all the nodes it contains.
### White Space
#### Whitespace Preservation (default, PRESERVE_WHITESPACE)
#### Whitespace Preservation (default, `PRESERVE_WHITESPACE`)
Microsoft has an excellent article on white space: http://msdn.microsoft.com/en-us/library/ms256097.aspx
@@ -103,51 +102,57 @@ line-feed character, as required by the XML spec.
White space in text is preserved. For example:
<element> Hello, World</element>
```xml
<element> Hello, World</element>
```
The leading space before the "Hello" and the double space after the comma are
The leading space before the `"Hello"` and the double space after the comma are
preserved. Line-feeds are preserved, as in this example:
<element> Hello again,
World</element>
```xml
<element> Hello again,
World</element>
```
However, white space between elements is **not** preserved. Although not strictly
compliant, tracking and reporting inter-element space is awkward, and not normally
valuable. TinyXML-2 sees these as the same XML:
<document>
<data>1</data>
<data>2</data>
<data>3</data>
</document>
```xml
<document>
<data>1</data>
<data>2</data>
<data>3</data>
</document>
<document><data>1</data><data>2</data><data>3</data></document>
<document><data>1</data><data>2</data><data>3</data></document>
```
#### Whitespace Collapse (COLLAPSE_WHITESPACE)
#### Whitespace Collapse (`COLLAPSE_WHITESPACE`)
For some applications, it is preferable to collapse whitespace. Collapsing
whitespace gives you "HTML-like" behavior, which is sometimes more suitable
for hand typed documents.
TinyXML-2 supports this with the 'whitespace' parameter to the XMLDocument constructor.
TinyXML-2 supports this with the `whitespace` parameter to the `XMLDocument` constructor.
(The default is to preserve whitespace, as described above.)
However, you may also use COLLAPSE_WHITESPACE, which will:
However, you may also use `COLLAPSE_WHITESPACE`, which will:
* Remove leading and trailing whitespace
* Convert newlines and line-feeds into a space character
* Collapse a run of any number of space characters into a single space character
Note that (currently) there is a performance impact for using COLLAPSE_WHITESPACE.
Note that (currently) there is a performance impact for using `COLLAPSE_WHITESPACE`.
It essentially causes the XML to be parsed twice.
#### Pedantic Whitespace (PEDANTIC_WHITESPACE)
#### Pedantic Whitespace (`PEDANTIC_WHITESPACE`)
For applications that need to know about text nodes that are composed entirely of
whitespace, PEDANTIC_WHITESPACE is available. PEDANTIC_WHITESPACE maintains all the
whilespace between elements.
whitespace, `PEDANTIC_WHITESPACE` is available. `PEDANTIC_WHITESPACE` maintains all the
whitespace between elements.
PEDANTIC_WHITESPACE is a new mode and not as tested as the other whitespace modes.
`PEDANTIC_WHITESPACE` is a new mode and not as tested as the other whitespace modes.
### Error Reporting
@@ -163,22 +168,26 @@ line number information for error messages.
TinyXML-2 recognizes the pre-defined "character entities", meaning special
characters. Namely:
&amp; &
&lt; <
&gt; >
&quot; "
&apos; '
```html
&amp; &
&lt; <
&gt; >
&quot; "
&apos; '
```
These are recognized when the XML document is read, and translated to their
UTF-8 equivalents. For instance, text with the XML of:
Far &amp; Away
```xml
Far &amp; Away
```
will have the Value() of "Far & Away" when queried from the XMLText object,
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 character.
The syntax `&#xA0;` or `&#160;` both refer 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.
@@ -188,21 +197,27 @@ regular code point. The output is correct, but the entity syntax isn't preserved
#### Print to file
You can directly use the convenience function:
XMLDocument doc;
...
doc.SaveFile( "foo.xml" );
```cpp
XMLDocument doc;
// ...
doc.SaveFile("foo.xml");
```
Or the XMLPrinter class:
Or the `XMLPrinter` class:
XMLPrinter printer( fp );
doc.Print( &printer );
```cpp
XMLPrinter printer(fp);
doc.Print(&printer);
```
#### Print to memory
Printing to memory is supported by the XMLPrinter.
Printing to memory is supported by the `XMLPrinter`.
XMLPrinter printer;
doc.Print( &printer );
// printer.CStr() has a const char* to the XML
```cpp
XMLPrinter printer;
doc.Print(&printer);
// printer.CStr() has a const char* to the XML
```
#### Print without an XMLDocument
@@ -210,92 +225,95 @@ When loading, an XML parser is very useful. However, sometimes
when saving, it just gets in the way. The code is often set up
for streaming, and constructing the DOM is just overhead.
The Printer supports the streaming case. The following code
The `XMLPrinter` supports the streaming case. The following code
prints out a trivially simple XML file without ever creating
an XML document.
XMLPrinter printer( fp );
printer.OpenElement( "foo" );
printer.PushAttribute( "foo", "bar" );
printer.CloseElement();
```cpp
XMLPrinter printer(fp);
printer.OpenElement("foo");
printer.PushAttribute("foo", "bar");
printer.CloseElement();
```
Examples
--------
### Examples
#### Load and parse an XML file.
/* ------ Example 1: Load and parse an XML file. ---- */
{
XMLDocument doc;
doc.LoadFile( "dream.xml" );
}
```cpp
/* ------ Example 1: Load and parse an XML file. ---- */
{
XMLDocument doc;
doc.LoadFile("dream.xml");
}
```
#### Lookup information.
/* ------ Example 2: Lookup information. ---- */
{
XMLDocument doc;
doc.LoadFile( "dream.xml" );
```cpp
/* ------ Example 2: Lookup information. ---- */
{
XMLDocument doc;
doc.LoadFile("dream.xml");
// Structure of the XML file:
// - Element "PLAY" the root Element, which is the
// FirstChildElement of the Document
// - - Element "TITLE" child of the root PLAY Element
// - - - Text child of the TITLE Element
// Structure of the XML file:
// - Element "PLAY" the root Element, which is the
// FirstChildElement of the Document
// - - Element "TITLE" child of the root PLAY Element
// - - - Text child of the TITLE Element
// Navigate to the title, using the convenience function,
// with a dangerous lack of error checking.
const char* title = doc.FirstChildElement( "PLAY" )->FirstChildElement( "TITLE" )->GetText();
printf( "Name of play (1): %s\n", title );
// Navigate to the title, using the convenience function,
// with a dangerous lack of error checking.
const char* title = doc.FirstChildElement("PLAY")->FirstChildElement("TITLE")->GetText();
printf("Name of play (1): %s\n", title);
// Text is just another Node to TinyXML-2. The more
// general way to get to the XMLText:
XMLText* textNode = doc.FirstChildElement( "PLAY" )->FirstChildElement( "TITLE" )->FirstChild()->ToText();
title = textNode->Value();
printf( "Name of play (2): %s\n", title );
}
// Text is just another Node to TinyXML-2. The more
// general way to get to the XMLText:
XMLText* textNode = doc.FirstChildElement("PLAY")->FirstChildElement("TITLE")->FirstChild()->ToText();
title = textNode->Value();
printf("Name of play (2): %s\n", title);
}
```
Using and Installing
--------------------
## Using and Installing
There are 2 files in TinyXML-2:
* tinyxml2.cpp
* tinyxml2.h
* `tinyxml2.cpp`
* `tinyxml2.h`
And additionally a test file:
* xmltest.cpp
* `xmltest.cpp`
Generally speaking, the intent is that you simply include the tinyxml2.cpp and
tinyxml2.h files in your project and build with your other source code.
Generally speaking, the intent is that you simply include the `tinyxml2.cpp` and
`tinyxml2.h` files in your project and build with your other source code.
There is also a CMake build included. CMake is the general build for TinyXML-2.
(Additional build systems are costly to maintain, and tend to bit-rot. They are
(Additional build systems are costly to maintain, and tend to become outdated. They are
being removed over time.)
Building TinyXML-2 - Using vcpkg
--------------------------------
### Building TinyXML-2 - Using vcpkg
You can download and install TinyXML-2 using the [vcpkg](https://github.com/Microsoft/vcpkg) dependency manager:
git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.sh
./vcpkg integrate install
./vcpkg install tinyxml2
```sh
git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.sh
./vcpkg integrate install
./vcpkg install tinyxml2
```
The TinyXML-2 port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please [create an issue or pull request](https://github.com/Microsoft/vcpkg) on the vcpkg repository.
Versioning
----------
## Versioning
TinyXML-2 uses semantic versioning. http://semver.org/ Releases are now tagged in github.
TinyXML-2 uses semantic versioning. http://semver.org/ Releases are now tagged in GitHub.
Note that the major version will (probably) change fairly rapidly. API changes are fairly
common.
License
-------
## License
TinyXML-2 is released under the zlib license:
@@ -316,8 +334,7 @@ must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
Contributors
------------
## Contributors
Thanks very much to everyone who sends suggestions, bugs, ideas, and
encouragement. It all helps, and makes this project fun.
Executable → Regular
View File
Executable → Regular
View File
Executable → Regular
View File
Executable → Regular
+231 -234
View File
File diff suppressed because it is too large Load Diff
Executable → Regular
+142 -142
View File
@@ -24,15 +24,12 @@ distribution.
#ifndef TINYXML2_INCLUDED
#define TINYXML2_INCLUDED
#if defined(ANDROID_NDK) || defined(__BORLANDC__) || defined(__QNXNTO__)
#if defined(ANDROID_NDK)
# include <ctype.h>
# include <limits.h>
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# if defined(__PS3__)
# include <stddef.h>
# endif
#else
# include <cctype>
# include <climits>
@@ -40,15 +37,7 @@ distribution.
# include <cstdlib>
# include <cstring>
#endif
#include <stdint.h>
/*
gcc:
g++ -Wall -DTINYXML2_DEBUG tinyxml2.cpp xmltest.cpp -o gccxmltest.exe
Formatting, Artistic Style:
AStyle.exe --style=1tbs --indent-switches --break-closing-brackets --indent-preprocessor tinyxml2.cpp tinyxml2.h
*/
#include <cstdint>
#if defined( _DEBUG ) || defined (__DEBUG__)
# ifndef TINYXML2_DEBUG
@@ -93,14 +82,22 @@ distribution.
#endif
#endif
#if defined(__cplusplus) && __cplusplus >= 201703L
#define TINYXML2_CONSTANT inline constexpr
#elif defined(__cplusplus) && __cplusplus >= 201103L
#define TINYXML2_CONSTANT static constexpr
#else
#define TINYXML2_CONSTANT static const
#endif
/* Versioning, past 1.0.14:
http://semver.org/
*/
static const int TIXML2_MAJOR_VERSION = 10;
static const int TIXML2_MINOR_VERSION = 0;
static const int TIXML2_PATCH_VERSION = 0;
TINYXML2_CONSTANT int TIXML2_MAJOR_VERSION = 11;
TINYXML2_CONSTANT int TIXML2_MINOR_VERSION = 0;
TINYXML2_CONSTANT int TIXML2_PATCH_VERSION = 0;
#define TINYXML2_MAJOR_VERSION 10
#define TINYXML2_MAJOR_VERSION 11
#define TINYXML2_MINOR_VERSION 0
#define TINYXML2_PATCH_VERSION 0
@@ -109,7 +106,7 @@ static const int TIXML2_PATCH_VERSION = 0;
// system, and the capacity of the stack. On the other hand, it's a trivial
// attack that can result from ill, malicious, or even correctly formed XML,
// so there needs to be a limit in place.
static const int TINYXML2_MAX_ELEMENT_DEPTH = 500;
TINYXML2_CONSTANT int TINYXML2_MAX_ELEMENT_DEPTH = 500;
namespace tinyxml2
{
@@ -146,7 +143,7 @@ public:
COMMENT = NEEDS_NEWLINE_NORMALIZATION
};
StrPair() : _flags( 0 ), _start( 0 ), _end( 0 ) {}
StrPair() : _flags( 0 ), _start( nullptr ), _end( nullptr ) {}
~StrPair();
void Set( char* start, char* end, int flags ) {
@@ -189,8 +186,8 @@ private:
char* _start;
char* _end;
StrPair( const StrPair& other ); // not supported
void operator=( const StrPair& other ); // not supported, use TransferTo()
StrPair( const StrPair& ) = delete;
StrPair& operator=( const StrPair& ) = delete;
};
@@ -199,7 +196,7 @@ 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 INITIAL_SIZE>
template <class T, size_t INITIAL_SIZE>
class DynArray
{
public:
@@ -227,9 +224,8 @@ public:
++_size;
}
T* PushArr( int count ) {
TIXMLASSERT( count >= 0 );
TIXMLASSERT( _size <= INT_MAX - count );
T* PushArr( size_t count ) {
TIXMLASSERT( _size <= SIZE_MAX - count );
EnsureCapacity( _size+count );
T* ret = &_mem[_size];
_size += count;
@@ -242,7 +238,7 @@ public:
return _mem[_size];
}
void PopArr( int count ) {
void PopArr( size_t count ) {
TIXMLASSERT( _size >= count );
_size -= count;
}
@@ -251,13 +247,13 @@ public:
return _size == 0;
}
T& operator[](int i) {
TIXMLASSERT( i>= 0 && i < _size );
T& operator[](size_t i) {
TIXMLASSERT( i < _size );
return _mem[i];
}
const T& operator[](int i) const {
TIXMLASSERT( i>= 0 && i < _size );
const T& operator[](size_t i) const {
TIXMLASSERT( i < _size );
return _mem[i];
}
@@ -266,18 +262,17 @@ public:
return _mem[ _size - 1];
}
int Size() const {
TIXMLASSERT( _size >= 0 );
size_t Size() const {
return _size;
}
int Capacity() const {
size_t Capacity() const {
TIXMLASSERT( _allocated >= INITIAL_SIZE );
return _allocated;
}
void SwapRemove(int i) {
TIXMLASSERT(i >= 0 && i < _size);
void SwapRemove(size_t i) {
TIXMLASSERT(i < _size);
TIXMLASSERT(_size > 0);
_mem[i] = _mem[_size - 1];
--_size;
@@ -294,17 +289,17 @@ public:
}
private:
DynArray( const DynArray& ); // not supported
void operator=( const DynArray& ); // not supported
DynArray( const DynArray& ) = delete;
DynArray& operator=( const DynArray& ) = delete;
void EnsureCapacity( int cap ) {
void EnsureCapacity( size_t cap ) {
TIXMLASSERT( cap > 0 );
if ( cap > _allocated ) {
TIXMLASSERT( cap <= INT_MAX / 2 );
const int newAllocated = cap * 2;
T* newMem = new T[static_cast<unsigned int>(newAllocated)];
TIXMLASSERT( cap <= SIZE_MAX / 2 / sizeof(T));
const size_t newAllocated = cap * 2;
T* newMem = new T[newAllocated];
TIXMLASSERT( newAllocated >= _size );
memcpy( newMem, _mem, sizeof(T)*static_cast<size_t>(_size) ); // warning: not using constructors, only works for PODs
memcpy( newMem, _mem, sizeof(T) * _size ); // warning: not using constructors, only works for PODs
if ( _mem != _pool ) {
delete [] _mem;
}
@@ -314,9 +309,9 @@ private:
}
T* _mem;
T _pool[static_cast<size_t>(INITIAL_SIZE)];
int _allocated; // objects allocated
int _size; // number objects in use
T _pool[INITIAL_SIZE];
size_t _allocated; // objects allocated
size_t _size; // number objects in use
};
@@ -330,7 +325,7 @@ public:
MemPool() {}
virtual ~MemPool() {}
virtual int ItemSize() const = 0;
virtual size_t ItemSize() const = 0;
virtual void* Alloc() = 0;
virtual void Free( void* ) = 0;
virtual void SetTracked() = 0;
@@ -340,11 +335,11 @@ public:
/*
Template child class to create pools of the correct type.
*/
template< int ITEM_SIZE >
template< size_t ITEM_SIZE >
class MemPoolT : public MemPool
{
public:
MemPoolT() : _blockPtrs(), _root(0), _currentAllocs(0), _nAllocs(0), _maxAllocs(0), _nUntracked(0) {}
MemPoolT() : _blockPtrs(), _root(nullptr), _currentAllocs(0), _nAllocs(0), _maxAllocs(0), _nUntracked(0) {}
~MemPoolT() {
MemPoolT< ITEM_SIZE >::Clear();
}
@@ -355,17 +350,17 @@ public:
Block* lastBlock = _blockPtrs.Pop();
delete lastBlock;
}
_root = 0;
_root = nullptr;
_currentAllocs = 0;
_nAllocs = 0;
_maxAllocs = 0;
_nUntracked = 0;
}
virtual int ItemSize() const override{
virtual size_t ItemSize() const override {
return ITEM_SIZE;
}
int CurrentAllocs() const {
size_t CurrentAllocs() const {
return _currentAllocs;
}
@@ -376,14 +371,14 @@ public:
_blockPtrs.Push( block );
Item* blockItems = block->items;
for( int i = 0; i < ITEMS_PER_BLOCK - 1; ++i ) {
for( size_t i = 0; i < ITEMS_PER_BLOCK - 1; ++i ) {
blockItems[i].next = &(blockItems[i + 1]);
}
blockItems[ITEMS_PER_BLOCK - 1].next = 0;
blockItems[ITEMS_PER_BLOCK - 1].next = nullptr;
_root = blockItems;
}
Item* const result = _root;
TIXMLASSERT( result != 0 );
TIXMLASSERT( result != nullptr );
_root = _root->next;
++_currentAllocs;
@@ -417,7 +412,7 @@ public:
--_nUntracked;
}
int Untracked() const {
size_t Untracked() const {
return _nUntracked;
}
@@ -435,8 +430,8 @@ public:
enum { ITEMS_PER_BLOCK = (4 * 1024) / ITEM_SIZE };
private:
MemPoolT( const MemPoolT& ); // not supported
void operator=( const MemPoolT& ); // not supported
MemPoolT( const MemPoolT& ) = delete;
MemPoolT& operator=( const MemPoolT& ) = delete;
union Item {
Item* next;
@@ -448,10 +443,10 @@ private:
DynArray< Block*, 10 > _blockPtrs;
Item* _root;
int _currentAllocs;
int _nAllocs;
int _maxAllocs;
int _nUntracked;
size_t _currentAllocs;
size_t _nAllocs;
size_t _maxAllocs;
size_t _nUntracked;
};
@@ -687,46 +682,46 @@ public:
/// Safely cast to an Element, or null.
virtual XMLElement* ToElement() {
return 0;
return nullptr;
}
/// Safely cast to Text, or null.
virtual XMLText* ToText() {
return 0;
return nullptr;
}
/// Safely cast to a Comment, or null.
virtual XMLComment* ToComment() {
return 0;
return nullptr;
}
/// Safely cast to a Document, or null.
virtual XMLDocument* ToDocument() {
return 0;
return nullptr;
}
/// Safely cast to a Declaration, or null.
virtual XMLDeclaration* ToDeclaration() {
return 0;
return nullptr;
}
/// Safely cast to an Unknown, or null.
virtual XMLUnknown* ToUnknown() {
return 0;
return nullptr;
}
virtual const XMLElement* ToElement() const {
return 0;
return nullptr;
}
virtual const XMLText* ToText() const {
return 0;
return nullptr;
}
virtual const XMLComment* ToComment() const {
return 0;
return nullptr;
}
virtual const XMLDocument* ToDocument() const {
return 0;
return nullptr;
}
virtual const XMLDeclaration* ToDeclaration() const {
return 0;
return nullptr;
}
virtual const XMLUnknown* ToUnknown() const {
return 0;
return nullptr;
}
// ChildElementCount was originally suggested by msteiger on the sourceforge page for TinyXML and modified by KB1SPH for TinyXML-2.
@@ -780,9 +775,9 @@ public:
/** Get the first child element, or optionally the first child
element with the specified name.
*/
const XMLElement* FirstChildElement( const char* name = 0 ) const;
const XMLElement* FirstChildElement( const char* name = nullptr ) const;
XMLElement* FirstChildElement( const char* name = 0 ) {
XMLElement* FirstChildElement( const char* name = nullptr ) {
return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->FirstChildElement( name ));
}
@@ -798,9 +793,9 @@ public:
/** Get the last child element or optionally the last child
element with the specified name.
*/
const XMLElement* LastChildElement( const char* name = 0 ) const;
const XMLElement* LastChildElement( const char* name = nullptr ) const;
XMLElement* LastChildElement( const char* name = 0 ) {
XMLElement* LastChildElement( const char* name = nullptr ) {
return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->LastChildElement(name) );
}
@@ -814,9 +809,9 @@ public:
}
/// Get the previous (left) sibling element of this node, with an optionally supplied name.
const XMLElement* PreviousSiblingElement( const char* name = 0 ) const ;
const XMLElement* PreviousSiblingElement( const char* name = nullptr ) const ;
XMLElement* PreviousSiblingElement( const char* name = 0 ) {
XMLElement* PreviousSiblingElement( const char* name = nullptr ) {
return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->PreviousSiblingElement( name ) );
}
@@ -830,9 +825,9 @@ public:
}
/// Get the next (right) sibling element of this node, with an optionally supplied name.
const XMLElement* NextSiblingElement( const char* name = 0 ) const;
const XMLElement* NextSiblingElement( const char* name = nullptr ) const;
XMLElement* NextSiblingElement( const char* name = 0 ) {
XMLElement* NextSiblingElement( const char* name = nullptr ) {
return const_cast<XMLElement*>(const_cast<const XMLNode*>(this)->NextSiblingElement( name ) );
}
@@ -892,7 +887,7 @@ public:
If the 'target' is null, then the nodes will
be allocated in the current document. If 'target'
is specified, the memory will be allocated is the
is specified, the memory will be allocated in the
specified XMLDocument.
NOTE: This is probably not the correct tool to
@@ -974,8 +969,8 @@ private:
void InsertChildPreamble( XMLNode* insertThis ) const;
const XMLElement* ToElementWithName( const char* name ) const;
XMLNode( const XMLNode& ); // not supported
XMLNode& operator=( const XMLNode& ); // not supported
XMLNode( const XMLNode& ) = delete;
XMLNode& operator=( const XMLNode& ) = delete;
};
@@ -1025,8 +1020,8 @@ protected:
private:
bool _isCData;
XMLText( const XMLText& ); // not supported
XMLText& operator=( const XMLText& ); // not supported
XMLText( const XMLText& ) = delete;
XMLText& operator=( const XMLText& ) = delete;
};
@@ -1054,8 +1049,8 @@ protected:
char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr) override;
private:
XMLComment( const XMLComment& ); // not supported
XMLComment& operator=( const XMLComment& ); // not supported
XMLComment( const XMLComment& ) = delete;
XMLComment& operator=( const XMLComment& ) = delete;
};
@@ -1093,8 +1088,8 @@ protected:
char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ) override;
private:
XMLDeclaration( const XMLDeclaration& ); // not supported
XMLDeclaration& operator=( const XMLDeclaration& ); // not supported
XMLDeclaration( const XMLDeclaration& ) = delete;
XMLDeclaration& operator=( const XMLDeclaration& ) = delete;
};
@@ -1128,8 +1123,8 @@ protected:
char* ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr ) override;
private:
XMLUnknown( const XMLUnknown& ); // not supported
XMLUnknown& operator=( const XMLUnknown& ); // not supported
XMLUnknown( const XMLUnknown& ) = delete;
XMLUnknown& operator=( const XMLUnknown& ) = delete;
};
@@ -1243,11 +1238,11 @@ public:
private:
enum { BUF_SIZE = 200 };
XMLAttribute() : _name(), _value(),_parseLineNum( 0 ), _next( 0 ), _memPool( 0 ) {}
XMLAttribute() : _name(), _value(),_parseLineNum( 0 ), _next( nullptr ), _memPool( nullptr ) {}
virtual ~XMLAttribute() {}
XMLAttribute( const XMLAttribute& ); // not supported
void operator=( const XMLAttribute& ); // not supported
XMLAttribute( const XMLAttribute& ) = delete;
XMLAttribute& operator=( const XMLAttribute& ) = delete;
void SetName( const char* name );
char* ParseDeep( char* p, bool processEntities, int* curLineNumPtr );
@@ -1308,7 +1303,7 @@ public:
}
@endverbatim
*/
const char* Attribute( const char* name, const char* value=0 ) const;
const char* Attribute( const char* name, const char* value=nullptr ) const;
/** Given an attribute name, IntAttribute() returns the value
of the attribute interpreted as an integer. The default
@@ -1688,8 +1683,8 @@ protected:
private:
XMLElement( XMLDocument* doc );
virtual ~XMLElement();
XMLElement( const XMLElement& ); // not supported
void operator=( const XMLElement& ); // not supported
XMLElement( const XMLElement& ) = delete;
XMLElement& operator=( const XMLElement& ) = delete;
XMLAttribute* FindOrCreateAttribute( const char* name );
char* ParseAttributes( char* p, int* curLineNumPtr );
@@ -1832,7 +1827,7 @@ public:
// printer.CStr() has a const char* to the XML
@endverbatim
*/
void Print( XMLPrinter* streamer=0 ) const;
void Print( XMLPrinter* streamer=nullptr ) const;
virtual bool Accept( XMLVisitor* visitor ) const override;
/**
@@ -1864,7 +1859,7 @@ public:
<?xml version="1.0" encoding="UTF-8"?>
@endverbatim
*/
XMLDeclaration* NewDeclaration( const char* text=0 );
XMLDeclaration* NewDeclaration( const char* text=nullptr );
/**
Create a new Unknown associated with
this Document. The memory for the object
@@ -1932,8 +1927,8 @@ public:
}
private:
XMLDocument( const XMLDocument& ); // not supported
void operator=( const XMLDocument& ); // not supported
XMLDocument( const XMLDocument& ) = delete;
XMLDocument& operator=( const XMLDocument& ) = delete;
bool _writeBOM;
bool _processEntities;
@@ -1981,11 +1976,11 @@ private:
void PushDepth();
void PopDepth();
template<class NodeType, int PoolElementSize>
template<class NodeType, size_t PoolElementSize>
NodeType* CreateUnlinkedNode( MemPoolT<PoolElementSize>& pool );
};
template<class NodeType, int PoolElementSize>
template<class NodeType, size_t PoolElementSize>
inline NodeType* XMLDocument::CreateUnlinkedNode( MemPoolT<PoolElementSize>& pool )
{
TIXMLASSERT( sizeof( NodeType ) == PoolElementSize );
@@ -2073,35 +2068,35 @@ public:
/// Get the first child of this handle.
XMLHandle FirstChild() {
return XMLHandle( _node ? _node->FirstChild() : 0 );
return XMLHandle( _node ? _node->FirstChild() : nullptr );
}
/// Get the first child element of this handle.
XMLHandle FirstChildElement( const char* name = 0 ) {
return XMLHandle( _node ? _node->FirstChildElement( name ) : 0 );
XMLHandle FirstChildElement( const char* name = nullptr ) {
return XMLHandle( _node ? _node->FirstChildElement( name ) : nullptr );
}
/// Get the last child of this handle.
XMLHandle LastChild() {
return XMLHandle( _node ? _node->LastChild() : 0 );
return XMLHandle( _node ? _node->LastChild() : nullptr );
}
/// Get the last child element of this handle.
XMLHandle LastChildElement( const char* name = 0 ) {
return XMLHandle( _node ? _node->LastChildElement( name ) : 0 );
XMLHandle LastChildElement( const char* name = nullptr ) {
return XMLHandle( _node ? _node->LastChildElement( name ) : nullptr );
}
/// Get the previous sibling of this handle.
XMLHandle PreviousSibling() {
return XMLHandle( _node ? _node->PreviousSibling() : 0 );
return XMLHandle( _node ? _node->PreviousSibling() : nullptr );
}
/// Get the previous sibling element of this handle.
XMLHandle PreviousSiblingElement( const char* name = 0 ) {
return XMLHandle( _node ? _node->PreviousSiblingElement( name ) : 0 );
XMLHandle PreviousSiblingElement( const char* name = nullptr ) {
return XMLHandle( _node ? _node->PreviousSiblingElement( name ) : nullptr );
}
/// Get the next sibling of this handle.
XMLHandle NextSibling() {
return XMLHandle( _node ? _node->NextSibling() : 0 );
return XMLHandle( _node ? _node->NextSibling() : nullptr );
}
/// Get the next sibling element of this handle.
XMLHandle NextSiblingElement( const char* name = 0 ) {
return XMLHandle( _node ? _node->NextSiblingElement( name ) : 0 );
XMLHandle NextSiblingElement( const char* name = nullptr ) {
return XMLHandle( _node ? _node->NextSiblingElement( name ) : nullptr );
}
/// Safe cast to XMLNode. This can return null.
@@ -2110,19 +2105,19 @@ public:
}
/// Safe cast to XMLElement. This can return null.
XMLElement* ToElement() {
return ( _node ? _node->ToElement() : 0 );
return ( _node ? _node->ToElement() : nullptr );
}
/// Safe cast to XMLText. This can return null.
XMLText* ToText() {
return ( _node ? _node->ToText() : 0 );
return ( _node ? _node->ToText() : nullptr );
}
/// Safe cast to XMLUnknown. This can return null.
XMLUnknown* ToUnknown() {
return ( _node ? _node->ToUnknown() : 0 );
return ( _node ? _node->ToUnknown() : nullptr );
}
/// Safe cast to XMLDeclaration. This can return null.
XMLDeclaration* ToDeclaration() {
return ( _node ? _node->ToDeclaration() : 0 );
return ( _node ? _node->ToDeclaration() : nullptr );
}
private:
@@ -2150,28 +2145,28 @@ public:
}
const XMLConstHandle FirstChild() const {
return XMLConstHandle( _node ? _node->FirstChild() : 0 );
return XMLConstHandle( _node ? _node->FirstChild() : nullptr );
}
const XMLConstHandle FirstChildElement( const char* name = 0 ) const {
return XMLConstHandle( _node ? _node->FirstChildElement( name ) : 0 );
const XMLConstHandle FirstChildElement( const char* name = nullptr ) const {
return XMLConstHandle( _node ? _node->FirstChildElement( name ) : nullptr );
}
const XMLConstHandle LastChild() const {
return XMLConstHandle( _node ? _node->LastChild() : 0 );
return XMLConstHandle( _node ? _node->LastChild() : nullptr );
}
const XMLConstHandle LastChildElement( const char* name = 0 ) const {
return XMLConstHandle( _node ? _node->LastChildElement( name ) : 0 );
const XMLConstHandle LastChildElement( const char* name = nullptr ) const {
return XMLConstHandle( _node ? _node->LastChildElement( name ) : nullptr );
}
const XMLConstHandle PreviousSibling() const {
return XMLConstHandle( _node ? _node->PreviousSibling() : 0 );
return XMLConstHandle( _node ? _node->PreviousSibling() : nullptr );
}
const XMLConstHandle PreviousSiblingElement( const char* name = 0 ) const {
return XMLConstHandle( _node ? _node->PreviousSiblingElement( name ) : 0 );
const XMLConstHandle PreviousSiblingElement( const char* name = nullptr ) const {
return XMLConstHandle( _node ? _node->PreviousSiblingElement( name ) : nullptr );
}
const XMLConstHandle NextSibling() const {
return XMLConstHandle( _node ? _node->NextSibling() : 0 );
return XMLConstHandle( _node ? _node->NextSibling() : nullptr );
}
const XMLConstHandle NextSiblingElement( const char* name = 0 ) const {
return XMLConstHandle( _node ? _node->NextSiblingElement( name ) : 0 );
const XMLConstHandle NextSiblingElement( const char* name = nullptr ) const {
return XMLConstHandle( _node ? _node->NextSiblingElement( name ) : nullptr );
}
@@ -2179,16 +2174,16 @@ public:
return _node;
}
const XMLElement* ToElement() const {
return ( _node ? _node->ToElement() : 0 );
return ( _node ? _node->ToElement() : nullptr );
}
const XMLText* ToText() const {
return ( _node ? _node->ToText() : 0 );
return ( _node ? _node->ToText() : nullptr );
}
const XMLUnknown* ToUnknown() const {
return ( _node ? _node->ToUnknown() : 0 );
return ( _node ? _node->ToUnknown() : nullptr );
}
const XMLDeclaration* ToDeclaration() const {
return ( _node ? _node->ToDeclaration() : 0 );
return ( _node ? _node->ToDeclaration() : nullptr );
}
private:
@@ -2241,13 +2236,18 @@ private:
class TINYXML2_LIB XMLPrinter : public XMLVisitor
{
public:
enum EscapeAposCharsInAttributes {
ESCAPE_APOS_CHARS_IN_ATTRIBUTES,
DONT_ESCAPE_APOS_CHARS_IN_ATTRIBUTES
};
/** Construct the printer. If the FILE* is specified,
this will print to the FILE. Else it will print
to memory, and the result is available in CStr().
If 'compact' is set to true, then output is created
with only required whitespace and newlines.
*/
XMLPrinter( FILE* file=0, bool compact = false, int depth = 0 );
XMLPrinter( FILE* file=nullptr, bool compact = false, int depth = 0, EscapeAposCharsInAttributes aposInAttributes = ESCAPE_APOS_CHARS_IN_ATTRIBUTES );
virtual ~XMLPrinter() {}
/** If streaming, write the BOM and declaration. */
@@ -2315,7 +2315,7 @@ public:
of the XML file in memory. (Note the size returned
includes the terminating null.)
*/
int CStrSize() const {
size_t CStrSize() const {
return _buffer.Size();
}
/**
@@ -2369,13 +2369,13 @@ private:
DynArray< char, 20 > _buffer;
// Prohibit cloning, intentionally not implemented
XMLPrinter( const XMLPrinter& );
XMLPrinter& operator=( const XMLPrinter& );
// Prohibit cloning
XMLPrinter( const XMLPrinter& ) = delete;
XMLPrinter& operator=( const XMLPrinter& ) = delete;
};
} // tinyxml2
} // namespace tinyxml2
#if defined(_MSC_VER)
# pragma warning(pop)
Executable → Regular
+154 -32
View File
@@ -45,13 +45,15 @@ bool XMLTest (const char* testString, const char* expected, const char* found, b
printf (" %s\n", testString);
}
else {
const char* expectedStr = expected ? expected : "(null)";
const char* foundStr = found ? found : "(null)";
if ( extraNL ) {
printf( " %s\n", testString );
printf( "%s\n", expected );
printf( "%s\n", found );
printf( "%s\n", expectedStr );
printf( "%s\n", foundStr );
}
else {
printf (" %s [%s][%s]\n", testString, expected, found);
printf (" %s [%s][%s]\n", testString, expectedStr, foundStr);
}
}
@@ -324,9 +326,9 @@ int main( int argc, const char ** argv )
printf( "Test file '%s' loaded. ErrorID=%d\n", argv[1], errorID );
if ( !errorID ) {
printf( "Load time=%u\n", (unsigned)(loadTime - startTime) );
printf( "Delete time=%u\n", (unsigned)(deleteTime - loadTime) );
printf( "Total time=%u\n", (unsigned)(deleteTime - startTime) );
printf( "Load time=%u\n", static_cast<unsigned>(loadTime - startTime) );
printf( "Delete time=%u\n", static_cast<unsigned>(deleteTime - loadTime) );
printf( "Total time=%u\n", static_cast<unsigned>(deleteTime - startTime) );
}
exit(0);
}
@@ -595,8 +597,8 @@ int main( int argc, const char ** argv )
result = ele->QueryDoubleAttribute( "attr0", &dVal );
XMLTest( "Query attribute: int as double", XML_SUCCESS, result);
XMLTest( "Query attribute: int as double", 1, (int)dVal );
XMLTest( "Query attribute: int as double", 1, (int)ele->DoubleAttribute("attr0"));
XMLTest( "Query attribute: int as double", 1, static_cast<int>(dVal) );
XMLTest( "Query attribute: int as double", 1, static_cast<int>(ele->DoubleAttribute("attr0")));
result = ele->QueryDoubleAttribute( "attr1", &dVal );
XMLTest( "Query attribute: double as double", XML_SUCCESS, result);
@@ -648,17 +650,17 @@ int main( int argc, const char ** argv )
{
XMLError queryResult = ele->QueryAttribute( "int", &iVal2 );
XMLTest( "Query int attribute generic", (int)XML_SUCCESS, queryResult);
XMLTest( "Query int attribute generic", static_cast<int>(XML_SUCCESS), queryResult);
}
{
XMLError queryResult = ele->QueryAttribute( "double", &dVal2 );
XMLTest( "Query double attribute generic", (int)XML_SUCCESS, queryResult);
XMLTest( "Query double attribute generic", static_cast<int>(XML_SUCCESS), queryResult);
}
XMLTest( "Attribute match test", "strValue", ele->Attribute( "str", "strValue" ) );
XMLTest( "Attribute round trip. c-string.", "strValue", cStr );
XMLTest( "Attribute round trip. int.", 1, iVal );
XMLTest( "Attribute round trip. double.", -1, (int)dVal );
XMLTest( "Attribute round trip. double.", -1, static_cast<int>(dVal) );
XMLTest( "Alternate query", true, iVal == iVal2 );
XMLTest( "Alternate query", true, dVal == dVal2 );
XMLTest( "Alternate query", true, iVal == ele->IntAttribute("int") );
@@ -675,7 +677,7 @@ int main( int argc, const char ** argv )
const unsigned char correctValue[] = { 0xd1U, 0x86U, 0xd0U, 0xb5U, 0xd0U, 0xbdU, 0xd0U, 0xbdU,
0xd0U, 0xbeU, 0xd1U, 0x81U, 0xd1U, 0x82U, 0xd1U, 0x8cU, 0 };
XMLTest( "UTF-8: Russian value.", (const char*)correctValue, element->Attribute( "value" ) );
XMLTest( "UTF-8: Russian value.", reinterpret_cast<const char*>(correctValue), element->Attribute( "value" ) );
const unsigned char russianElementName[] = { 0xd0U, 0xa0U, 0xd1U, 0x83U,
0xd1U, 0x81U, 0xd1U, 0x81U,
@@ -683,7 +685,7 @@ int main( int argc, const char ** argv )
0xd0U, 0xb9U, 0 };
const char russianText[] = "<\xD0\xB8\xD0\xBC\xD0\xB5\xD0\xB5\xD1\x82>";
XMLText* text = doc.FirstChildElement( "document" )->FirstChildElement( (const char*) russianElementName )->FirstChild()->ToText();
XMLText* text = doc.FirstChildElement( "document" )->FirstChildElement( reinterpret_cast<const char*>(russianElementName) )->FirstChild()->ToText();
XMLTest( "UTF-8: Browsing russian element name.",
russianText,
text->Value() );
@@ -824,7 +826,7 @@ int main( int argc, const char ** argv )
{
int v = 0;
XMLError queryResult = element->QueryAttribute("attrib", &v);
XMLTest("Attribute: int", (int)XML_SUCCESS, queryResult, true);
XMLTest("Attribute: int", static_cast<int>(XML_SUCCESS), queryResult, true);
XMLTest("Attribute: int", -100, v, true);
}
XMLTest("Attribute: int", -100, element->IntAttribute("attrib"), true);
@@ -840,7 +842,7 @@ int main( int argc, const char ** argv )
{
unsigned v = 0;
XMLError queryResult = element->QueryAttribute("attrib", &v);
XMLTest("Attribute: unsigned", (int)XML_SUCCESS, queryResult, true);
XMLTest("Attribute: unsigned", static_cast<int>(XML_SUCCESS), queryResult, true);
XMLTest("Attribute: unsigned", unsigned(100), v, true);
}
{
@@ -864,7 +866,7 @@ int main( int argc, const char ** argv )
{
int64_t v = 0;
XMLError queryResult = element->QueryAttribute("attrib", &v);
XMLTest("Attribute: int64_t", (int)XML_SUCCESS, queryResult, true);
XMLTest("Attribute: int64_t", static_cast<int>(XML_SUCCESS), queryResult, true);
XMLTest("Attribute: int64_t", BIG, v, true);
}
XMLTest("Attribute: int64_t", BIG, element->Int64Attribute("attrib"), true);
@@ -880,7 +882,7 @@ int main( int argc, const char ** argv )
{
uint64_t v = 0;
XMLError queryResult = element->QueryAttribute("attrib", &v);
XMLTest("Attribute: uint64_t", (int)XML_SUCCESS, queryResult, true);
XMLTest("Attribute: uint64_t", static_cast<int>(XML_SUCCESS), queryResult, true);
XMLTest("Attribute: uint64_t", BIG_POS, v, true);
}
XMLTest("Attribute: uint64_t", BIG_POS, element->Unsigned64Attribute("attrib"), true);
@@ -896,7 +898,7 @@ int main( int argc, const char ** argv )
{
bool v = false;
XMLError queryResult = element->QueryAttribute("attrib", &v);
XMLTest("Attribute: bool", (int)XML_SUCCESS, queryResult, true);
XMLTest("Attribute: bool", static_cast<int>(XML_SUCCESS), queryResult, true);
XMLTest("Attribute: bool", true, v, true);
}
XMLTest("Attribute: bool", true, element->BoolAttribute("attrib"), true);
@@ -924,7 +926,7 @@ int main( int argc, const char ** argv )
{
double v = 0;
XMLError queryResult = element->QueryAttribute("attrib", &v);
XMLTest("Attribute: bool", (int)XML_SUCCESS, queryResult, true);
XMLTest("Attribute: bool", static_cast<int>(XML_SUCCESS), queryResult, true);
XMLTest("Attribute: double", 100.0, v, true);
}
XMLTest("Attribute: double", 100.0, element->DoubleAttribute("attrib"), true);
@@ -940,7 +942,7 @@ int main( int argc, const char ** argv )
{
float v = 0;
XMLError queryResult = element->QueryAttribute("attrib", &v);
XMLTest("Attribute: float", (int)XML_SUCCESS, queryResult, true);
XMLTest("Attribute: float", static_cast<int>(XML_SUCCESS), queryResult, true);
XMLTest("Attribute: float", 100.0f, v, true);
}
XMLTest("Attribute: float", 100.0f, element->FloatAttribute("attrib"), true);
@@ -1005,7 +1007,7 @@ int main( int argc, const char ** argv )
FILE* fp1 = fopen("resources/out/printer_1.xml", "w");
XMLPrinter printer(fp1);
printer.PushDeclaration("version = '1.0' enconding = 'utf-8'");
printer.PushDeclaration("version = '1.0' encoding = 'utf-8'");
printer.OpenElement("foo");
printer.PushAttribute("attrib-text", "text");
@@ -1068,15 +1070,15 @@ int main( int argc, const char ** argv )
unsigned unsigned_value;
unsigned_value = root->FirstChildElement("unsigned")->UnsignedText();
XMLTest("PushText( unsigned value ) test", (unsigned)12, unsigned_value);
XMLTest("PushText( unsigned value ) test", static_cast<unsigned>(12), unsigned_value);
int64_t int64_t_value;
int64_t_value = root->FirstChildElement("int64_t")->Int64Text();
XMLTest("PushText( int64_t value ) test", (int64_t) 13, int64_t_value);
XMLTest("PushText( int64_t value ) test", static_cast<int64_t>(13), int64_t_value);
uint64_t uint64_t_value;
uint64_t_value = root->FirstChildElement("uint64_t")->Unsigned64Text();
XMLTest("PushText( uint64_t value ) test", (uint64_t) 14, uint64_t_value);
XMLTest("PushText( uint64_t value ) test", static_cast<uint64_t>(14), uint64_t_value);
float float_value;
float_value = root->FirstChildElement("float")->FloatText();
@@ -1096,7 +1098,7 @@ int main( int argc, const char ** argv )
const XMLDeclaration* declaration = cdoc.FirstChild()->ToDeclaration();
const char* declaration_value = declaration->Value();
XMLTest("PushDeclaration() test", "version = '1.0' enconding = 'utf-8'", declaration_value);
XMLTest("PushDeclaration() test", "version = '1.0' encoding = 'utf-8'", declaration_value);
}
}
@@ -1397,7 +1399,7 @@ int main( int argc, const char ** argv )
buf[61] = 0;
XMLDocument doc;
doc.Parse( (const char*)buf);
doc.Parse( reinterpret_cast<const char*>(buf) );
XMLTest( "Broken CDATA", true, doc.Error() );
}
@@ -1642,7 +1644,7 @@ int main( int argc, const char ** argv )
static const char* result = "\xef\xbb\xbf<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
XMLTest( "BOM and default declaration", result, printer.CStr(), false );
XMLTest( "CStrSize", 42, printer.CStrSize(), false );
XMLTest( "CStrSize", true, printer.CStrSize() == 42, false );
}
{
const char* xml = "<ipxml ws='1'><info bla=' /></ipxml>";
@@ -1753,7 +1755,7 @@ int main( int argc, const char ** argv )
unsigned unsignedValue = 0;
XMLError queryResult = pointElement->FirstChildElement( "y" )->QueryUnsignedText( &unsignedValue );
XMLTest( "QueryUnsignedText result", XML_SUCCESS, queryResult, false );
XMLTest( "QueryUnsignedText", (unsigned)1, unsignedValue, false );
XMLTest( "QueryUnsignedText", static_cast<unsigned>(1), unsignedValue, false );
}
{
@@ -2025,7 +2027,13 @@ int main( int argc, const char ** argv )
XMLTest("Parse nested elements with pedantic whitespace", false, doc.Error());
XMLTest("Pedantic whitespace", true, 0 == doc.RootElement()->FirstChildElement()->GetText());
}
//Check the robustness of the DeleteNode function in handling null pointers.
{
XMLDocument doc;
doc.DeleteNode(nullptr);
XMLTest("DeleteNode with null pointer", true, doc.Error() == XML_SUCCESS);
}
// Check sample xml can be parsed with pedantic mode
{
XMLDocument doc(true, PEDANTIC_WHITESPACE);
@@ -2639,7 +2647,7 @@ int main( int argc, const char ** argv )
"<?xml version=\"1.0\"?>\n" // 2 DecL
"<root>\r\n" // 3 Element
"\n" // 4
"text contining new line \n" // 5 Text
"text containing new line \n" // 5 Text
" and also containing crlf \r\n" // 6
"<sub><![CDATA[\n" // 7 Element Text
"cdata containing new line \n" // 8
@@ -2666,6 +2674,120 @@ int main( int argc, const char ** argv )
doc.PrintError();
}
// ---------- CVE-2024-50615 -----------
{
const char* xml = "<Hello value='12&#65;34' value2='56&#x42;78'>Text</Hello>";
XMLDocument doc;
doc.Parse(xml);
const char* value = doc.FirstChildElement()->Attribute("value");
const char* value2 = doc.FirstChildElement()->Attribute("value2");
XMLTest("Test attribute encode", false, doc.Error());
XMLTest("Test decimal value", value, "12A34");
XMLTest("Test hex encode", value2, "56B78");
}
{
const char* xml = "<Hello value='&#ABC9000000065;' value2='&#xffffffff;' value3='&#5000000000;' value4='&#x00000045;' value5='&#x000000000000000021;'>Text</Hello>";
XMLDocument doc;
doc.Parse(xml);
const char* value = doc.FirstChildElement()->Attribute("value");
const char* value2 = doc.FirstChildElement()->Attribute("value2");
const char* value3 = doc.FirstChildElement()->Attribute("value3");
const char* value4 = doc.FirstChildElement()->Attribute("value4");
const char* value5 = doc.FirstChildElement()->Attribute("value5");
XMLTest("Test attribute encode", false, doc.Error());
XMLTest("Test attribute encode too long value", value, "&#ABC9000000065;"); // test long value
XMLTest("Test attribute encode out of unicode range", value2, "&#xffffffff;"); // out of unicode range
XMLTest("Test attribute encode out of int max value", value3, "&#5000000000;"); // out of int max value
XMLTest("Test attribute encode with a Hex value", value4, "E"); // hex value in unicode value
XMLTest("Test attribute encode with a Hex value", value5, "!"); // hex value in unicode value
}
// ---------- Security: numeric character reference bounds ----------
{
// Regression: U+10FFFF is the last valid Unicode code point and must
// parse correctly. The in-loop overflow guard must not reject it.
XMLDocument doc;
doc.Parse( "<t v='&#x10FFFF;'/>" );
XMLTest( "Numeric ref U+10FFFF: no error", false, doc.Error() );
const char* v = doc.FirstChildElement()->Attribute( "v" );
// U+10FFFF encodes to the 4-byte UTF-8 sequence F4 8F BF BF.
const char expected[] = {
static_cast<char>(0xF4), static_cast<char>(0x8F),
static_cast<char>(0xBF), static_cast<char>(0xBF), 0
};
XMLTest( "Numeric ref U+10FFFF: correct UTF-8 output", expected, v );
}
{
// Boundary check: U+110000 is one above the maximum code point.
// The in-loop overflow guard must catch this before ucs is written,
// leaving the entity as a literal (starting with '&').
XMLDocument doc;
doc.Parse( "<t v='&#x110000;'/>" );
XMLTest( "Numeric ref U+110000: no parse error", false, doc.Error() );
const char* v = doc.FirstChildElement()->Attribute( "v" );
XMLTest( "Numeric ref U+110000: not resolved (left as literal)", true,
v != nullptr && v[0] == '&' );
}
{
// A hex entity with enough digits to overflow uint32_t must
// be rejected by the in-loop guard before the accumulator wraps.
// Before the fix, ucs could wrap around and pass the post-loop range
// check, producing an attacker-chosen character in the parsed output.
// Build "&#x" + 300 'F' digits + ";" -- far beyond what fits in uint32_t.
const char prefix[] = "<t v='&#x";
const char suffix[] = ";'/>";
static const int NDIGITS = 300;
char xml[sizeof(prefix) + NDIGITS + sizeof(suffix)];
strcpy( xml, prefix );
memset( xml + strlen(prefix), 'F', NDIGITS );
strcpy( xml + strlen(prefix) + NDIGITS, suffix );
XMLDocument doc;
doc.Parse( xml );
XMLTest( "Overflow hex entity: no parse error", false, doc.Error() );
const char* v = doc.FirstChildElement()->Attribute( "v" );
// GetCharacterRef returns 0 for rejected refs; the caller then copies
// the literal '&', so the attribute must start with '&', not a char.
XMLTest( "Overflow hex entity: not resolved to a character", true,
v != nullptr && v[0] == '&' );
}
// ---------- XMLPrinter Apos Escaping ------
{
const char* testText = "text containing a ' character";
XMLDocument doc;
XMLElement* element = doc.NewElement( "element" );
doc.InsertEndChild( element );
element->SetAttribute( "attrib", testText );
{
XMLPrinter defaultPrinter;
doc.Print( &defaultPrinter );
const char* defaultOutput = defaultPrinter.CStr();
const bool foundTextWithUnescapedApos = (strstr(defaultOutput, testText) != nullptr);
XMLTest("Default XMLPrinter should escape ' characters", false, foundTextWithUnescapedApos);
{
XMLDocument parsingDoc;
parsingDoc.Parse(defaultOutput);
const XMLAttribute* attrib = parsingDoc.FirstChildElement("element")->FindAttribute("attrib");
XMLTest("Default XMLPrinter should output parsable xml", testText, attrib->Value(), true);
}
}
{
XMLPrinter customPrinter(0, false, 0, XMLPrinter::DONT_ESCAPE_APOS_CHARS_IN_ATTRIBUTES);
doc.Print( &customPrinter );
const char* customOutput = customPrinter.CStr();
const bool foundTextWithUnescapedApos = (strstr(customOutput, testText) != nullptr);
XMLTest("Custom XMLPrinter should not escape ' characters", true, foundTextWithUnescapedApos);
{
XMLDocument parsingDoc;
parsingDoc.Parse(customOutput);
const XMLAttribute* attrib = parsingDoc.FirstChildElement("element")->FindAttribute("attrib");
XMLTest("Custom XMLPrinter should output parsable xml", testText, attrib->Value(), true);
}
}
}
// ----------- Performance tracking --------------
{
#if defined( _MSC_VER )
@@ -2715,9 +2837,9 @@ int main( int argc, const char ** argv )
#endif
#if defined( _MSC_VER )
const double duration = 1000.0 * (double)(end - start) / ((double)freq * (double)COUNT);
const double duration = 1000.0 * static_cast<double>(end - start) / (static_cast<double>(freq) * static_cast<double>(COUNT));
#else
const double duration = (double)(cend - cstart) / (double)COUNT;
const double duration = static_cast<double>(cend - cstart) / static_cast<double>(COUNT);
#endif
printf("\nParsing dream.xml (%s): %.3f milli-seconds\n", note, duration);
}