mirror of
https://github.com/leethomason/tinyxml2.git
synced 2026-07-22 19:52:59 +04:00
Compare commits
40 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 96a2dd3a43 | |||
| 8224e427b6 | |||
| 935ddecc91 | |||
| 88d678c39e | |||
| 999a21fa86 | |||
| a737ecb2cb | |||
| 9901919829 | |||
| 63428c8852 | |||
| beb16fbca0 | |||
| 26ab0bd591 | |||
| 8d8472fe1a | |||
| 3dcad8e3c3 | |||
| 418229dc5c | |||
| 98137e6936 | |||
| 111f462dc4 | |||
| aba13c50bf | |||
| e48a1310fe | |||
| 3324d04d58 | |||
| c4e29afeaf | |||
| 5c9a452c73 | |||
| 2722500313 | |||
| b5e767a6b9 | |||
| e186491558 | |||
| 36ff404c34 | |||
| 302f4661a7 | |||
| e6caeae857 | |||
| b765a210b3 | |||
| 6e246aec4d | |||
| 30dee1efa0 | |||
| a93163d2f5 | |||
| f87d0e3077 | |||
| 487f42aa69 | |||
| afff7bf328 | |||
| 9148bdf719 | |||
| 57eea48c5b | |||
| 198cb82c9b | |||
| c6ab6d76e8 | |||
| 008e32968f | |||
| 0ca3584fa4 | |||
| 57ec94127b |
+12
-12
@@ -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
|
||||
@@ -33,14 +33,14 @@ jobs:
|
||||
# System set-up
|
||||
- uses: actions/checkout@v4
|
||||
- uses: ilammy/msvc-dev-cmd@v1
|
||||
- uses: seanmiddleditch/gha-setup-ninja@master
|
||||
- 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
|
||||
|
||||
+3
-3
@@ -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(
|
||||
|
||||
@@ -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
@@ -22,7 +22,7 @@
|
||||
project(
|
||||
'tinyxml2',
|
||||
['cpp'],
|
||||
version : '10.0.0',
|
||||
version : '11.0.0',
|
||||
meson_version : '>= 0.49.0',
|
||||
)
|
||||
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
TinyXML-2
|
||||
=========
|
||||
# TinyXML-2
|
||||
|
||||
[](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:
|
||||
|
||||
& &
|
||||
< <
|
||||
> >
|
||||
" "
|
||||
' '
|
||||
```html
|
||||
& &
|
||||
< <
|
||||
> >
|
||||
" "
|
||||
' '
|
||||
```
|
||||
|
||||
These are recognized when the XML document is read, and translated to their
|
||||
UTF-8 equivalents. For instance, text with the XML of:
|
||||
|
||||
Far & Away
|
||||
```xml
|
||||
Far & 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 ` ` or ` ` are both to the non-breaking space character.
|
||||
The syntax ` ` or ` ` 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.
|
||||
|
||||
+169
-159
@@ -24,7 +24,7 @@ distribution.
|
||||
#include "tinyxml2.h"
|
||||
|
||||
#include <new> // yes, this one new style header, is in the Android SDK.
|
||||
#if defined(ANDROID_NDK) || defined(__BORLANDC__) || defined(__QNXNTO__)
|
||||
#if defined(ANDROID_NDK)
|
||||
# include <stddef.h>
|
||||
# include <stdarg.h>
|
||||
#else
|
||||
@@ -32,15 +32,27 @@ distribution.
|
||||
# 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] ...
|
||||
);*/
|
||||
// Handle fallthrough attribute for different compilers
|
||||
#ifndef __has_attribute
|
||||
# define __has_attribute(x) 0
|
||||
#endif
|
||||
#ifndef __has_cpp_attribute
|
||||
# define __has_cpp_attribute(x) 0
|
||||
#endif
|
||||
|
||||
#if (__cplusplus >= 201703L && __has_cpp_attribute(fallthrough))
|
||||
# define TIXML_FALLTHROUGH [[fallthrough]]
|
||||
#elif __has_cpp_attribute(clang::fallthrough)
|
||||
# define TIXML_FALLTHROUGH [[clang::fallthrough]]
|
||||
#elif __has_attribute(fallthrough)
|
||||
# define TIXML_FALLTHROUGH __attribute__((fallthrough))
|
||||
#else
|
||||
# define TIXML_FALLTHROUGH (void(0))
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
|
||||
// Microsoft Visual Studio, version 2005 and higher.
|
||||
static inline int TIXML_SNPRINTF( char* buffer, size_t size, const char* format, ... )
|
||||
{
|
||||
va_list va;
|
||||
@@ -59,33 +71,11 @@ distribution.
|
||||
#define TIXML_VSCPRINTF _vscprintf
|
||||
#define TIXML_SSCANF sscanf_s
|
||||
#elif defined _MSC_VER
|
||||
// Microsoft Visual Studio 2003 and earlier or WinCE
|
||||
// Microsoft Visual Studio 2003 and earlier.
|
||||
#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
|
||||
#define TIXML_VSCPRINTF _vscprintf
|
||||
#else
|
||||
// GCC version 3 and higher
|
||||
//#warning( "Using sn* functions." )
|
||||
@@ -93,6 +83,9 @@ distribution.
|
||||
#define TIXML_VSNPRINTF vsnprintf
|
||||
static inline int TIXML_VSCPRINTF( const char* format, va_list va )
|
||||
{
|
||||
if (!format) {
|
||||
return 0;
|
||||
}
|
||||
int len = vsnprintf( 0, 0, format, va );
|
||||
TIXMLASSERT( len >= 0 );
|
||||
return len;
|
||||
@@ -100,7 +93,7 @@ distribution.
|
||||
#define TIXML_SSCANF sscanf
|
||||
#endif
|
||||
|
||||
#if defined(_WIN64)
|
||||
#if defined(_MSC_VER)
|
||||
#define TIXML_FSEEK _fseeki64
|
||||
#define TIXML_FTELL _ftelli64
|
||||
#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__CYGWIN__)
|
||||
@@ -161,12 +154,12 @@ void StrPair::TransferTo( StrPair* other )
|
||||
return;
|
||||
}
|
||||
// This in effect implements the assignment operator by "moving"
|
||||
// ownership (as in auto_ptr).
|
||||
// ownership (as in unique_ptr / move semantics).
|
||||
|
||||
TIXMLASSERT( other != 0 );
|
||||
TIXMLASSERT( other != nullptr );
|
||||
TIXMLASSERT( other->_flags == 0 );
|
||||
TIXMLASSERT( other->_start == 0 );
|
||||
TIXMLASSERT( other->_end == 0 );
|
||||
TIXMLASSERT( other->_start == nullptr );
|
||||
TIXMLASSERT( other->_end == nullptr );
|
||||
|
||||
other->Reset();
|
||||
|
||||
@@ -175,8 +168,8 @@ void StrPair::TransferTo( StrPair* other )
|
||||
other->_end = _end;
|
||||
|
||||
_flags = 0;
|
||||
_start = 0;
|
||||
_end = 0;
|
||||
_start = nullptr;
|
||||
_end = nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -186,8 +179,8 @@ void StrPair::Reset()
|
||||
delete [] _start;
|
||||
}
|
||||
_flags = 0;
|
||||
_start = 0;
|
||||
_end = 0;
|
||||
_start = nullptr;
|
||||
_end = nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -196,7 +189,7 @@ void StrPair::SetStr( const char* str, int flags )
|
||||
TIXMLASSERT( str );
|
||||
Reset();
|
||||
size_t len = strlen( str );
|
||||
TIXMLASSERT( _start == 0 );
|
||||
TIXMLASSERT( _start == nullptr );
|
||||
_start = new char[ len+1 ];
|
||||
memcpy( _start, str, len+1 );
|
||||
_end = _start + len;
|
||||
@@ -225,17 +218,17 @@ char* StrPair::ParseText( char* p, const char* endTag, int strFlags, int* curLin
|
||||
++p;
|
||||
TIXMLASSERT( p );
|
||||
}
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
char* StrPair::ParseName( char* p )
|
||||
{
|
||||
if ( !p || !(*p) ) {
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
if ( !XMLUtil::IsNameStartChar( static_cast<unsigned char>(*p) ) ) {
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
char* const start = p;
|
||||
@@ -325,7 +318,7 @@ const char* StrPair::GetStr()
|
||||
char buf[buflen] = { 0 };
|
||||
int len = 0;
|
||||
const char* adjusted = const_cast<char*>( XMLUtil::GetCharacterRef( p, buf, &len ) );
|
||||
if ( adjusted == 0 ) {
|
||||
if ( adjusted == nullptr ) {
|
||||
*q = *p;
|
||||
++p;
|
||||
++q;
|
||||
@@ -446,17 +439,17 @@ void XMLUtil::ConvertUTF32ToUTF8( unsigned long input, char* output, int* length
|
||||
--output;
|
||||
*output = static_cast<char>((input | BYTE_MARK) & BYTE_MASK);
|
||||
input >>= 6;
|
||||
//fall through
|
||||
TIXML_FALLTHROUGH;
|
||||
case 3:
|
||||
--output;
|
||||
*output = static_cast<char>((input | BYTE_MARK) & BYTE_MASK);
|
||||
input >>= 6;
|
||||
//fall through
|
||||
TIXML_FALLTHROUGH;
|
||||
case 2:
|
||||
--output;
|
||||
*output = static_cast<char>((input | BYTE_MARK) & BYTE_MASK);
|
||||
input >>= 6;
|
||||
//fall through
|
||||
TIXML_FALLTHROUGH;
|
||||
case 1:
|
||||
--output;
|
||||
*output = static_cast<char>(input | FIRST_BYTE_MARK[*length]);
|
||||
@@ -482,7 +475,7 @@ const char* XMLUtil::GetCharacterRef(const char* p, char* value, int* length)
|
||||
|
||||
bool hex = false;
|
||||
uint32_t radix = 10;
|
||||
const char* q = 0;
|
||||
const char* q = nullptr;
|
||||
char terminator = '#';
|
||||
|
||||
if (*(p + 2) == 'x') {
|
||||
@@ -498,12 +491,12 @@ const char* XMLUtil::GetCharacterRef(const char* p, char* value, int* length)
|
||||
q = p + 2;
|
||||
}
|
||||
if (!(*q)) {
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
q = strchr(q, SEMICOLON);
|
||||
if (!q) {
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
TIXMLASSERT(*q == SEMICOLON);
|
||||
|
||||
@@ -523,17 +516,20 @@ const char* XMLUtil::GetCharacterRef(const char* p, char* value, int* length)
|
||||
digit = *q - 'A' + 10;
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
TIXMLASSERT(digit < radix);
|
||||
|
||||
const unsigned int digitScaled = mult * digit;
|
||||
// Reject before adding: if digitScaled alone exceeds MAX_CODE_POINT,
|
||||
// or if adding it to ucs would exceed it (checked without overflow by
|
||||
// testing ucs > MAX_CODE_POINT - digitScaled, safe since digitScaled
|
||||
// <= MAX_CODE_POINT at this point).
|
||||
if (digitScaled > MAX_CODE_POINT || ucs > MAX_CODE_POINT - digitScaled) {
|
||||
return nullptr;
|
||||
}
|
||||
ucs += digitScaled;
|
||||
mult *= radix;
|
||||
|
||||
// Security check: could a value exist that is out of range?
|
||||
// Easily; limit to the MAX_CODE_POINT, which also allows for a
|
||||
// bunch of leading zeroes.
|
||||
mult *= radix;
|
||||
if (mult > MAX_CODE_POINT) {
|
||||
mult = MAX_CODE_POINT;
|
||||
}
|
||||
@@ -541,15 +537,15 @@ const char* XMLUtil::GetCharacterRef(const char* p, char* value, int* length)
|
||||
}
|
||||
// Out of range:
|
||||
if (ucs > MAX_CODE_POINT) {
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
// convert the UCS to UTF-8
|
||||
ConvertUTF32ToUTF8(ucs, value, length);
|
||||
if (length == 0) {
|
||||
// If length is 0, there was an error. (Security? Bad input?)
|
||||
if (*length == 0) {
|
||||
// If *length is 0, ConvertUTF32ToUTF8 rejected the code point.
|
||||
// Fail safely.
|
||||
return 0;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
return p + delta + 1;
|
||||
}
|
||||
return p + 1;
|
||||
@@ -632,8 +628,8 @@ bool XMLUtil::ToBool( const char* str, bool* value )
|
||||
*value = (ival==0) ? false : true;
|
||||
return true;
|
||||
}
|
||||
static const char* TRUE_VALS[] = { "true", "True", "TRUE", 0 };
|
||||
static const char* FALSE_VALS[] = { "false", "False", "FALSE", 0 };
|
||||
static const char* TRUE_VALS[] = { "true", "True", "TRUE", nullptr };
|
||||
static const char* FALSE_VALS[] = { "false", "False", "FALSE", nullptr };
|
||||
|
||||
for (int i = 0; TRUE_VALS[i]; ++i) {
|
||||
if (StringEqual(str, TRUE_VALS[i])) {
|
||||
@@ -707,7 +703,7 @@ char* XMLDocument::Identify( char* p, XMLNode** node, bool first )
|
||||
int const startLine = _parseCurLineNum;
|
||||
p = XMLUtil::SkipWhiteSpace( p, &_parseCurLineNum );
|
||||
if( !*p ) {
|
||||
*node = 0;
|
||||
*node = nullptr;
|
||||
TIXMLASSERT( p );
|
||||
return p;
|
||||
}
|
||||
@@ -727,7 +723,7 @@ char* XMLDocument::Identify( char* p, XMLNode** node, bool first )
|
||||
|
||||
TIXMLASSERT( sizeof( XMLComment ) == sizeof( XMLUnknown ) ); // use same memory pool
|
||||
TIXMLASSERT( sizeof( XMLComment ) == sizeof( XMLDeclaration ) ); // use same memory pool
|
||||
XMLNode* returnNode = 0;
|
||||
XMLNode* returnNode = nullptr;
|
||||
if ( XMLUtil::StringEqual( p, xmlHeader, xmlHeaderLen ) ) {
|
||||
returnNode = CreateUnlinkedNode<XMLDeclaration>( _commentPool );
|
||||
returnNode->_parseLineNum = _parseCurLineNum;
|
||||
@@ -797,20 +793,30 @@ bool XMLDocument::Accept( XMLVisitor* visitor ) const
|
||||
|
||||
XMLNode::XMLNode( XMLDocument* doc ) :
|
||||
_document( doc ),
|
||||
_parent( 0 ),
|
||||
_parent( nullptr ),
|
||||
_value(),
|
||||
_parseLineNum( 0 ),
|
||||
_firstChild( 0 ), _lastChild( 0 ),
|
||||
_prev( 0 ), _next( 0 ),
|
||||
_userData( 0 ),
|
||||
_memPool( 0 )
|
||||
_firstChild( nullptr ), _lastChild( nullptr ),
|
||||
_prev( nullptr ), _next( nullptr ),
|
||||
_userData( nullptr ),
|
||||
_memPool( nullptr )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
XMLNode::~XMLNode()
|
||||
{
|
||||
DeleteChildren();
|
||||
// Fast path: this node is dying, so maintaining _firstChild/_lastChild and
|
||||
// sibling _prev/_next links is unnecessary. Only _parent must be zeroed to
|
||||
// satisfy the MarkInUse assertion inside DeleteNode.
|
||||
XMLNode *currentChild = _firstChild;
|
||||
while (currentChild != nullptr) {
|
||||
XMLNode *next = currentChild->_next;
|
||||
currentChild->_parent = nullptr;
|
||||
DeleteNode(currentChild);
|
||||
currentChild = next;
|
||||
}
|
||||
|
||||
if ( _parent ) {
|
||||
_parent->Unlink( this );
|
||||
}
|
||||
@@ -848,7 +854,7 @@ const char* XMLNode::Value() const
|
||||
{
|
||||
// Edge case: XMLDocuments don't have a Value. Return null.
|
||||
if ( this->ToDocument() )
|
||||
return 0;
|
||||
return nullptr;
|
||||
return _value.GetStr();
|
||||
}
|
||||
|
||||
@@ -865,7 +871,7 @@ void XMLNode::SetValue( const char* str, bool staticMem )
|
||||
XMLNode* XMLNode::DeepClone(XMLDocument* target) const
|
||||
{
|
||||
XMLNode* clone = this->ShallowClone(target);
|
||||
if (!clone) return 0;
|
||||
if (!clone) return nullptr;
|
||||
|
||||
for (const XMLNode* child = this->FirstChild(); child; child = child->NextSibling()) {
|
||||
XMLNode* childClone = child->DeepClone(target);
|
||||
@@ -881,7 +887,7 @@ void XMLNode::DeleteChildren()
|
||||
TIXMLASSERT( _lastChild );
|
||||
DeleteChild( _firstChild );
|
||||
}
|
||||
_firstChild = _lastChild = 0;
|
||||
_firstChild = _lastChild = nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -903,9 +909,9 @@ void XMLNode::Unlink( XMLNode* child )
|
||||
if ( child->_next ) {
|
||||
child->_next->_prev = child->_prev;
|
||||
}
|
||||
child->_next = 0;
|
||||
child->_prev = 0;
|
||||
child->_parent = 0;
|
||||
child->_next = nullptr;
|
||||
child->_prev = nullptr;
|
||||
child->_parent = nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -915,9 +921,9 @@ void XMLNode::DeleteChild( XMLNode* node )
|
||||
TIXMLASSERT( node->_document == _document );
|
||||
TIXMLASSERT( node->_parent == this );
|
||||
Unlink( node );
|
||||
TIXMLASSERT(node->_prev == 0);
|
||||
TIXMLASSERT(node->_next == 0);
|
||||
TIXMLASSERT(node->_parent == 0);
|
||||
TIXMLASSERT(node->_prev == nullptr);
|
||||
TIXMLASSERT(node->_next == nullptr);
|
||||
TIXMLASSERT(node->_parent == nullptr);
|
||||
DeleteNode( node );
|
||||
}
|
||||
|
||||
@@ -927,25 +933,25 @@ XMLNode* XMLNode::InsertEndChild( XMLNode* addThis )
|
||||
TIXMLASSERT( addThis );
|
||||
if ( addThis->_document != _document ) {
|
||||
TIXMLASSERT( false );
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
InsertChildPreamble( addThis );
|
||||
|
||||
if ( _lastChild ) {
|
||||
TIXMLASSERT( _firstChild );
|
||||
TIXMLASSERT( _lastChild->_next == 0 );
|
||||
TIXMLASSERT( _lastChild->_next == nullptr );
|
||||
_lastChild->_next = addThis;
|
||||
addThis->_prev = _lastChild;
|
||||
_lastChild = addThis;
|
||||
|
||||
addThis->_next = 0;
|
||||
addThis->_next = nullptr;
|
||||
}
|
||||
else {
|
||||
TIXMLASSERT( _firstChild == 0 );
|
||||
TIXMLASSERT( _firstChild == nullptr );
|
||||
_firstChild = _lastChild = addThis;
|
||||
|
||||
addThis->_prev = 0;
|
||||
addThis->_next = 0;
|
||||
addThis->_prev = nullptr;
|
||||
addThis->_next = nullptr;
|
||||
}
|
||||
addThis->_parent = this;
|
||||
return addThis;
|
||||
@@ -957,26 +963,26 @@ XMLNode* XMLNode::InsertFirstChild( XMLNode* addThis )
|
||||
TIXMLASSERT( addThis );
|
||||
if ( addThis->_document != _document ) {
|
||||
TIXMLASSERT( false );
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
InsertChildPreamble( addThis );
|
||||
|
||||
if ( _firstChild ) {
|
||||
TIXMLASSERT( _lastChild );
|
||||
TIXMLASSERT( _firstChild->_prev == 0 );
|
||||
TIXMLASSERT( _firstChild->_prev == nullptr );
|
||||
|
||||
_firstChild->_prev = addThis;
|
||||
addThis->_next = _firstChild;
|
||||
_firstChild = addThis;
|
||||
|
||||
addThis->_prev = 0;
|
||||
addThis->_prev = nullptr;
|
||||
}
|
||||
else {
|
||||
TIXMLASSERT( _lastChild == 0 );
|
||||
TIXMLASSERT( _lastChild == nullptr );
|
||||
_firstChild = _lastChild = addThis;
|
||||
|
||||
addThis->_prev = 0;
|
||||
addThis->_next = 0;
|
||||
addThis->_prev = nullptr;
|
||||
addThis->_next = nullptr;
|
||||
}
|
||||
addThis->_parent = this;
|
||||
return addThis;
|
||||
@@ -988,14 +994,14 @@ XMLNode* XMLNode::InsertAfterChild( XMLNode* afterThis, XMLNode* addThis )
|
||||
TIXMLASSERT( addThis );
|
||||
if ( addThis->_document != _document ) {
|
||||
TIXMLASSERT( false );
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
TIXMLASSERT( afterThis );
|
||||
|
||||
if ( afterThis->_parent != this ) {
|
||||
TIXMLASSERT( false );
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
if ( afterThis == addThis ) {
|
||||
// Current state: BeforeThis -> AddThis -> OneAfterAddThis
|
||||
@@ -1005,7 +1011,7 @@ XMLNode* XMLNode::InsertAfterChild( XMLNode* afterThis, XMLNode* addThis )
|
||||
return addThis;
|
||||
}
|
||||
|
||||
if ( afterThis->_next == 0 ) {
|
||||
if ( afterThis->_next == nullptr ) {
|
||||
// The last node or the only node.
|
||||
return InsertEndChild( addThis );
|
||||
}
|
||||
@@ -1029,7 +1035,7 @@ const XMLElement* XMLNode::FirstChildElement( const char* name ) const
|
||||
return element;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -1041,7 +1047,7 @@ const XMLElement* XMLNode::LastChildElement( const char* name ) const
|
||||
return element;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -1053,7 +1059,7 @@ const XMLElement* XMLNode::NextSiblingElement( const char* name ) const
|
||||
return element;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -1065,7 +1071,7 @@ const XMLElement* XMLNode::PreviousSiblingElement( const char* name ) const
|
||||
return element;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -1090,15 +1096,15 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr )
|
||||
|
||||
XMLDocument::DepthTracker tracker(_document);
|
||||
if (_document->Error())
|
||||
return 0;
|
||||
return nullptr;
|
||||
|
||||
bool first = true;
|
||||
while( p && *p ) {
|
||||
XMLNode* node = 0;
|
||||
XMLNode* node = nullptr;
|
||||
|
||||
p = _document->Identify( p, &node, first );
|
||||
TIXMLASSERT( p );
|
||||
if ( node == 0 ) {
|
||||
if ( node == nullptr ) {
|
||||
break;
|
||||
}
|
||||
first = false;
|
||||
@@ -1110,7 +1116,7 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr )
|
||||
if ( !p ) {
|
||||
_document->DeleteNode( node );
|
||||
if ( !_document->Error() ) {
|
||||
_document->SetError( XML_ERROR_PARSING, initialLineNum, 0);
|
||||
_document->SetError( XML_ERROR_PARSING, initialLineNum, nullptr);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -1182,12 +1188,12 @@ char* XMLNode::ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr )
|
||||
}
|
||||
InsertEndChild( node );
|
||||
}
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/*static*/ void XMLNode::DeleteNode( XMLNode* node )
|
||||
{
|
||||
if ( node == 0 ) {
|
||||
if ( node == nullptr ) {
|
||||
return;
|
||||
}
|
||||
TIXMLASSERT(node->_document);
|
||||
@@ -1217,16 +1223,16 @@ void XMLNode::InsertChildPreamble( XMLNode* insertThis ) const
|
||||
const XMLElement* XMLNode::ToElementWithName( const char* name ) const
|
||||
{
|
||||
const XMLElement* element = this->ToElement();
|
||||
if ( element == 0 ) {
|
||||
return 0;
|
||||
if ( element == nullptr ) {
|
||||
return nullptr;
|
||||
}
|
||||
if ( name == 0 ) {
|
||||
if ( name == nullptr ) {
|
||||
return element;
|
||||
}
|
||||
if ( XMLUtil::StringEqual( element->Name(), name ) ) {
|
||||
return element;
|
||||
}
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// --------- XMLText ---------- //
|
||||
@@ -1250,10 +1256,10 @@ char* XMLText::ParseDeep( char* p, StrPair*, int* curLineNumPtr )
|
||||
return p-1;
|
||||
}
|
||||
if ( !p ) {
|
||||
_document->SetError( XML_ERROR_PARSING_TEXT, _parseLineNum, 0 );
|
||||
_document->SetError( XML_ERROR_PARSING_TEXT, _parseLineNum, nullptr );
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -1299,7 +1305,7 @@ char* XMLComment::ParseDeep( char* p, StrPair*, int* curLineNumPtr )
|
||||
{
|
||||
// Comment parses as text.
|
||||
p = _value.ParseText( p, "-->", StrPair::COMMENT, curLineNumPtr );
|
||||
if ( p == 0 ) {
|
||||
if ( p == nullptr ) {
|
||||
_document->SetError( XML_ERROR_PARSING_COMMENT, _parseLineNum, 0 );
|
||||
}
|
||||
return p;
|
||||
@@ -1348,7 +1354,7 @@ char* XMLDeclaration::ParseDeep( char* p, StrPair*, int* curLineNumPtr )
|
||||
{
|
||||
// Declaration parses as text.
|
||||
p = _value.ParseText( p, "?>", StrPair::NEEDS_NEWLINE_NORMALIZATION, curLineNumPtr );
|
||||
if ( p == 0 ) {
|
||||
if ( p == nullptr ) {
|
||||
_document->SetError( XML_ERROR_PARSING_DECLARATION, _parseLineNum, 0 );
|
||||
}
|
||||
return p;
|
||||
@@ -1444,19 +1450,19 @@ char* XMLAttribute::ParseDeep( char* p, bool processEntities, int* curLineNumPtr
|
||||
// Parse using the name rules: bug fix, was using ParseText before
|
||||
p = _name.ParseName( p );
|
||||
if ( !p || !*p ) {
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Skip white space before =
|
||||
p = XMLUtil::SkipWhiteSpace( p, curLineNumPtr );
|
||||
if ( *p != '=' ) {
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
++p; // move up to opening quote
|
||||
p = XMLUtil::SkipWhiteSpace( p, curLineNumPtr );
|
||||
if ( *p != '\"' && *p != '\'' ) {
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const char endTag[2] = { *p, 0 };
|
||||
@@ -1598,7 +1604,7 @@ void XMLAttribute::SetAttribute( float v )
|
||||
// --------- XMLElement ---------- //
|
||||
XMLElement::XMLElement( XMLDocument* doc ) : XMLNode( doc ),
|
||||
_closingType( OPEN ),
|
||||
_rootAttribute( 0 )
|
||||
_rootAttribute( nullptr )
|
||||
{
|
||||
}
|
||||
|
||||
@@ -1620,7 +1626,7 @@ const XMLAttribute* XMLElement::FindAttribute( const char* name ) const
|
||||
return a;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -1628,12 +1634,12 @@ const char* XMLElement::Attribute( const char* name, const char* value ) const
|
||||
{
|
||||
const XMLAttribute* a = FindAttribute( name );
|
||||
if ( !a ) {
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
if ( !value || XMLUtil::StringEqual( a->Value(), value )) {
|
||||
return a->Value();
|
||||
}
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int XMLElement::IntAttribute(const char* name, int defaultValue) const
|
||||
@@ -1700,7 +1706,7 @@ const char* XMLElement::GetText() const
|
||||
if ( node && node->ToText() ) {
|
||||
return node->Value();
|
||||
}
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -1911,8 +1917,8 @@ float XMLElement::FloatText(float defaultValue) const
|
||||
|
||||
XMLAttribute* XMLElement::FindOrCreateAttribute( const char* name )
|
||||
{
|
||||
XMLAttribute* last = 0;
|
||||
XMLAttribute* attrib = 0;
|
||||
XMLAttribute* last = nullptr;
|
||||
XMLAttribute* attrib = nullptr;
|
||||
for( attrib = _rootAttribute;
|
||||
attrib;
|
||||
last = attrib, attrib = attrib->_next ) {
|
||||
@@ -1924,11 +1930,11 @@ XMLAttribute* XMLElement::FindOrCreateAttribute( const char* name )
|
||||
attrib = CreateAttribute();
|
||||
TIXMLASSERT( attrib );
|
||||
if ( last ) {
|
||||
TIXMLASSERT( last->_next == 0 );
|
||||
TIXMLASSERT( last->_next == nullptr );
|
||||
last->_next = attrib;
|
||||
}
|
||||
else {
|
||||
TIXMLASSERT( _rootAttribute == 0 );
|
||||
TIXMLASSERT( _rootAttribute == nullptr );
|
||||
_rootAttribute = attrib;
|
||||
}
|
||||
attrib->SetName( name );
|
||||
@@ -1939,7 +1945,7 @@ XMLAttribute* XMLElement::FindOrCreateAttribute( const char* name )
|
||||
|
||||
void XMLElement::DeleteAttribute( const char* name )
|
||||
{
|
||||
XMLAttribute* prev = 0;
|
||||
XMLAttribute* prev = nullptr;
|
||||
for( XMLAttribute* a=_rootAttribute; a; a=a->_next ) {
|
||||
if ( XMLUtil::StringEqual( name, a->Name() ) ) {
|
||||
if ( prev ) {
|
||||
@@ -1958,14 +1964,14 @@ void XMLElement::DeleteAttribute( const char* name )
|
||||
|
||||
char* XMLElement::ParseAttributes( char* p, int* curLineNumPtr )
|
||||
{
|
||||
XMLAttribute* prevAttribute = 0;
|
||||
XMLAttribute* prevAttribute = nullptr;
|
||||
|
||||
// Read the attributes.
|
||||
while( p ) {
|
||||
p = XMLUtil::SkipWhiteSpace( p, curLineNumPtr );
|
||||
if ( !(*p) ) {
|
||||
_document->SetError( XML_ERROR_PARSING_ELEMENT, _parseLineNum, "XMLElement name=%s", Name() );
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// attribute.
|
||||
@@ -1980,7 +1986,7 @@ char* XMLElement::ParseAttributes( char* p, int* curLineNumPtr )
|
||||
if ( !p || Attribute( attrib->Name() ) ) {
|
||||
DeleteAttribute( attrib );
|
||||
_document->SetError( XML_ERROR_PARSING_ATTRIBUTE, attrLineNum, "XMLElement name=%s", Name() );
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
// There is a minor bug here: if the attribute in the source xml
|
||||
// document is duplicated, it will not be detected and the
|
||||
@@ -1988,11 +1994,11 @@ char* XMLElement::ParseAttributes( char* p, int* curLineNumPtr )
|
||||
// avoids re-scanning the attribute list. Preferring performance for
|
||||
// now, may reconsider in the future.
|
||||
if ( prevAttribute ) {
|
||||
TIXMLASSERT( prevAttribute->_next == 0 );
|
||||
TIXMLASSERT( prevAttribute->_next == nullptr );
|
||||
prevAttribute->_next = attrib;
|
||||
}
|
||||
else {
|
||||
TIXMLASSERT( _rootAttribute == 0 );
|
||||
TIXMLASSERT( _rootAttribute == nullptr );
|
||||
_rootAttribute = attrib;
|
||||
}
|
||||
prevAttribute = attrib;
|
||||
@@ -2008,8 +2014,8 @@ char* XMLElement::ParseAttributes( char* p, int* curLineNumPtr )
|
||||
return p+2; // done; sealed element.
|
||||
}
|
||||
else {
|
||||
_document->SetError( XML_ERROR_PARSING_ELEMENT, _parseLineNum, 0 );
|
||||
return 0;
|
||||
_document->SetError( XML_ERROR_PARSING_ELEMENT, _parseLineNum, nullptr );
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
return p;
|
||||
@@ -2017,7 +2023,7 @@ char* XMLElement::ParseAttributes( char* p, int* curLineNumPtr )
|
||||
|
||||
void XMLElement::DeleteAttribute( XMLAttribute* attribute )
|
||||
{
|
||||
if ( attribute == 0 ) {
|
||||
if ( attribute == nullptr ) {
|
||||
return;
|
||||
}
|
||||
MemPool* pool = attribute->_memPool;
|
||||
@@ -2087,7 +2093,7 @@ char* XMLElement::ParseDeep( char* p, StrPair* parentEndTag, int* curLineNumPtr
|
||||
|
||||
p = _value.ParseName( p );
|
||||
if ( _value.Empty() ) {
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
p = ParseAttributes( p, curLineNumPtr );
|
||||
@@ -2181,14 +2187,14 @@ const char* XMLDocument::_errorNames[XML_ERROR_COUNT] = {
|
||||
|
||||
|
||||
XMLDocument::XMLDocument( bool processEntities, Whitespace whitespaceMode ) :
|
||||
XMLNode( 0 ),
|
||||
XMLNode( nullptr ),
|
||||
_writeBOM( false ),
|
||||
_processEntities( processEntities ),
|
||||
_errorID(XML_SUCCESS),
|
||||
_whitespaceMode( whitespaceMode ),
|
||||
_errorStr(),
|
||||
_errorLineNum( 0 ),
|
||||
_charBuffer( 0 ),
|
||||
_charBuffer( nullptr ),
|
||||
_parseCurLineNum( 0 ),
|
||||
_parsingDepth(0),
|
||||
_unlinked(),
|
||||
@@ -2211,7 +2217,7 @@ XMLDocument::~XMLDocument()
|
||||
void XMLDocument::MarkInUse(const XMLNode* const node)
|
||||
{
|
||||
TIXMLASSERT(node);
|
||||
TIXMLASSERT(node->_parent == 0);
|
||||
TIXMLASSERT(node->_parent == nullptr);
|
||||
|
||||
for (size_t i = 0; i < _unlinked.Size(); ++i) {
|
||||
if (node == _unlinked[i]) {
|
||||
@@ -2234,9 +2240,9 @@ void XMLDocument::Clear()
|
||||
ClearError();
|
||||
|
||||
delete [] _charBuffer;
|
||||
_charBuffer = 0;
|
||||
_charBuffer = nullptr;
|
||||
_parsingDepth = 0;
|
||||
|
||||
|
||||
#if 0
|
||||
_textPool.Trace( "text" );
|
||||
_elementPool.Trace( "element" );
|
||||
@@ -2311,11 +2317,11 @@ static FILE* callfopen( const char* filepath, const char* mode )
|
||||
{
|
||||
TIXMLASSERT( filepath );
|
||||
TIXMLASSERT( mode );
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1400 ) && (!defined WINCE)
|
||||
FILE* fp = 0;
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
|
||||
FILE* fp = nullptr;
|
||||
const errno_t err = fopen_s( &fp, filepath, mode );
|
||||
if ( err ) {
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
#else
|
||||
FILE* fp = fopen( filepath, mode );
|
||||
@@ -2324,8 +2330,10 @@ static FILE* callfopen( const char* filepath, const char* mode )
|
||||
}
|
||||
|
||||
void XMLDocument::DeleteNode( XMLNode* node ) {
|
||||
TIXMLASSERT( node );
|
||||
TIXMLASSERT(node->_document == this );
|
||||
if(node == nullptr) {
|
||||
return; // check for null pointer
|
||||
}
|
||||
TIXMLASSERT(node->_document == this);
|
||||
if (node->_parent) {
|
||||
node->_parent->DeleteChild( node );
|
||||
}
|
||||
@@ -2399,7 +2407,7 @@ XMLError XMLDocument::LoadFile( FILE* fp )
|
||||
}
|
||||
|
||||
const size_t size = static_cast<size_t>(filelength);
|
||||
TIXMLASSERT( _charBuffer == 0 );
|
||||
TIXMLASSERT( _charBuffer == nullptr );
|
||||
_charBuffer = new char[size+1];
|
||||
const size_t read = fread( _charBuffer, 1, size, fp );
|
||||
if ( read != size ) {
|
||||
@@ -2455,7 +2463,7 @@ XMLError XMLDocument::Parse( const char* xml, size_t nBytes )
|
||||
if ( nBytes == static_cast<size_t>(-1) ) {
|
||||
nBytes = strlen( xml );
|
||||
}
|
||||
TIXMLASSERT( _charBuffer == 0 );
|
||||
TIXMLASSERT( _charBuffer == nullptr );
|
||||
_charBuffer = new char[ nBytes+1 ];
|
||||
memcpy( _charBuffer, xml, nBytes );
|
||||
_charBuffer[nBytes] = 0;
|
||||
@@ -2481,7 +2489,7 @@ void XMLDocument::Print( XMLPrinter* streamer ) const
|
||||
Accept( streamer );
|
||||
}
|
||||
else {
|
||||
XMLPrinter stdoutStreamer( stdout );
|
||||
XMLPrinter stdoutStreamer( stdout ); // file=stdout, not nullptr
|
||||
Accept( &stdoutStreamer );
|
||||
}
|
||||
}
|
||||
@@ -2560,7 +2568,7 @@ void XMLDocument::Parse()
|
||||
SetError( XML_ERROR_EMPTY_DOCUMENT, 0, 0 );
|
||||
return;
|
||||
}
|
||||
ParseDeep(p, 0, &_parseCurLineNum );
|
||||
ParseDeep(p, nullptr, &_parseCurLineNum );
|
||||
}
|
||||
|
||||
void XMLDocument::PushDepth()
|
||||
@@ -2577,7 +2585,7 @@ void XMLDocument::PopDepth()
|
||||
--_parsingDepth;
|
||||
}
|
||||
|
||||
XMLPrinter::XMLPrinter( FILE* file, bool compact, int depth ) :
|
||||
XMLPrinter::XMLPrinter( FILE* file, bool compact, int depth, EscapeAposCharsInAttributes aposInAttributes ) :
|
||||
_elementJustOpened( false ),
|
||||
_stack(),
|
||||
_firstElement( true ),
|
||||
@@ -2594,9 +2602,11 @@ XMLPrinter::XMLPrinter( FILE* file, bool compact, int depth ) :
|
||||
}
|
||||
for( int i=0; i<NUM_ENTITIES; ++i ) {
|
||||
const char entityValue = entities[i].value;
|
||||
const unsigned char flagIndex = static_cast<unsigned char>(entityValue);
|
||||
TIXMLASSERT( flagIndex < ENTITY_RANGE );
|
||||
_entityFlag[flagIndex] = true;
|
||||
if ((aposInAttributes == ESCAPE_APOS_CHARS_IN_ATTRIBUTES) || (entityValue != SINGLE_QUOTE)) {
|
||||
const unsigned char flagIndex = static_cast<unsigned char>(entityValue);
|
||||
TIXMLASSERT( flagIndex < ENTITY_RANGE );
|
||||
_entityFlag[flagIndex] = true;
|
||||
}
|
||||
}
|
||||
_restrictedEntityFlag[static_cast<unsigned char>('&')] = true;
|
||||
_restrictedEntityFlag[static_cast<unsigned char>('<')] = true;
|
||||
@@ -2633,7 +2643,7 @@ void XMLPrinter::Write( const char* data, size_t size )
|
||||
fwrite ( data , sizeof(char), size, _fp);
|
||||
}
|
||||
else {
|
||||
char* p = _buffer.PushArr( static_cast<int>(size) ) - 1; // back up over the null terminator.
|
||||
char* p = _buffer.PushArr( size ) - 1; // back up over the null terminator.
|
||||
memcpy( p, data, size );
|
||||
p[size] = 0;
|
||||
}
|
||||
@@ -2969,7 +2979,7 @@ bool XMLPrinter::VisitEnter( const XMLDocument& doc )
|
||||
|
||||
bool XMLPrinter::VisitEnter( const XMLElement& element, const XMLAttribute* attribute )
|
||||
{
|
||||
const XMLElement* parentElem = 0;
|
||||
const XMLElement* parentElem = nullptr;
|
||||
if ( element.Parent() ) {
|
||||
parentElem = element.Parent()->ToElement();
|
||||
}
|
||||
|
||||
+107
-106
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
@@ -266,7 +263,6 @@ public:
|
||||
}
|
||||
|
||||
size_t Size() const {
|
||||
TIXMLASSERT( _size >= 0 );
|
||||
return _size;
|
||||
}
|
||||
|
||||
@@ -293,8 +289,8 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
DynArray( const DynArray& ); // not supported
|
||||
void operator=( const DynArray& ); // not supported
|
||||
DynArray( const DynArray& ) = delete;
|
||||
DynArray& operator=( const DynArray& ) = delete;
|
||||
|
||||
void EnsureCapacity( size_t cap ) {
|
||||
TIXMLASSERT( cap > 0 );
|
||||
@@ -343,7 +339,7 @@ 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();
|
||||
}
|
||||
@@ -354,7 +350,7 @@ public:
|
||||
Block* lastBlock = _blockPtrs.Pop();
|
||||
delete lastBlock;
|
||||
}
|
||||
_root = 0;
|
||||
_root = nullptr;
|
||||
_currentAllocs = 0;
|
||||
_nAllocs = 0;
|
||||
_maxAllocs = 0;
|
||||
@@ -378,11 +374,11 @@ public:
|
||||
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;
|
||||
@@ -434,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;
|
||||
@@ -686,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.
|
||||
@@ -779,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 ));
|
||||
}
|
||||
|
||||
@@ -797,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) );
|
||||
}
|
||||
|
||||
@@ -813,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 ) );
|
||||
}
|
||||
|
||||
@@ -829,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 ) );
|
||||
}
|
||||
|
||||
@@ -973,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;
|
||||
};
|
||||
|
||||
|
||||
@@ -1024,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;
|
||||
};
|
||||
|
||||
|
||||
@@ -1053,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;
|
||||
};
|
||||
|
||||
|
||||
@@ -1092,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;
|
||||
};
|
||||
|
||||
|
||||
@@ -1127,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;
|
||||
};
|
||||
|
||||
|
||||
@@ -1242,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 );
|
||||
@@ -1307,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
|
||||
@@ -1687,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 );
|
||||
@@ -1831,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;
|
||||
|
||||
/**
|
||||
@@ -1863,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
|
||||
@@ -1931,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;
|
||||
@@ -2072,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.
|
||||
@@ -2109,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:
|
||||
@@ -2149,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 );
|
||||
}
|
||||
|
||||
|
||||
@@ -2178,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:
|
||||
@@ -2240,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. */
|
||||
@@ -2368,9 +2369,9 @@ 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;
|
||||
};
|
||||
|
||||
|
||||
|
||||
+124
-31
@@ -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() );
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -2695,6 +2703,91 @@ int main( int argc, const char ** argv )
|
||||
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=''/>" );
|
||||
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='�'/>" );
|
||||
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 )
|
||||
@@ -2744,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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user