From f7aa65db8a13d32da0586c125f6b9b67460af374 Mon Sep 17 00:00:00 2001 From: Stephan Beyer Date: Sun, 24 Jan 2016 14:03:02 +0100 Subject: Fix whitespace issues Git warns when it finds "whitespace errors". This commit gets rid of these whitespace errors for code and adoc files. --- docs/manual.adoc | 114 +++--- docs/quickstart.adoc | 8 +- docs/samples/include.cpp | 2 +- docs/samples/save_declaration.cpp | 2 +- scripts/CMakeLists.txt | 4 +- src/pugiconfig.hpp | 2 +- src/pugixml.cpp | 790 +++++++++++++++++++------------------- src/pugixml.hpp | 94 ++--- tests/main.cpp | 12 +- tests/test.hpp | 2 +- tests/test_document.cpp | 4 +- tests/test_dom_modify.cpp | 76 ++-- tests/test_dom_text.cpp | 6 +- tests/test_dom_traverse.cpp | 26 +- tests/test_memory.cpp | 2 +- tests/test_parse.cpp | 8 +- tests/test_xpath.cpp | 4 +- tests/test_xpath_api.cpp | 10 +- tests/test_xpath_functions.cpp | 58 +-- tests/test_xpath_operators.cpp | 6 +- tests/test_xpath_variables.cpp | 2 +- tests/test_xpath_xalan_1.cpp | 2 +- tests/writer_string.hpp | 2 +- 23 files changed, 618 insertions(+), 618 deletions(-) diff --git a/docs/manual.adoc b/docs/manual.adoc index 56ebc07..982926f 100644 --- a/docs/manual.adoc +++ b/docs/manual.adoc @@ -71,7 +71,7 @@ OTHER DEALINGS IN THE SOFTWARE. .... This means that you can freely use pugixml in your applications, both open-source and proprietary. If you use pugixml in a product, it is sufficient to add an acknowledgment like this to the product distribution: - + .... This software is based on pugixml library (http://pugixml.org). pugixml is Copyright (C) 2006-2016 Arseny Kapoulkine. @@ -142,9 +142,9 @@ Here's an incomplete list of pugixml packages in various systems: === Building pugixml pugixml is distributed in source form without any pre-built binaries; you have to build them yourself. - + The complete pugixml source consists of three files - one source file, `pugixml.cpp`, and two header files, `pugixml.hpp` and `pugiconfig.hpp`. `pugixml.hpp` is the primary header which you need to include in order to use pugixml classes/functions; `pugiconfig.hpp` is a supplementary configuration file (see <>). The rest of this guide assumes that `pugixml.hpp` is either in the current directory or in one of include directories of your projects, so that `#include "pugixml.hpp"` can find the header; however you can also use relative path (i.e. `#include "../libs/pugixml/src/pugixml.hpp"`) or include directory-relative path (i.e. `#include `). - + [[install.building.embed]] ==== Building pugixml as a part of another static library/executable @@ -165,11 +165,11 @@ The correct way to resolve this is to disable precompiled headers for `pugixml.c | image::vs2005_pch3.png[link="images/vs2005_pch3.png"] | image::vs2005_pch4.png[link="images/vs2005_pch4.png"] |=== - + [[install.building.static]] ==== Building pugixml as a standalone static library - -It's possible to compile pugixml as a standalone static library. This process depends on the method of building your application; pugixml distribution comes with project files for several popular IDEs/build systems. There are project files for Apple XCode, Code::Blocks, Codelite, Microsoft Visual Studio 2005, 2008, 2010+, and configuration scripts for CMake and premake4. You're welcome to submit project files/build scripts for other software; see <>. + +It's possible to compile pugixml as a standalone static library. This process depends on the method of building your application; pugixml distribution comes with project files for several popular IDEs/build systems. There are project files for Apple XCode, Code::Blocks, Codelite, Microsoft Visual Studio 2005, 2008, 2010+, and configuration scripts for CMake and premake4. You're welcome to submit project files/build scripts for other software; see <>. There are two projects for each version of Microsoft Visual Studio: one for dynamically linked CRT, which has a name like `pugixml_vs2008.vcproj`, and another one for statically linked CRT, which has a name like `pugixml_vs2008_static.vcproj`. You should select the version that matches the CRT used in your application; the default option for new projects created by Microsoft Visual Studio is dynamically linked CRT, so unless you changed the defaults, you should use the version with dynamic CRT (i.e. `pugixml_vs2008.vcproj` for Microsoft Visual Studio 2008). @@ -187,7 +187,7 @@ In addition to adding pugixml project to your workspace, you'll have to make sur [[install.building.shared]] ==== Building pugixml as a standalone shared library - + It's possible to compile pugixml as a standalone shared library. The process is usually similar to the static library approach; however, no preconfigured projects/scripts are included into pugixml distribution, so you'll have to do it yourself. Generally, if you're using GCC-based toolchain, the process does not differ from building any other library as DLL (adding -shared to compilation flags should suffice); if you're using MSVC-based toolchain, you'll have to explicitly mark exported symbols with a declspec attribute. You can do it by defining <> macro, i.e. via `pugiconfig.hpp`: [source] @@ -243,7 +243,7 @@ NOTE: In that example `PUGIXML_API` is inconsistent between several source files [[PUGIXML_MEMORY_PAGE_SIZE]]`PUGIXML_MEMORY_PAGE_SIZE`, [[PUGIXML_MEMORY_OUTPUT_STACK]]`PUGIXML_MEMORY_OUTPUT_STACK` and [[PUGIXML_MEMORY_XPATH_PAGE_SIZE]]`PUGIXML_MEMORY_XPATH_PAGE_SIZE` can be used to customize certain important sizes to optimize memory usage for the application-specific patterns. For details see <>. [[PUGIXML_HAS_LONG_LONG]]`PUGIXML_HAS_LONG_LONG` define enables support for `long long` type in pugixml. This define is automatically enabled if your platform is known to have `long long` support (i.e. has C{plus}{plus}11 support or uses a reasonably modern version of a known compiler); if pugixml does not recognize that your platform supports `long long` but in fact it does, you can enable the define manually. - + [[install.portability]] === Portability @@ -451,7 +451,7 @@ you'll have to use `xml_node node = doc.child(L"bookstore").find_child_by_attribute(L"book", L"id", L"12345");` ==== - + [[dom.thread]] === Thread-safety guarantees @@ -509,11 +509,11 @@ This is a simple example of custom memory management (link:samples/custom_memory [source,indent=0] ---- -include::samples/custom_memory_management.cpp[tags=decl] +include::samples/custom_memory_management.cpp[tags=decl] ---- [source,indent=0] ---- -include::samples/custom_memory_management.cpp[tags=call] +include::samples/custom_memory_management.cpp[tags=call] ---- When setting new memory management functions, care must be taken to make sure that there are no live pugixml objects. Otherwise when the objects are destroyed, the new deallocation function will be called with the memory obtained by the old allocation function, resulting in undefined behavior. @@ -569,7 +569,7 @@ The most common source of XML data is files; pugixml provides dedicated function xml_parse_result xml_document::load_file(const char* path, unsigned int options = parse_default, xml_encoding encoding = encoding_auto); xml_parse_result xml_document::load_file(const wchar_t* path, unsigned int options = parse_default, xml_encoding encoding = encoding_auto); ---- - + These functions accept the file path as its first argument, and also two optional arguments, which specify parsing options (see <>) and input data encoding (see <>). The path has the target operating system format, so it can be a relative or absolute one, it should have the delimiters of the target system, it should have the exact case if the target file system is case-sensitive, etc. File path is passed to the system file opening function as is in case of the first function (which accepts `const char* path`); the second function either uses a special file opening function if it is provided by the runtime library or converts the path to UTF-8 and uses the system file opening function. @@ -580,7 +580,7 @@ This is an example of loading XML document from file (link:samples/load_file.cpp [source,indent=0] ---- -include::samples/load_file.cpp[tags=code] +include::samples/load_file.cpp[tags=code] ---- [[loading.memory]] @@ -616,25 +616,25 @@ This is an example of loading XML document from memory using different functions [source,indent=0] ---- -include::samples/load_memory.cpp[tags=decl] +include::samples/load_memory.cpp[tags=decl] ---- [source,indent=0] ---- -include::samples/load_memory.cpp[tags=load_buffer] +include::samples/load_memory.cpp[tags=load_buffer] ---- [source,indent=0] ---- -include::samples/load_memory.cpp[tags=load_buffer_inplace_begin] +include::samples/load_memory.cpp[tags=load_buffer_inplace_begin] -include::samples/load_memory.cpp[tags=load_buffer_inplace_end] +include::samples/load_memory.cpp[tags=load_buffer_inplace_end] ---- [source,indent=0] ---- -include::samples/load_memory.cpp[tags=load_buffer_inplace_own] +include::samples/load_memory.cpp[tags=load_buffer_inplace_own] ---- [source,indent=0] ---- -include::samples/load_memory.cpp[tags=load_string] +include::samples/load_memory.cpp[tags=load_string] ---- [[loading.stream]] @@ -657,7 +657,7 @@ This is a simple example of loading XML document from file using streams (link:s [source,indent=0] ---- -include::samples/load_stream.cpp[tags=code] +include::samples/load_stream.cpp[tags=code] ---- [[loading.errors]] @@ -718,7 +718,7 @@ This is an example of handling loading errors (link:samples/load_error_handling. [source,indent=0] ---- -include::samples/load_error_handling.cpp[tags=code] +include::samples/load_error_handling.cpp[tags=code] ---- [[loading.options]] @@ -777,7 +777,7 @@ This is an example of using different parsing options (link:samples/load_options [source,indent=0] ---- -include::samples/load_options.cpp[tags=code] +include::samples/load_options.cpp[tags=code] ---- [[loading.encoding]] @@ -838,7 +838,7 @@ pugixml features an extensive interface for getting various types of data from t [[xml_node::parent]][[xml_node::first_child]][[xml_node::last_child]][[xml_node::next_sibling]][[xml_node::previous_sibling]][[xml_node::first_attribute]][[xml_node::last_attribute]][[xml_attribute::next_attribute]][[xml_attribute::previous_attribute]] The internal representation of the document is a tree, where each node has a list of child nodes (the order of children corresponds to their order in the XML representation), and additionally element nodes have a list of attributes, which is also ordered. Several functions are provided in order to let you get from one node in the tree to the other. These functions roughly correspond to the internal representation, and thus are usually building blocks for other methods of traversing (i.e. XPath traversals are based on these functions). - + [source] ---- xml_node xml_node::parent() const; @@ -863,7 +863,7 @@ With these functions, you can iterate through all child nodes and display all at [source,indent=0] ---- -include::samples/traverse_base.cpp[tags=basic] +include::samples/traverse_base.cpp[tags=basic] ---- [[access.nodedata]] @@ -922,7 +922,7 @@ It returns `def` argument if the attribute handle is null. If you do not specify [[xml_attribute::as_int]][[xml_attribute::as_uint]][[xml_attribute::as_double]][[xml_attribute::as_float]][[xml_attribute::as_bool]][[xml_attribute::as_llong]][[xml_attribute::as_ullong]] In many cases attribute values have types that are not strings - i.e. an attribute may always contain values that should be treated as integers, despite the fact that they are represented as strings in XML. pugixml provides several accessors that convert attribute value to some other type: - + [source] ---- int xml_attribute::as_int(int def = 0) const; @@ -949,7 +949,7 @@ This is an example of using these functions, along with node data retrieval ones [source,indent=0] ---- -include::samples/traverse_base.cpp[tags=data] +include::samples/traverse_base.cpp[tags=data] ---- [[access.contents]] @@ -992,7 +992,7 @@ This is an example of using these functions (link:samples/traverse_base.cpp[]): [source,indent=0] ---- -include::samples/traverse_base.cpp[tags=contents] +include::samples/traverse_base.cpp[tags=contents] ---- [[access.rangefor]] @@ -1014,7 +1014,7 @@ This is an example of using these functions (link:samples/traverse_rangefor.cpp[ [source,indent=0] ---- -include::samples/traverse_rangefor.cpp[tags=code] +include::samples/traverse_rangefor.cpp[tags=code] ---- [[access.iterators]] @@ -1047,7 +1047,7 @@ Here is an example of using iterators for document traversal (link:samples/trave [source,indent=0] ---- -include::samples/traverse_iter.cpp[tags=code] +include::samples/traverse_iter.cpp[tags=code] ---- CAUTION: Node and attribute iterators are somewhere in the middle between const and non-const iterators. While dereference operation yields a non-constant reference to the object, so that you can use it for tree modification operations, modifying this reference using assignment - i.e. passing iterators to a function like `std::sort` - will not give expected results, as assignment modifies local handle that's stored in the iterator. @@ -1089,11 +1089,11 @@ This is an example of traversing tree hierarchy with xml_tree_walker (link:sampl [source,indent=0] ---- -include::samples/traverse_walker.cpp[tags=impl] +include::samples/traverse_walker.cpp[tags=impl] ---- [source,indent=0] ---- -include::samples/traverse_walker.cpp[tags=traverse] +include::samples/traverse_walker.cpp[tags=traverse] ---- [[access.predicate]] @@ -1121,11 +1121,11 @@ This is an example of using predicate-based functions (link:samples/traverse_pre [source,indent=0] ---- -include::samples/traverse_predicate.cpp[tags=decl] +include::samples/traverse_predicate.cpp[tags=decl] ---- [source,indent=0] ---- -include::samples/traverse_predicate.cpp[tags=find] +include::samples/traverse_predicate.cpp[tags=find] ---- [[access.text]] @@ -1136,7 +1136,7 @@ It is common to store data as text contents of some node - i.e. ``, node `` has path `"a/b/c"`; calling `first_element_by_path` for document with path `"a/b"` results in node ``; calling `first_element_by_path` for node `` with path `"../a/./b/../."` results in node ``; calling `first_element_by_path` with path `"/a"` results in node `` for any node. -In case path component is ambiguous (if there are two nodes with given name), the first one is selected; paths are not guaranteed to uniquely identify nodes in a document. If any component of a path is not found, the result of `first_element_by_path` is null node; also `first_element_by_path` returns null node for null nodes, in which case the path does not matter. `path` returns an empty string for null nodes. +In case path component is ambiguous (if there are two nodes with given name), the first one is selected; paths are not guaranteed to uniquely identify nodes in a document. If any component of a path is not found, the result of `first_element_by_path` is null node; also `first_element_by_path` returns null node for null nodes, in which case the path does not matter. `path` returns an empty string for null nodes. NOTE: `path` function returns the result as STL string, and thus is not available if <> is defined. @@ -1261,7 +1261,7 @@ This is an example of setting node name and value (link:samples/modify_base.cpp[ [source,indent=0] ---- -include::samples/modify_base.cpp[tags=node] +include::samples/modify_base.cpp[tags=node] ---- [[modify.attrdata]] @@ -1290,7 +1290,7 @@ bool xml_attribute::set_value(bool rhs); bool xml_attribute::set_value(long long rhs); bool xml_attribute::set_value(unsigned long long rhs); ---- - + The above functions convert the argument to string and then call the base `set_value` function. Integers are converted to a decimal form, floating-point numbers are converted to either decimal or scientific form, depending on the number magnitude, boolean values are converted to either `"true"` or `"false"`. CAUTION: Number conversion functions depend on current C locale as set with `setlocale`, so may generate unexpected results if the locale is different from `"C"`. @@ -1319,7 +1319,7 @@ This is an example of setting attribute name and value (link:samples/modify_base [source,indent=0] ---- -include::samples/modify_base.cpp[tags=attr] +include::samples/modify_base.cpp[tags=attr] ---- [[modify.add]] @@ -1368,7 +1368,7 @@ This is an example of adding new attributes/nodes to the document (link:samples/ [source,indent=0] ---- -include::samples/modify_add.cpp[tags=code] +include::samples/modify_add.cpp[tags=code] ---- [[modify.remove]] @@ -1405,7 +1405,7 @@ This is an example of removing attributes/nodes from the document (link:samples/ [source,indent=0] ---- -include::samples/modify_remove.cpp[tags=code] +include::samples/modify_remove.cpp[tags=code] ---- [[modify.text]] @@ -1436,7 +1436,7 @@ bool xml_text::set(bool rhs); bool xml_text::set(long long rhs); bool xml_text::set(unsigned long long rhs); ---- - + The above functions convert the argument to string and then call the base `set` function. These functions have the same semantics as similar `xml_attribute` functions. You can <> for details. [[xml_text::assign]] @@ -1461,7 +1461,7 @@ This is an example of using `xml_text` object to modify text contents (link:samp [source,indent=0] ---- -include::samples/text.cpp[tags=modify] +include::samples/text.cpp[tags=modify] ---- [[modify.clone]] @@ -1497,7 +1497,7 @@ This is an example with one possible implementation of include tags in XML (link [source,indent=0] ---- -include::samples/include.cpp[tags=code] +include::samples/include.cpp[tags=code] ---- [[modify.move]] @@ -1600,7 +1600,7 @@ This is a simple example of saving XML document to file (link:samples/save_file. [source,indent=0] ---- -include::samples/save_file.cpp[tags=code] +include::samples/save_file.cpp[tags=code] ---- [[saving.stream]] @@ -1624,7 +1624,7 @@ This is a simple example of saving XML document to standard output (link:samples [source,indent=0] ---- -include::samples/save_stream.cpp[tags=code] +include::samples/save_stream.cpp[tags=code] ---- [[saving.writer]] @@ -1652,7 +1652,7 @@ This is a simple example of custom writer for saving document data to STL string [source,indent=0] ---- -include::samples/save_custom_writer.cpp[tags=code] +include::samples/save_custom_writer.cpp[tags=code] ---- [[saving.subtree]] @@ -1674,7 +1674,7 @@ Saving a subtree differs from saving the whole document: the process behaves as [source,indent=0] ---- -include::samples/save_subtree.cpp[tags=code] +include::samples/save_subtree.cpp[tags=code] ---- [[saving.options]] @@ -1711,7 +1711,7 @@ This is an example that shows the outputs of different output options (link:samp [source,indent=0] ---- -include::samples/save_options.cpp[tags=code] +include::samples/save_options.cpp[tags=code] ---- [[saving.encoding]] @@ -1738,7 +1738,7 @@ This is an example that shows how to create a custom declaration node (link:samp [source,indent=0] ---- -include::samples/save_declaration.cpp[tags=code] +include::samples/save_declaration.cpp[tags=code] ---- [[xpath]] @@ -1872,7 +1872,7 @@ This is an example of selecting nodes using XPath expressions (link:samples/xpat [source,indent=0] ---- -include::samples/xpath_select.cpp[tags=code] +include::samples/xpath_select.cpp[tags=code] ---- [[xpath.query]] @@ -1927,7 +1927,7 @@ Note that `evaluate_string` function returns the STL string; as such, it's not a size_t xpath_query::evaluate_string(char_t* buffer, size_t capacity, const xpath_node& n) const; ---- -This function evaluates the string, and then writes the result to `buffer` (but at most `capacity` characters); then it returns the full size of the result in characters, including the terminating zero. If `capacity` is not 0, the resulting buffer is always zero-terminated. You can use this function as follows: +This function evaluates the string, and then writes the result to `buffer` (but at most `capacity` characters); then it returns the full size of the result in characters, including the terminating zero. If `capacity` is not 0, the resulting buffer is always zero-terminated. You can use this function as follows: * First call the function with `buffer = 0` and `capacity = 0`; then allocate the returned amount of characters, and call the function again, passing the allocated storage and the amount of characters; * First call the function with small buffer and buffer capacity; then, if the result is larger than the capacity, the output has been trimmed, so allocate a larger buffer and call the function again. @@ -1936,7 +1936,7 @@ This is an example of using query objects (link:samples/xpath_query.cpp[]): [source,indent=0] ---- -include::samples/xpath_query.cpp[tags=code] +include::samples/xpath_query.cpp[tags=code] ---- [[xpath.variables]] @@ -2040,7 +2040,7 @@ This is an example of using variables in XPath queries (link:samples/xpath_varia [source,indent=0] ---- -include::samples/xpath_variables.cpp[tags=code] +include::samples/xpath_variables.cpp[tags=code] ---- [[xpath.errors]] @@ -2064,7 +2064,7 @@ If exceptions are disabled, then in the event of parsing failure the query is in ---- const xpath_parse_result& xpath_query::result() const; ---- - + Without exceptions, evaluating invalid query results in `false`, empty string, `NaN` or an empty node set, depending on the type; evaluating a query as a node set results in an empty node set if the return type is not node set. [[xpath_parse_result]] @@ -2098,7 +2098,7 @@ This is an example of XPath error handling (link:samples/xpath_error.cpp[]): [source,indent=0] ---- -include::samples/xpath_error.cpp[tags=code] +include::samples/xpath_error.cpp[tags=code] ---- [[xpath.w3c]] @@ -2618,7 +2618,7 @@ const unsigned int +++parse_embed_pcdata+++ const unsigned int +++parse_wconv_attribute+++ const unsigned int +++parse_wnorm_attribute+++ ---- - + [[apiref.classes]] === Classes diff --git a/docs/quickstart.adoc b/docs/quickstart.adoc index 41a169b..3fe29b1 100644 --- a/docs/quickstart.adoc +++ b/docs/quickstart.adoc @@ -24,7 +24,7 @@ https://github.com/zeux/pugixml/releases/download/v{version}/pugixml-{version}.t The distribution contains library source, documentation (the guide you're reading now and the manual) and some code examples. After downloading the distribution, install pugixml by extracting all files from the compressed archive. The complete pugixml source consists of three files - one source file, `pugixml.cpp`, and two header files, `pugixml.hpp` and `pugiconfig.hpp`. `pugixml.hpp` is the primary header which you need to include in order to use pugixml classes/functions. The rest of this guide assumes that `pugixml.hpp` is either in the current directory or in one of include directories of your projects, so that `#include "pugixml.hpp"` can find the header; however you can also use relative path (i.e. `#include "../libs/pugixml/src/pugixml.hpp"`) or include directory-relative path (i.e. `#include `). - + The easiest way to build pugixml is to compile the source file, `pugixml.cpp`, along with the existing library/executable. This process depends on the method of building your application; for example, if you're using Microsoft Visual Studio footnote:[All trademarks used are properties of their respective owners.], Apple Xcode, Code::Blocks or any other IDE, just add `pugixml.cpp` to one of your projects. There are other building methods available, including building pugixml as a standalone static/shared library; link:manual/install.html#install.building[read the manual] for further information. [[dom]] @@ -67,7 +67,7 @@ This is an example of loading XML document from file (link:samples/load_file.cpp [source,indent=0] ---- -include::samples/load_file.cpp[tags=code] +include::samples/load_file.cpp[tags=code] ---- `load_file`, as well as other loading functions, destroys the existing document tree and then tries to load the new tree from the specified file. The result of the operation is returned in an `xml_parse_result` object; this object contains the operation status, and the related information (i.e. last successfully parsed position in the input file, if parsing fails). @@ -78,7 +78,7 @@ This is an example of handling loading errors (link:samples/load_error_handling. [source,indent=0] ---- -include::samples/load_error_handling.cpp[tags=code] +include::samples/load_error_handling.cpp[tags=code] ---- Sometimes XML data should be loaded from some other source than file, i.e. HTTP URL; also you may want to load XML data from file using non-standard functions, i.e. to use your virtual file system facilities or to load XML from gzip-compressed files. These scenarios either require loading document from memory, in which case you should prepare a contiguous memory block with all XML data and to pass it to one of buffer loading functions, or loading document from C{plus}{plus} IOstream, in which case you should provide an object which implements `std::istream` or `std::wistream` interface. @@ -280,7 +280,7 @@ OTHER DEALINGS IN THE SOFTWARE. .... This means that you can freely use pugixml in your applications, both open-source and proprietary. If you use pugixml in a product, it is sufficient to add an acknowledgment like this to the product distribution: - + .... This software is based on pugixml library (http://pugixml.org). pugixml is Copyright (C) 2006-2016 Arseny Kapoulkine. diff --git a/docs/samples/include.cpp b/docs/samples/include.cpp index 39830c5..84f9dd0 100644 --- a/docs/samples/include.cpp +++ b/docs/samples/include.cpp @@ -48,7 +48,7 @@ bool preprocess(pugi::xml_node node) bool load_preprocess(pugi::xml_document& doc, const char* path) { pugi::xml_parse_result result = doc.load_file(path, pugi::parse_default | pugi::parse_pi); // for - + return result ? preprocess(doc) : false; } // end::code[] diff --git a/docs/samples/save_declaration.cpp b/docs/samples/save_declaration.cpp index 7ca1e07..ca98dcb 100644 --- a/docs/samples/save_declaration.cpp +++ b/docs/samples/save_declaration.cpp @@ -15,7 +15,7 @@ int main() decl.append_attribute("encoding") = "UTF-8"; decl.append_attribute("standalone") = "no"; - // + // // // hey // diff --git a/scripts/CMakeLists.txt b/scripts/CMakeLists.txt index 82f7adb..bb16870 100644 --- a/scripts/CMakeLists.txt +++ b/scripts/CMakeLists.txt @@ -8,7 +8,7 @@ set(BUILD_DEFINES "" CACHE STRING "Build defines") if(MSVC) option(STATIC_CRT "Use static CRT libraries" OFF) - + # Rewrite command line flags to use /MT if necessary if(STATIC_CRT) foreach(flag_var @@ -47,7 +47,7 @@ endif() set_target_properties(pugixml PROPERTIES VERSION 1.7 SOVERSION 1) -install(TARGETS pugixml EXPORT pugixml-config +install(TARGETS pugixml EXPORT pugixml-config ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} diff --git a/src/pugiconfig.hpp b/src/pugiconfig.hpp index a5167b8..59a3a32 100644 --- a/src/pugiconfig.hpp +++ b/src/pugiconfig.hpp @@ -62,7 +62,7 @@ * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND diff --git a/src/pugixml.cpp b/src/pugixml.cpp index e234926..ad6fbc2 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -54,7 +54,7 @@ #endif #ifdef __INTEL_COMPILER -# pragma warning(disable: 177) // function was declared but never referenced +# pragma warning(disable: 177) // function was declared but never referenced # pragma warning(disable: 279) // controlling expression is constant # pragma warning(disable: 1478 1786) // function was declared "deprecated" # pragma warning(disable: 1684) // conversion from pointer to same-sized integral type @@ -82,7 +82,7 @@ #elif defined(__GNUC__) # define PUGI__NO_INLINE __attribute__((noinline)) #else -# define PUGI__NO_INLINE +# define PUGI__NO_INLINE #endif // Branch weight controls @@ -213,7 +213,7 @@ PUGI__NS_BEGIN for (size_t i = 0; i < count; ++i) if (lhs[i] != rhs[i]) return false; - + return lhs[count] == 0; } @@ -617,7 +617,7 @@ PUGI__NS_BEGIN // allocate memory for string and header block size_t size = sizeof(xml_memory_string_header) + length * sizeof(char_t); - + // round size up to block alignment boundary size_t full_size = (size + (xml_memory_block_alignment - 1)) & ~(xml_memory_block_alignment - 1); @@ -1844,7 +1844,7 @@ PUGI__NS_BEGIN ctx_digit = 8, // 0-9 ctx_symbol = 16 // Any symbol > 127, a-z, A-Z, 0-9, _, -, . }; - + static const unsigned char chartypex_table[256] = { 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 2, 3, 3, 2, 3, 3, // 0-15 @@ -1866,7 +1866,7 @@ PUGI__NS_BEGIN 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20 }; - + #ifdef PUGIXML_WCHAR_MODE #define PUGI__IS_CHARTYPE_IMPL(c, ct, table) ((static_cast(c) < 128 ? table[static_cast(c)] : table[128]) & (ct)) #else @@ -1889,7 +1889,7 @@ PUGI__NS_BEGIN if (sizeof(wchar_t) == 2) return is_little_endian() ? encoding_utf16_le : encoding_utf16_be; - else + else return is_little_endian() ? encoding_utf32_le : encoding_utf32_be; } @@ -2193,12 +2193,12 @@ PUGI__NS_BEGIN // convert to utf8 uint8_t* begin = reinterpret_cast(buffer); uint8_t* end = wchar_decoder::process(str, length, begin, utf8_writer()); - + assert(begin + size == end); (void)!end; (void)!size; } - + #ifndef PUGIXML_NO_STL PUGI__FN std::string as_utf8_impl(const wchar_t* str, size_t length) { @@ -2266,7 +2266,7 @@ PUGI__NS_BEGIN xml_allocator* alloc = PUGI__GETPAGE_IMPL(header)->allocator; if (header & header_mask) alloc->deallocate_string(dest); - + // mark the string as not allocated dest = 0; header &= ~header_mask; @@ -2278,7 +2278,7 @@ PUGI__NS_BEGIN // we can reuse old buffer, so just copy the new data (including zero terminator) memcpy(dest, source, source_length * sizeof(char_t)); dest[source_length] = 0; - + return true; } else @@ -2297,7 +2297,7 @@ PUGI__NS_BEGIN // deallocate old buffer (*after* the above to protect against overlapping memory and/or allocation failures) if (header & header_mask) alloc->deallocate_string(dest); - + // the string is now allocated, so set the flag dest = buf; header |= header_mask; @@ -2310,11 +2310,11 @@ PUGI__NS_BEGIN { char_t* end; size_t size; - + gap(): end(0), size(0) { } - + // Push new gap, move s count bytes further (skipping the gap). // Collapse previous gap. void push(char_t*& s, size_t count) @@ -2325,14 +2325,14 @@ PUGI__NS_BEGIN assert(s >= end); memmove(end - size, end, reinterpret_cast(s) - reinterpret_cast(end)); } - + s += count; // end of current gap - + // "merge" two gaps end = s; size += count; } - + // Collapse all gaps, return past-the-end pointer char_t* flush(char_t* s) { @@ -2347,7 +2347,7 @@ PUGI__NS_BEGIN else return s; } }; - + PUGI__FN char_t* strconv_escape(char_t* s, gap& g) { char_t* stre = s + 1; @@ -2379,7 +2379,7 @@ PUGI__NS_BEGIN ch = *++stre; } - + ++stre; } else // &#... (dec code) @@ -2399,7 +2399,7 @@ PUGI__NS_BEGIN ch = *++stre; } - + ++stre; } @@ -2408,7 +2408,7 @@ PUGI__NS_BEGIN #else s = reinterpret_cast(utf8_writer::any(reinterpret_cast(s), ucsc)); #endif - + g.push(s, stre - s); return stre; } @@ -2423,7 +2423,7 @@ PUGI__NS_BEGIN { *s++ = '&'; ++stre; - + g.push(s, stre - s); return stre; } @@ -2448,7 +2448,7 @@ PUGI__NS_BEGIN { *s++ = '>'; ++stre; - + g.push(s, stre - s); return stre; } @@ -2461,7 +2461,7 @@ PUGI__NS_BEGIN { *s++ = '<'; ++stre; - + g.push(s, stre - s); return stre; } @@ -2474,7 +2474,7 @@ PUGI__NS_BEGIN { *s++ = '"'; ++stre; - + g.push(s, stre - s); return stre; } @@ -2484,7 +2484,7 @@ PUGI__NS_BEGIN default: break; } - + return stre; } @@ -2504,21 +2504,21 @@ PUGI__NS_BEGIN PUGI__FN char_t* strconv_comment(char_t* s, char_t endch) { gap g; - + while (true) { PUGI__SCANWHILE_UNROLL(!PUGI__IS_CHARTYPE(ss, ct_parse_comment)); - + if (*s == '\r') // Either a single 0x0d or 0x0d 0x0a pair { *s++ = '\n'; // replace first one with 0x0a - + if (*s == '\n') g.push(s, 1); } else if (s[0] == '-' && s[1] == '-' && PUGI__ENDSWITH(s[2], '>')) // comment ends here { *g.flush(s) = 0; - + return s + (s[2] == '>' ? 3 : 2); } else if (*s == 0) @@ -2532,21 +2532,21 @@ PUGI__NS_BEGIN PUGI__FN char_t* strconv_cdata(char_t* s, char_t endch) { gap g; - + while (true) { PUGI__SCANWHILE_UNROLL(!PUGI__IS_CHARTYPE(ss, ct_parse_cdata)); - + if (*s == '\r') // Either a single 0x0d or 0x0d 0x0a pair { *s++ = '\n'; // replace first one with 0x0a - + if (*s == '\n') g.push(s, 1); } else if (s[0] == ']' && s[1] == ']' && PUGI__ENDSWITH(s[2], '>')) // CDATA ends here { *g.flush(s) = 0; - + return s + 1; } else if (*s == 0) @@ -2556,9 +2556,9 @@ PUGI__NS_BEGIN else ++s; } } - + typedef char_t* (*strconv_pcdata_t)(char_t*); - + template struct strconv_pcdata_impl { static char_t* parse(char_t* s) @@ -2580,13 +2580,13 @@ PUGI__NS_BEGIN --end; *end = 0; - + return s + 1; } else if (opt_eol::value && *s == '\r') // Either a single 0x0d or 0x0d 0x0a pair { *s++ = '\n'; // replace first one with 0x0a - + if (*s == '\n') g.push(s, 1); } else if (opt_escape::value && *s == '&') @@ -2609,7 +2609,7 @@ PUGI__NS_BEGIN } } }; - + PUGI__FN strconv_pcdata_t get_strconv_pcdata(unsigned int optmask) { PUGI__STATIC_ASSERT(parse_escapes == 0x10 && parse_eol == 0x20 && parse_trim_pcdata == 0x0800); @@ -2629,7 +2629,7 @@ PUGI__NS_BEGIN } typedef char_t* (*strconv_attribute_t)(char_t*, char_t); - + template struct strconv_attribute_impl { static char_t* parse_wnorm(char_t* s, char_t end_quote) @@ -2640,35 +2640,35 @@ PUGI__NS_BEGIN if (PUGI__IS_CHARTYPE(*s, ct_space)) { char_t* str = s; - + do ++str; while (PUGI__IS_CHARTYPE(*str, ct_space)); - + g.push(s, str - s); } while (true) { PUGI__SCANWHILE_UNROLL(!PUGI__IS_CHARTYPE(ss, ct_parse_attr_ws | ct_space)); - + if (*s == end_quote) { char_t* str = g.flush(s); - + do *str-- = 0; while (PUGI__IS_CHARTYPE(*str, ct_space)); - + return s + 1; } else if (PUGI__IS_CHARTYPE(*s, ct_space)) { *s++ = ' '; - + if (PUGI__IS_CHARTYPE(*s, ct_space)) { char_t* str = s + 1; while (PUGI__IS_CHARTYPE(*str, ct_space)) ++str; - + g.push(s, str - s); } } @@ -2691,11 +2691,11 @@ PUGI__NS_BEGIN while (true) { PUGI__SCANWHILE_UNROLL(!PUGI__IS_CHARTYPE(ss, ct_parse_attr_ws)); - + if (*s == end_quote) { *g.flush(s) = 0; - + return s + 1; } else if (PUGI__IS_CHARTYPE(*s, ct_space)) @@ -2703,7 +2703,7 @@ PUGI__NS_BEGIN if (*s == '\r') { *s++ = ' '; - + if (*s == '\n') g.push(s, 1); } else *s++ = ' '; @@ -2727,17 +2727,17 @@ PUGI__NS_BEGIN while (true) { PUGI__SCANWHILE_UNROLL(!PUGI__IS_CHARTYPE(ss, ct_parse_attr)); - + if (*s == end_quote) { *g.flush(s) = 0; - + return s + 1; } else if (*s == '\r') { *s++ = '\n'; - + if (*s == '\n') g.push(s, 1); } else if (opt_escape::value && *s == '&') @@ -2759,11 +2759,11 @@ PUGI__NS_BEGIN while (true) { PUGI__SCANWHILE_UNROLL(!PUGI__IS_CHARTYPE(ss, ct_parse_attr)); - + if (*s == end_quote) { *g.flush(s) = 0; - + return s + 1; } else if (opt_escape::value && *s == '&') @@ -2782,7 +2782,7 @@ PUGI__NS_BEGIN PUGI__FN strconv_attribute_t get_strconv_attribute(unsigned int optmask) { PUGI__STATIC_ASSERT(parse_escapes == 0x10 && parse_eol == 0x20 && parse_wconv_attribute == 0x40 && parse_wnorm_attribute == 0x80); - + switch ((optmask >> 4) & 15) // get bitmask for flags (wconv wnorm eol escapes) { case 0: return strconv_attribute_impl::parse_simple; @@ -2820,7 +2820,7 @@ PUGI__NS_BEGIN xml_allocator* alloc_state; char_t* error_offset; xml_parse_status error_status; - + xml_parser(xml_allocator* alloc_): alloc(*alloc_), alloc_state(alloc_), error_offset(0), error_status(status_ok) { } @@ -3154,7 +3154,7 @@ PUGI__NS_BEGIN { strconv_attribute_t strconv_attribute = get_strconv_attribute(optmsk); strconv_pcdata_t strconv_pcdata = get_strconv_pcdata(optmsk); - + char_t ch = 0; xml_node_struct* cursor = root; char_t* mark = s; @@ -3185,7 +3185,7 @@ PUGI__NS_BEGIN while (true) { PUGI__SKIPWS(); // Eat any whitespace. - + if (PUGI__IS_CHARTYPE(*s, ct_start_symbol)) // <... #... { xml_attribute_struct* a = append_new_attribute(cursor, alloc); // Make space for this attribute. @@ -3203,7 +3203,7 @@ PUGI__NS_BEGIN ch = *s; ++s; } - + if (ch == '=') // '<... #=...' { PUGI__SKIPWS(); // Eat any whitespace. @@ -3215,7 +3215,7 @@ PUGI__NS_BEGIN a->value = s; // Save the offset. s = strconv_attribute(s, ch); - + if (!s) PUGI__THROW_ERROR(status_bad_attribute, a->value); // After this line the loop continues from the start; @@ -3230,7 +3230,7 @@ PUGI__NS_BEGIN else if (*s == '/') { ++s; - + if (*s == '>') { PUGI__POPNODE(); @@ -3271,7 +3271,7 @@ PUGI__NS_BEGIN { // we stepped over null terminator, backtrack & handle closing tag --s; - + if (endch != '>') PUGI__THROW_ERROR(status_bad_start_element, s); } else PUGI__THROW_ERROR(status_bad_start_element, s); @@ -3282,7 +3282,7 @@ PUGI__NS_BEGIN char_t* name = cursor->name; if (!name) PUGI__THROW_ERROR(status_end_element_mismatch, s); - + while (PUGI__IS_CHARTYPE(*s, ct_symbol)) { if (*s++ != *name++) PUGI__THROW_ERROR(status_end_element_mismatch, s); @@ -3293,7 +3293,7 @@ PUGI__NS_BEGIN if (*s == 0 && name[0] == endch && name[1] == 0) PUGI__THROW_ERROR(status_bad_end_element, s); else PUGI__THROW_ERROR(status_end_element_mismatch, s); } - + PUGI__POPNODE(); // Pop. PUGI__SKIPWS(); @@ -3347,7 +3347,7 @@ PUGI__NS_BEGIN if (!PUGI__OPTSET(parse_trim_pcdata)) s = mark; - + if (cursor->parent || PUGI__OPTSET(parse_fragment)) { if (PUGI__OPTSET(parse_embed_pcdata) && cursor->parent && !cursor->first_child && !cursor->value) @@ -3364,14 +3364,14 @@ PUGI__NS_BEGIN } s = strconv_pcdata(s); - + if (!*s) break; } else { PUGI__SCANFOR(*s == '<'); // '...<' if (!*s) break; - + ++s; } @@ -3419,14 +3419,14 @@ PUGI__NS_BEGIN // get last child of the root before parsing xml_node_struct* last_root_child = root->first_child ? root->first_child->prev_sibling_c + 0 : 0; - + // create parser on stack xml_parser parser(static_cast(xmldoc)); // save last character and make buffer zero-terminated (speeds up parsing) char_t endch = buffer[length - 1]; buffer[length - 1] = 0; - + // skip BOM to make sure it does not end up as part of parse output char_t* buffer_data = parse_skip_bom(buffer); @@ -3516,7 +3516,7 @@ PUGI__NS_BEGIN { if (length < 1) return 0; - // discard last character if it's the lead of a surrogate pair + // discard last character if it's the lead of a surrogate pair return (sizeof(wchar_t) == 2 && static_cast(static_cast(data[length - 1]) - 0xD800) < 0x400) ? length - 1 : length; } @@ -3529,7 +3529,7 @@ PUGI__NS_BEGIN return length * sizeof(char_t); } - + // convert to utf8 if (encoding == encoding_utf8) return convert_buffer_output_generic(r_u8, data, length, wchar_decoder(), utf8_writer()); @@ -3817,10 +3817,10 @@ PUGI__NS_BEGIN while (*s) { const char_t* prev = s; - + // While *s is a usual symbol PUGI__SCANWHILE_UNROLL(!PUGI__IS_CHARTYPEX(ss, type)); - + writer.write_buffer(prev, static_cast(s - prev)); switch (*s) @@ -4567,7 +4567,7 @@ PUGI__NS_BEGIN return set_value_ascii(dest, header, header_mask, buf); } - + template PUGI__FN bool set_value_convert(String& dest, Header& header, uintptr_t header_mask, bool value) { @@ -4656,7 +4656,7 @@ PUGI__NS_BEGIN // check for I/O errors if (length < 0) return status_io_error; - + // check for overflow size_t result = static_cast(length); @@ -4669,7 +4669,7 @@ PUGI__NS_BEGIN } // This function assumes that buffer has extra sizeof(char_t) writable bytes after size - PUGI__FN size_t zero_terminate_buffer(void* buffer, size_t size, xml_encoding encoding) + PUGI__FN size_t zero_terminate_buffer(void* buffer, size_t size, xml_encoding encoding) { // We only need to zero-terminate if encoding conversion does not do it for us #ifdef PUGIXML_WCHAR_MODE @@ -4701,7 +4701,7 @@ PUGI__NS_BEGIN size_t size = 0; xml_parse_status size_status = get_file_size(file, size); if (size_status != status_ok) return make_parse_result(size_status); - + size_t max_suffix_size = sizeof(char_t); // allocate buffer for the whole file @@ -4729,7 +4729,7 @@ PUGI__NS_BEGIN { void* memory = xml_memory::allocate(sizeof(xml_stream_chunk)); if (!memory) return 0; - + return new (memory) xml_stream_chunk(); } @@ -4839,7 +4839,7 @@ PUGI__NS_BEGIN // return buffer size_t actual_length = static_cast(stream.gcount()); assert(actual_length <= read_length); - + *out_buffer = buffer.release(); *out_size = actual_length * sizeof(T); @@ -4867,7 +4867,7 @@ PUGI__NS_BEGIN if (status != status_ok) return make_parse_result(status); xml_encoding real_encoding = get_buffer_encoding(encoding, buffer, size); - + return load_buffer_impl(doc, doc, buffer, zero_terminate_buffer(buffer, size, real_encoding), options, real_encoding, true, true, out_buffer); } #endif @@ -4987,7 +4987,7 @@ namespace pugi PUGI__FN xml_tree_walker::xml_tree_walker(): _depth(0) { } - + PUGI__FN xml_tree_walker::~xml_tree_walker() { } @@ -5033,7 +5033,7 @@ namespace pugi { return (_attr == r._attr); } - + PUGI__FN bool xml_attribute::operator!=(const xml_attribute& r) const { return (_attr != r._attr); @@ -5043,17 +5043,17 @@ namespace pugi { return (_attr < r._attr); } - + PUGI__FN bool xml_attribute::operator>(const xml_attribute& r) const { return (_attr > r._attr); } - + PUGI__FN bool xml_attribute::operator<=(const xml_attribute& r) const { return (_attr <= r._attr); } - + PUGI__FN bool xml_attribute::operator>=(const xml_attribute& r) const { return (_attr >= r._attr); @@ -5141,7 +5141,7 @@ namespace pugi set_value(rhs); return *this; } - + PUGI__FN xml_attribute& xml_attribute::operator=(int rhs) { set_value(rhs); @@ -5159,7 +5159,7 @@ namespace pugi set_value(rhs); return *this; } - + PUGI__FN xml_attribute& xml_attribute::operator=(float rhs) { set_value(rhs); @@ -5189,10 +5189,10 @@ namespace pugi PUGI__FN bool xml_attribute::set_name(const char_t* rhs) { if (!_attr) return false; - + return impl::strcpy_insitu(_attr->name, _attr->header, impl::xml_memory_page_name_allocated_mask, rhs, impl::strlength(rhs)); } - + PUGI__FN bool xml_attribute::set_value(const char_t* rhs) { if (!_attr) return false; @@ -5220,7 +5220,7 @@ namespace pugi return impl::set_value_convert(_attr->value, _attr->header, impl::xml_memory_page_value_allocated_mask, rhs); } - + PUGI__FN bool xml_attribute::set_value(float rhs) { if (!_attr) return false; @@ -5270,7 +5270,7 @@ namespace pugi PUGI__FN xml_node::xml_node(xml_node_struct* p): _root(p) { } - + PUGI__FN static void unspecified_bool_xml_node(xml_node***) { } @@ -5294,7 +5294,7 @@ namespace pugi { return iterator(0, _root); } - + PUGI__FN xml_node::attribute_iterator xml_node::attributes_begin() const { return attribute_iterator(_root ? _root->first_attribute + 0 : 0, _root); @@ -5304,7 +5304,7 @@ namespace pugi { return attribute_iterator(0, _root); } - + PUGI__FN xml_object_range xml_node::children() const { return xml_object_range(begin(), end()); @@ -5334,17 +5334,17 @@ namespace pugi { return (_root < r._root); } - + PUGI__FN bool xml_node::operator>(const xml_node& r) const { return (_root > r._root); } - + PUGI__FN bool xml_node::operator<=(const xml_node& r) const { return (_root <= r._root); } - + PUGI__FN bool xml_node::operator>=(const xml_node& r) const { return (_root >= r._root); @@ -5354,7 +5354,7 @@ namespace pugi { return !_root; } - + PUGI__FN const char_t* xml_node::name() const { return (_root && _root->name) ? _root->name + 0 : PUGIXML_TEXT(""); @@ -5364,12 +5364,12 @@ namespace pugi { return _root ? PUGI__NODETYPE(_root) : node_null; } - + PUGI__FN const char_t* xml_node::value() const { return (_root && _root->value) ? _root->value + 0 : PUGIXML_TEXT(""); } - + PUGI__FN xml_node xml_node::child(const char_t* name_) const { if (!_root) return xml_node(); @@ -5387,14 +5387,14 @@ namespace pugi for (xml_attribute_struct* i = _root->first_attribute; i; i = i->next_attribute) if (i->name && impl::strequal(name_, i->name)) return xml_attribute(i); - + return xml_attribute(); } - + PUGI__FN xml_node xml_node::next_sibling(const char_t* name_) const { if (!_root) return xml_node(); - + for (xml_node_struct* i = _root->next_sibling; i; i = i->next_sibling) if (i->name && impl::strequal(name_, i->name)) return xml_node(i); @@ -5409,7 +5409,7 @@ namespace pugi PUGI__FN xml_node xml_node::previous_sibling(const char_t* name_) const { if (!_root) return xml_node(); - + for (xml_node_struct* i = _root->prev_sibling_c; i->next_sibling; i = i->prev_sibling_c) if (i->name && impl::strequal(name_, i->name)) return xml_node(i); @@ -5452,7 +5452,7 @@ namespace pugi PUGI__FN xml_node xml_node::previous_sibling() const { if (!_root) return xml_node(); - + if (_root->prev_sibling_c->next_sibling) return xml_node(_root->prev_sibling_c); else return xml_node(); } @@ -5475,7 +5475,7 @@ namespace pugi PUGI__FN const char_t* xml_node::child_value() const { if (!_root) return PUGIXML_TEXT(""); - + // element nodes can have value if parse_embed_pcdata was used if (PUGI__NODETYPE(_root) == node_element && _root->value) return _root->value; @@ -5521,7 +5521,7 @@ namespace pugi return impl::strcpy_insitu(_root->name, _root->header, impl::xml_memory_page_name_allocated_mask, rhs, impl::strlength(rhs)); } - + PUGI__FN bool xml_node::set_value(const char_t* rhs) { xml_node_type type_ = _root ? PUGI__NODETYPE(_root) : node_null; @@ -5535,7 +5535,7 @@ namespace pugi PUGI__FN xml_attribute xml_node::append_attribute(const char_t* name_) { if (!impl::allow_insert_attribute(type())) return xml_attribute(); - + impl::xml_allocator& alloc = impl::get_allocator(_root); if (!alloc.reserve()) return xml_attribute(); @@ -5545,14 +5545,14 @@ namespace pugi impl::append_attribute(a._attr, _root); a.set_name(name_); - + return a; } PUGI__FN xml_attribute xml_node::prepend_attribute(const char_t* name_) { if (!impl::allow_insert_attribute(type())) return xml_attribute(); - + impl::xml_allocator& alloc = impl::get_allocator(_root); if (!alloc.reserve()) return xml_attribute(); @@ -5570,7 +5570,7 @@ namespace pugi { if (!impl::allow_insert_attribute(type())) return xml_attribute(); if (!attr || !impl::is_attribute_of(attr._attr, _root)) return xml_attribute(); - + impl::xml_allocator& alloc = impl::get_allocator(_root); if (!alloc.reserve()) return xml_attribute(); @@ -5588,7 +5588,7 @@ namespace pugi { if (!impl::allow_insert_attribute(type())) return xml_attribute(); if (!attr || !impl::is_attribute_of(attr._attr, _root)) return xml_attribute(); - + impl::xml_allocator& alloc = impl::get_allocator(_root); if (!alloc.reserve()) return xml_attribute(); @@ -5675,7 +5675,7 @@ namespace pugi PUGI__FN xml_node xml_node::append_child(xml_node_type type_) { if (!impl::allow_insert_child(type(), type_)) return xml_node(); - + impl::xml_allocator& alloc = impl::get_allocator(_root); if (!alloc.reserve()) return xml_node(); @@ -5695,12 +5695,12 @@ namespace pugi impl::xml_allocator& alloc = impl::get_allocator(_root); if (!alloc.reserve()) return xml_node(); - + xml_node n(impl::allocate_node(alloc, type_)); if (!n) return xml_node(); impl::prepend_node(n._root, _root); - + if (type_ == node_declaration) n.set_name(PUGIXML_TEXT("xml")); return n; @@ -5713,7 +5713,7 @@ namespace pugi impl::xml_allocator& alloc = impl::get_allocator(_root); if (!alloc.reserve()) return xml_node(); - + xml_node n(impl::allocate_node(alloc, type_)); if (!n) return xml_node(); @@ -5731,7 +5731,7 @@ namespace pugi impl::xml_allocator& alloc = impl::get_allocator(_root); if (!alloc.reserve()) return xml_node(); - + xml_node n(impl::allocate_node(alloc, type_)); if (!n) return xml_node(); @@ -5963,7 +5963,7 @@ namespace pugi // disable document_buffer_order optimization since in a document with multiple buffers comparing buffer pointers does not make sense doc->header |= impl::xml_memory_page_contents_shared_mask; - + // get extra buffer element (we'll store the document fragment buffer there so that we can deallocate it later) impl::xml_memory_page* page = 0; impl::xml_extra_buffer* extra = static_cast(doc->allocate_memory(sizeof(impl::xml_extra_buffer), page)); @@ -5985,7 +5985,7 @@ namespace pugi PUGI__FN xml_node xml_node::find_child_by_attribute(const char_t* name_, const char_t* attr_name, const char_t* attr_value) const { if (!_root) return xml_node(); - + for (xml_node_struct* i = _root->first_child; i; i = i->next_sibling) if (i->name && impl::strequal(name_, i->name)) { @@ -6000,7 +6000,7 @@ namespace pugi PUGI__FN xml_node xml_node::find_child_by_attribute(const char_t* attr_name, const char_t* attr_value) const { if (!_root) return xml_node(); - + for (xml_node_struct* i = _root->first_child; i; i = i->next_sibling) for (xml_attribute_struct* a = i->first_attribute; a; a = a->next_attribute) if (a->name && impl::strequal(attr_name, a->name) && impl::strequal(attr_value, a->value ? a->value + 0 : PUGIXML_TEXT(""))) @@ -6095,22 +6095,22 @@ namespace pugi PUGI__FN bool xml_node::traverse(xml_tree_walker& walker) { walker._depth = -1; - + xml_node arg_begin = *this; if (!walker.begin(arg_begin)) return false; xml_node cur = first_child(); - + if (cur) { ++walker._depth; - do + do { xml_node arg_for_each = cur; if (!walker.for_each(arg_for_each)) return false; - + if (cur.first_child()) { ++walker._depth; @@ -6126,7 +6126,7 @@ namespace pugi --walker._depth; cur = cur.parent(); } - + if (cur != *this) cur = cur.next_sibling(); } @@ -6475,7 +6475,7 @@ namespace pugi { return _wrap._root == rhs._wrap._root && _parent._root == rhs._parent._root; } - + PUGI__FN bool xml_node_iterator::operator!=(const xml_node_iterator& rhs) const { return _wrap._root != rhs._wrap._root || _parent._root != rhs._parent._root; @@ -6536,7 +6536,7 @@ namespace pugi { return _wrap._attr == rhs._wrap._attr && _parent._root == rhs._parent._root; } - + PUGI__FN bool xml_attribute_iterator::operator!=(const xml_attribute_iterator& rhs) const { return _wrap._attr != rhs._wrap._attr || _parent._root != rhs._parent._root; @@ -6952,14 +6952,14 @@ namespace pugi { return impl::as_utf8_impl(str.c_str(), str.size()); } - + PUGI__FN std::basic_string PUGIXML_FUNCTION as_wide(const char* str) { assert(str); return impl::as_wide_impl(str, strlen(str)); } - + PUGI__FN std::basic_string PUGIXML_FUNCTION as_wide(const std::string& str) { return impl::as_wide_impl(str.c_str(), str.size()); @@ -7091,7 +7091,7 @@ PUGI__NS_BEGIN if (begin == end) return begin; // last written element - I write = begin++; + I write = begin++; // merge unique elements while (begin != end) @@ -7266,7 +7266,7 @@ PUGI__NS_BEGIN static const uintptr_t xpath_memory_block_alignment = sizeof(double) > sizeof(void*) ? sizeof(double) : sizeof(void*); struct xpath_memory_block - { + { xpath_memory_block* next; size_t capacity; @@ -7276,7 +7276,7 @@ PUGI__NS_BEGIN double alignment; }; }; - + class xpath_allocator { xpath_memory_block* _root; @@ -7293,7 +7293,7 @@ PUGI__NS_BEGIN error_handler = 0; #endif } - + void* allocate_nothrow(size_t size) { // round size up to block alignment boundary @@ -7316,13 +7316,13 @@ PUGI__NS_BEGIN xpath_memory_block* block = static_cast(xml_memory::allocate(block_size)); if (!block) return 0; - + block->next = _root; block->capacity = block_capacity; - + _root = block; _root_size = size; - + return block->data; } } @@ -7570,7 +7570,7 @@ PUGI__NS_BEGIN { return _uses_heap ? _length_heap : strlength(_buffer); } - + char_t* data(xpath_allocator* alloc) { // make private heap copy @@ -7660,7 +7660,7 @@ PUGI__NS_BEGIN case node_comment: case node_pi: return xpath_string::from_const(n.value()); - + case node_document: case node_element: { @@ -7671,7 +7671,7 @@ PUGI__NS_BEGIN result.append(xpath_string::from_const(n.value()), alloc); xml_node cur = n.first_child(); - + while (cur && cur != n) { if (cur.type() == node_pcdata || cur.type() == node_cdata) @@ -7689,16 +7689,16 @@ PUGI__NS_BEGIN if (cur != n) cur = cur.next_sibling(); } } - + return result; } - + default: return xpath_string(); } } } - + PUGI__FN bool node_is_before_sibling(xml_node_struct* ln, xml_node_struct* rn) { assert(ln->parent == rn->parent); @@ -7722,7 +7722,7 @@ PUGI__NS_BEGIN // if rn sibling chain ended ln must be before rn return !rs; } - + PUGI__FN bool node_is_before(xml_node_struct* ln, xml_node_struct* rn) { // find common ancestor at the same depth, if any @@ -7803,7 +7803,7 @@ PUGI__NS_BEGIN return 0; } - + struct document_order_comparator { bool operator()(const xpath_node& lhs, const xpath_node& rhs) const @@ -7827,10 +7827,10 @@ PUGI__NS_BEGIN for (xml_attribute a = lhs.attribute(); a; a = a.next_attribute()) if (a == rhs.attribute()) return true; - + return false; } - + // compare attribute parents ln = lhs.parent(); rn = rhs.parent(); @@ -7839,21 +7839,21 @@ PUGI__NS_BEGIN { // attributes go after the parent element if (lhs.parent() == rhs.node()) return false; - + ln = lhs.parent(); } else if (rhs.attribute()) { // attributes go after the parent element if (rhs.parent() == lhs.node()) return true; - + rn = rhs.parent(); } if (ln == rn) return false; if (!ln || !rn) return ln < rn; - + return node_is_before(ln.internal_object(), rn.internal_object()); } }; @@ -7866,7 +7866,7 @@ PUGI__NS_BEGIN else return rhs.attribute() ? false : lhs.node() < rhs.node(); } }; - + PUGI__FN double gen_nan() { #if defined(__STDC_IEC_559__) || ((FLT_RADIX - 0 == 2) && (FLT_MAX_EXP - 0 == 128) && (FLT_MANT_DIG - 0 == 24)) @@ -7881,7 +7881,7 @@ PUGI__NS_BEGIN return zero / zero; #endif } - + PUGI__FN bool is_nan(double value) { #if defined(PUGI__MSVC_CRT_VERSION) || defined(__BORLANDC__) @@ -7894,7 +7894,7 @@ PUGI__NS_BEGIN return v != v; #endif } - + PUGI__FN const char_t* convert_number_to_string_special(double value) { #if defined(PUGI__MSVC_CRT_VERSION) || defined(__BORLANDC__) @@ -7926,12 +7926,12 @@ PUGI__NS_BEGIN return 0; #endif } - + PUGI__FN bool convert_number_to_boolean(double value) { return (value != 0 && !is_nan(value)); } - + PUGI__FN void truncate_zeros(char* begin, char* end) { while (begin != end && end[-1] == '0') end--; @@ -8052,7 +8052,7 @@ PUGI__NS_BEGIN return xpath_string::from_heap_preallocated(result, s); } - + PUGI__FN bool check_string_to_number_format(const char_t* string) { // parse leading whitespace @@ -8119,7 +8119,7 @@ PUGI__NS_BEGIN return true; } - + PUGI__FN double round_nearest(double value) { return floor(value + 0.5); @@ -8131,17 +8131,17 @@ PUGI__NS_BEGIN // ceil is used to differentiate between +0 and -0 (we return -0 for [-0.5, -0] and +0 for +0) return (value >= -0.5 && value <= 0) ? ceil(value) : floor(value + 0.5); } - + PUGI__FN const char_t* qualified_name(const xpath_node& node) { return node.attribute() ? node.attribute().name() : node.node().name(); } - + PUGI__FN const char_t* local_name(const xpath_node& node) { const char_t* name = qualified_name(node); const char_t* p = find_char(name, ':'); - + return p ? p + 1 : name; } @@ -8171,39 +8171,39 @@ PUGI__NS_BEGIN PUGI__FN const char_t* namespace_uri(xml_node node) { namespace_uri_predicate pred = node.name(); - + xml_node p = node; - + while (p) { xml_attribute a = p.find_attribute(pred); - + if (a) return a.value(); - + p = p.parent(); } - + return PUGIXML_TEXT(""); } PUGI__FN const char_t* namespace_uri(xml_attribute attr, xml_node parent) { namespace_uri_predicate pred = attr.name(); - + // Default namespace does not apply to attributes if (!pred.prefix) return PUGIXML_TEXT(""); - + xml_node p = parent; - + while (p) { xml_attribute a = p.find_attribute(pred); - + if (a) return a.value(); - + p = p.parent(); } - + return PUGIXML_TEXT(""); } @@ -8389,11 +8389,11 @@ PUGI__NS_BEGIN result += result << 10; result ^= result >> 6; } - + result += result << 3; result ^= result >> 11; result += result << 15; - + return result; } @@ -8547,9 +8547,9 @@ PUGI__NS_BEGIN else type = sorted; } - + if (type != order) reverse(begin, end); - + return order; } @@ -8662,7 +8662,7 @@ PUGI__NS_BEGIN { if (_type == xpath_node_set::type_unsorted) sort(_begin, _end, duplicate_comparator()); - + _end = unique(_begin, _end); } @@ -8770,12 +8770,12 @@ PUGI__NS_BEGIN { next(); } - + const char_t* state() const { return _cur; } - + void next() { const char_t* cur = _cur; @@ -8790,7 +8790,7 @@ PUGI__NS_BEGIN case 0: _cur_lexeme = lex_eof; break; - + case '>': if (*(cur+1) == '=') { @@ -8834,7 +8834,7 @@ PUGI__NS_BEGIN _cur_lexeme = lex_equal; break; - + case '+': cur += 1; _cur_lexeme = lex_plus; @@ -8858,7 +8858,7 @@ PUGI__NS_BEGIN _cur_lexeme = lex_union; break; - + case '$': cur += 1; @@ -8876,7 +8876,7 @@ PUGI__NS_BEGIN } _cur_lexeme_contents.end = cur; - + _cur_lexeme = lex_var_ref; } else @@ -8897,7 +8897,7 @@ PUGI__NS_BEGIN _cur_lexeme = lex_close_brace; break; - + case '[': cur += 1; _cur_lexeme = lex_open_square_brace; @@ -8928,7 +8928,7 @@ PUGI__NS_BEGIN _cur_lexeme = lex_slash; } break; - + case '.': if (*(cur+1) == '.') { @@ -8944,7 +8944,7 @@ PUGI__NS_BEGIN while (PUGI__IS_CHARTYPEX(*cur, ctx_digit)) cur++; _cur_lexeme_contents.end = cur; - + _cur_lexeme = lex_number; } else @@ -8970,7 +8970,7 @@ PUGI__NS_BEGIN _cur_lexeme_contents.begin = cur; while (*cur && *cur != terminator) cur++; _cur_lexeme_contents.end = cur; - + if (!*cur) _cur_lexeme = lex_none; else @@ -9000,7 +9000,7 @@ PUGI__NS_BEGIN _cur_lexeme_contents.begin = cur; while (PUGI__IS_CHARTYPEX(*cur, ctx_digit)) cur++; - + if (*cur == '.') { cur++; @@ -9033,7 +9033,7 @@ PUGI__NS_BEGIN } _cur_lexeme_contents.end = cur; - + _cur_lexeme = lex_string; } else @@ -9144,7 +9144,7 @@ PUGI__NS_BEGIN axis_preceding_sibling, axis_self }; - + enum nodetest_t { nodetest_none, @@ -9179,7 +9179,7 @@ PUGI__NS_BEGIN }; template const axis_t axis_to_type::axis = N; - + class xpath_ast_node { private: @@ -9498,7 +9498,7 @@ PUGI__NS_BEGIN return true; } break; - + case nodetest_type_node: case nodetest_all: if (is_xpath_attribute(name)) @@ -9507,7 +9507,7 @@ PUGI__NS_BEGIN return true; } break; - + case nodetest_all_in_namespace: if (starts_with(name, _data.nodetest) && is_xpath_attribute(name)) { @@ -9515,14 +9515,14 @@ PUGI__NS_BEGIN return true; } break; - + default: ; } return false; } - + bool step_push(xpath_node_set_raw& ns, xml_node_struct* n, xpath_allocator* alloc) { assert(n); @@ -9538,11 +9538,11 @@ PUGI__NS_BEGIN return true; } break; - + case nodetest_type_node: ns.push_back(xml_node(n), alloc); return true; - + case nodetest_type_comment: if (type == node_comment) { @@ -9550,7 +9550,7 @@ PUGI__NS_BEGIN return true; } break; - + case nodetest_type_text: if (type == node_pcdata || type == node_cdata) { @@ -9558,7 +9558,7 @@ PUGI__NS_BEGIN return true; } break; - + case nodetest_type_pi: if (type == node_pi) { @@ -9566,7 +9566,7 @@ PUGI__NS_BEGIN return true; } break; - + case nodetest_pi: if (type == node_pi && n->name && strequal(n->name, _data.nodetest)) { @@ -9574,7 +9574,7 @@ PUGI__NS_BEGIN return true; } break; - + case nodetest_all: if (type == node_element) { @@ -9582,7 +9582,7 @@ PUGI__NS_BEGIN return true; } break; - + case nodetest_all_in_namespace: if (type == node_element && n->name && starts_with(n->name, _data.nodetest)) { @@ -9609,33 +9609,33 @@ PUGI__NS_BEGIN for (xml_attribute_struct* a = n->first_attribute; a; a = a->next_attribute) if (step_push(ns, a, n, alloc) & once) return; - + break; } - + case axis_child: { for (xml_node_struct* c = n->first_child; c; c = c->next_sibling) if (step_push(ns, c, alloc) & once) return; - + break; } - + case axis_descendant: case axis_descendant_or_self: { if (axis == axis_descendant_or_self) if (step_push(ns, n, alloc) & once) return; - + xml_node_struct* cur = n->first_child; - + while (cur) { if (step_push(ns, cur, alloc) & once) return; - + if (cur->first_child) cur = cur->first_child; else @@ -9646,32 +9646,32 @@ PUGI__NS_BEGIN if (cur == n) return; } - + cur = cur->next_sibling; } } - + break; } - + case axis_following_sibling: { for (xml_node_struct* c = n->next_sibling; c; c = c->next_sibling) if (step_push(ns, c, alloc) & once) return; - + break; } - + case axis_preceding_sibling: { for (xml_node_struct* c = n->prev_sibling_c; c->next_sibling; c = c->prev_sibling_c) if (step_push(ns, c, alloc) & once) return; - + break; } - + case axis_following: { xml_node_struct* cur = n; @@ -9750,7 +9750,7 @@ PUGI__NS_BEGIN break; } - + case axis_ancestor: case axis_ancestor_or_self: { @@ -9759,15 +9759,15 @@ PUGI__NS_BEGIN return; xml_node_struct* cur = n->parent; - + while (cur) { if (step_push(ns, cur, alloc) & once) return; - + cur = cur->parent; } - + break; } @@ -9785,12 +9785,12 @@ PUGI__NS_BEGIN break; } - + default: assert(false && "Unimplemented axis"); } } - + template void step_fill(xpath_node_set_raw& ns, xml_attribute_struct* a, xml_node_struct* p, xpath_allocator* alloc, bool once, T v) { const axis_t axis = T::axis; @@ -9805,15 +9805,15 @@ PUGI__NS_BEGIN return; xml_node_struct* cur = p; - + while (cur) { if (step_push(ns, cur, alloc) & once) return; - + cur = cur->parent; } - + break; } @@ -9829,7 +9829,7 @@ PUGI__NS_BEGIN case axis_following: { xml_node_struct* cur = p; - + while (cur) { if (cur->first_child) @@ -9866,7 +9866,7 @@ PUGI__NS_BEGIN step_fill(ns, p, alloc, once, v); break; } - + default: assert(false && "Unimplemented axis"); } @@ -9910,7 +9910,7 @@ PUGI__NS_BEGIN // in general, all axes generate elements in a particular order, but there is no order guarantee if axis is applied to two nodes if (axis != axis_self && size != 0) ns.set_type(xpath_node_set::type_unsorted); - + step_fill(ns, *it, stack.result, once, v); if (_right) apply_predicates(ns, size, stack, eval); } @@ -9928,7 +9928,7 @@ PUGI__NS_BEGIN return ns; } - + public: xpath_ast_node(ast_type_t type, xpath_value_type rettype_, const char_t* value): _type(static_cast(type)), _rettype(static_cast(rettype_)), _axis(0), _test(0), _left(0), _right(0), _next(0) @@ -9943,14 +9943,14 @@ PUGI__NS_BEGIN assert(type == ast_number_constant); _data.number = value; } - + xpath_ast_node(ast_type_t type, xpath_value_type rettype_, xpath_variable* value): _type(static_cast(type)), _rettype(static_cast(rettype_)), _axis(0), _test(0), _left(0), _right(0), _next(0) { assert(type == ast_variable); _data.variable = value; } - + xpath_ast_node(ast_type_t type, xpath_value_type rettype_, xpath_ast_node* left = 0, xpath_ast_node* right = 0): _type(static_cast(type)), _rettype(static_cast(rettype_)), _axis(0), _test(0), _left(left), _right(right), _next(0) { @@ -9985,25 +9985,25 @@ PUGI__NS_BEGIN { case ast_op_or: return _left->eval_boolean(c, stack) || _right->eval_boolean(c, stack); - + case ast_op_and: return _left->eval_boolean(c, stack) && _right->eval_boolean(c, stack); - + case ast_op_equal: return compare_eq(_left, _right, c, stack, equal_to()); case ast_op_not_equal: return compare_eq(_left, _right, c, stack, not_equal_to()); - + case ast_op_less: return compare_rel(_left, _right, c, stack, less()); - + case ast_op_greater: return compare_rel(_right, _left, c, stack, less()); case ast_op_less_or_equal: return compare_rel(_left, _right, c, stack, less_equal()); - + case ast_op_greater_or_equal: return compare_rel(_right, _left, c, stack, less_equal()); @@ -10029,43 +10029,43 @@ PUGI__NS_BEGIN case ast_func_boolean: return _left->eval_boolean(c, stack); - + case ast_func_not: return !_left->eval_boolean(c, stack); - + case ast_func_true: return true; - + case ast_func_false: return false; case ast_func_lang: { if (c.n.attribute()) return false; - + xpath_allocator_capture cr(stack.result); xpath_string lang = _left->eval_string(c, stack); - + for (xml_node n = c.n.node(); n; n = n.parent()) { xml_attribute a = n.attribute(PUGIXML_TEXT("xml:lang")); - + if (a) { const char_t* value = a.value(); - + // strnicmp / strncasecmp is not portable for (const char_t* lit = lang.c_str(); *lit; ++lit) { if (tolower_ascii(*lit) != tolower_ascii(*value)) return false; ++value; } - + return *value == 0 || *value == '-'; } } - + return false; } @@ -10094,15 +10094,15 @@ PUGI__NS_BEGIN { case xpath_type_number: return convert_number_to_boolean(eval_number(c, stack)); - + case xpath_type_string: { xpath_allocator_capture cr(stack.result); return !eval_string(c, stack).empty(); } - - case xpath_type_node_set: + + case xpath_type_node_set: { xpath_allocator_capture cr(stack.result); @@ -10123,7 +10123,7 @@ PUGI__NS_BEGIN { case ast_op_add: return _left->eval_number(c, stack) + _right->eval_number(c, stack); - + case ast_op_subtract: return _left->eval_number(c, stack) - _right->eval_number(c, stack); @@ -10144,7 +10144,7 @@ PUGI__NS_BEGIN case ast_func_last: return static_cast(c.size); - + case ast_func_position: return static_cast(c.position); @@ -10154,28 +10154,28 @@ PUGI__NS_BEGIN return static_cast(_left->eval_node_set(c, stack, nodeset_eval_all).size()); } - + case ast_func_string_length_0: { xpath_allocator_capture cr(stack.result); return static_cast(string_value(c.n, stack.result).length()); } - + case ast_func_string_length_1: { xpath_allocator_capture cr(stack.result); return static_cast(_left->eval_string(c, stack).length()); } - + case ast_func_number_0: { xpath_allocator_capture cr(stack.result); return convert_string_to_number(string_value(c.n, stack.result).c_str()); } - + case ast_func_number_1: return _left->eval_number(c, stack); @@ -10184,36 +10184,36 @@ PUGI__NS_BEGIN xpath_allocator_capture cr(stack.result); double r = 0; - + xpath_node_set_raw ns = _left->eval_node_set(c, stack, nodeset_eval_all); - + for (const xpath_node* it = ns.begin(); it != ns.end(); ++it) { xpath_allocator_capture cri(stack.result); r += convert_string_to_number(string_value(*it, stack.result).c_str()); } - + return r; } case ast_func_floor: { double r = _left->eval_number(c, stack); - + return r == r ? floor(r) : r; } case ast_func_ceiling: { double r = _left->eval_number(c, stack); - + return r == r ? ceil(r) : r; } case ast_func_round: return round_nearest_nzero(_left->eval_number(c, stack)); - + case ast_variable: { assert(_rettype == _data.variable->type()); @@ -10230,30 +10230,30 @@ PUGI__NS_BEGIN { case xpath_type_boolean: return eval_boolean(c, stack) ? 1 : 0; - + case xpath_type_string: { xpath_allocator_capture cr(stack.result); return convert_string_to_number(eval_string(c, stack).c_str()); } - + case xpath_type_node_set: { xpath_allocator_capture cr(stack.result); return convert_string_to_number(eval_string(c, stack).c_str()); } - + default: assert(false && "Wrong expression for return type number"); return 0; } - + } } } - + xpath_string eval_string_concat(const xpath_context& c, const xpath_stack& stack) { assert(_type == ast_func_concat); @@ -10309,11 +10309,11 @@ PUGI__NS_BEGIN { case ast_string_constant: return xpath_string::from_const(_data.string); - + case ast_func_local_name_0: { xpath_node na = c.n; - + return xpath_string::from_const(local_name(na)); } @@ -10323,14 +10323,14 @@ PUGI__NS_BEGIN xpath_node_set_raw ns = _left->eval_node_set(c, stack, nodeset_eval_first); xpath_node na = ns.first(); - + return xpath_string::from_const(local_name(na)); } case ast_func_name_0: { xpath_node na = c.n; - + return xpath_string::from_const(qualified_name(na)); } @@ -10340,14 +10340,14 @@ PUGI__NS_BEGIN xpath_node_set_raw ns = _left->eval_node_set(c, stack, nodeset_eval_first); xpath_node na = ns.first(); - + return xpath_string::from_const(qualified_name(na)); } case ast_func_namespace_uri_0: { xpath_node na = c.n; - + return xpath_string::from_const(namespace_uri(na)); } @@ -10357,7 +10357,7 @@ PUGI__NS_BEGIN xpath_node_set_raw ns = _left->eval_node_set(c, stack, nodeset_eval_first); xpath_node na = ns.first(); - + return xpath_string::from_const(namespace_uri(na)); } @@ -10380,10 +10380,10 @@ PUGI__NS_BEGIN xpath_string p = _right->eval_string(c, swapped_stack); const char_t* pos = find_substring(s.c_str(), p.c_str()); - + return pos ? xpath_string::from_heap(s.c_str(), pos, stack.result) : xpath_string(); } - + case ast_func_substring_after: { xpath_allocator_capture cr(stack.temp); @@ -10392,7 +10392,7 @@ PUGI__NS_BEGIN xpath_string s = _left->eval_string(c, swapped_stack); xpath_string p = _right->eval_string(c, swapped_stack); - + const char_t* pos = find_substring(s.c_str(), p.c_str()); if (!pos) return xpath_string(); @@ -10412,19 +10412,19 @@ PUGI__NS_BEGIN size_t s_length = s.length(); double first = round_nearest(_right->eval_number(c, stack)); - + if (is_nan(first)) return xpath_string(); // NaN else if (first >= s_length + 1) return xpath_string(); - + size_t pos = first < 1 ? 1 : static_cast(first); assert(1 <= pos && pos <= s_length + 1); const char_t* rbegin = s.c_str() + (pos - 1); const char_t* rend = s.c_str() + s.length(); - + return s.uses_heap() ? xpath_string::from_heap(rbegin, rend, stack.result) : xpath_string::from_const(rbegin); } - + case ast_func_substring_3: { xpath_allocator_capture cr(stack.temp); @@ -10436,12 +10436,12 @@ PUGI__NS_BEGIN double first = round_nearest(_right->eval_number(c, stack)); double last = first + round_nearest(_right->_next->eval_number(c, stack)); - + if (is_nan(first) || is_nan(last)) return xpath_string(); else if (first >= s_length + 1) return xpath_string(); else if (first >= last) return xpath_string(); else if (last < 1) return xpath_string(); - + size_t pos = first < 1 ? 1 : static_cast(first); size_t end = last >= s_length + 1 ? s_length + 1 : static_cast(last); @@ -10468,7 +10468,7 @@ PUGI__NS_BEGIN char_t* begin = s.data(stack.result); char_t* end = normalize_space(begin); - + return xpath_string::from_heap_preallocated(begin, end); } @@ -10514,10 +10514,10 @@ PUGI__NS_BEGIN { case xpath_type_boolean: return xpath_string::from_const(eval_boolean(c, stack) ? PUGIXML_TEXT("true") : PUGIXML_TEXT("false")); - + case xpath_type_number: return convert_number_to_string(eval_number(c, stack), stack.result); - + case xpath_type_node_set: { xpath_allocator_capture cr(stack.temp); @@ -10527,7 +10527,7 @@ PUGI__NS_BEGIN xpath_node_set_raw ns = eval_node_set(c, swapped_stack, nodeset_eval_first); return ns.empty() ? xpath_string() : string_value(ns.first(), stack.result); } - + default: assert(false && "Wrong expression for return type string"); return xpath_string(); @@ -10568,20 +10568,20 @@ PUGI__NS_BEGIN bool once = eval_once(set.type(), eval); apply_predicate(set, 0, stack, once); - + return set; } - + case ast_func_id: return xpath_node_set_raw(); - + case ast_step: { switch (_axis) { case axis_ancestor: return step_do(c, stack, eval, axis_to_type()); - + case axis_ancestor_or_self: return step_do(c, stack, eval, axis_to_type()); @@ -10590,7 +10590,7 @@ PUGI__NS_BEGIN case axis_child: return step_do(c, stack, eval, axis_to_type()); - + case axis_descendant: return step_do(c, stack, eval, axis_to_type()); @@ -10599,23 +10599,23 @@ PUGI__NS_BEGIN case axis_following: return step_do(c, stack, eval, axis_to_type()); - + case axis_following_sibling: return step_do(c, stack, eval, axis_to_type()); - + case axis_namespace: // namespaced axis is not supported return xpath_node_set_raw(); - + case axis_parent: return step_do(c, stack, eval, axis_to_type()); - + case axis_preceding: return step_do(c, stack, eval, axis_to_type()); case axis_preceding_sibling: return step_do(c, stack, eval, axis_to_type()); - + case axis_self: return step_do(c, stack, eval, axis_to_type()); @@ -10732,7 +10732,7 @@ PUGI__NS_BEGIN _type = ast_opt_compare_attribute; } } - + bool is_posinv_expr() const { switch (_type) @@ -10756,10 +10756,10 @@ PUGI__NS_BEGIN default: if (_left && !_left->is_posinv_expr()) return false; - + for (xpath_ast_node* n = _right; n; n = n->_next) if (!n->is_posinv_expr()) return false; - + return true; } } @@ -10865,9 +10865,9 @@ PUGI__NS_BEGIN case 'b': if (name == PUGIXML_TEXT("boolean") && argc == 1) return new (alloc_node()) xpath_ast_node(ast_func_boolean, xpath_type_boolean, args[0]); - + break; - + case 'c': if (name == PUGIXML_TEXT("count") && argc == 1) { @@ -10880,23 +10880,23 @@ PUGI__NS_BEGIN return new (alloc_node()) xpath_ast_node(ast_func_concat, xpath_type_string, args[0], args[1]); else if (name == PUGIXML_TEXT("ceiling") && argc == 1) return new (alloc_node()) xpath_ast_node(ast_func_ceiling, xpath_type_number, args[0]); - + break; - + case 'f': if (name == PUGIXML_TEXT("false") && argc == 0) return new (alloc_node()) xpath_ast_node(ast_func_false, xpath_type_boolean); else if (name == PUGIXML_TEXT("floor") && argc == 1) return new (alloc_node()) xpath_ast_node(ast_func_floor, xpath_type_number, args[0]); - + break; - + case 'i': if (name == PUGIXML_TEXT("id") && argc == 1) return new (alloc_node()) xpath_ast_node(ast_func_id, xpath_type_node_set, args[0]); - + break; - + case 'l': if (name == PUGIXML_TEXT("last") && argc == 0) return new (alloc_node()) xpath_ast_node(ast_func_last, xpath_type_number); @@ -10904,9 +10904,9 @@ PUGI__NS_BEGIN return new (alloc_node()) xpath_ast_node(ast_func_lang, xpath_type_boolean, args[0]); else if (name == PUGIXML_TEXT("local-name") && argc <= 1) return parse_function_helper(ast_func_local_name_0, ast_func_local_name_1, argc, args); - + break; - + case 'n': if (name == PUGIXML_TEXT("name") && argc <= 1) return parse_function_helper(ast_func_name_0, ast_func_name_1, argc, args); @@ -10918,21 +10918,21 @@ PUGI__NS_BEGIN return new (alloc_node()) xpath_ast_node(ast_func_not, xpath_type_boolean, args[0]); else if (name == PUGIXML_TEXT("number") && argc <= 1) return new (alloc_node()) xpath_ast_node(argc == 0 ? ast_func_number_0 : ast_func_number_1, xpath_type_number, args[0]); - + break; - + case 'p': if (name == PUGIXML_TEXT("position") && argc == 0) return new (alloc_node()) xpath_ast_node(ast_func_position, xpath_type_number); - + break; - + case 'r': if (name == PUGIXML_TEXT("round") && argc == 1) return new (alloc_node()) xpath_ast_node(ast_func_round, xpath_type_number, args[0]); break; - + case 's': if (name == PUGIXML_TEXT("string") && argc <= 1) return new (alloc_node()) xpath_ast_node(argc == 0 ? ast_func_string_0 : ast_func_string_1, xpath_type_string, args[0]); @@ -10953,13 +10953,13 @@ PUGI__NS_BEGIN } break; - + case 't': if (name == PUGIXML_TEXT("translate") && argc == 3) return new (alloc_node()) xpath_ast_node(ast_func_translate, xpath_type_string, args[0], args[1]); else if (name == PUGIXML_TEXT("true") && argc == 0) return new (alloc_node()) xpath_ast_node(ast_func_true, xpath_type_boolean); - + break; default: @@ -10984,37 +10984,37 @@ PUGI__NS_BEGIN return axis_ancestor_or_self; else if (name == PUGIXML_TEXT("attribute")) return axis_attribute; - + break; - + case 'c': if (name == PUGIXML_TEXT("child")) return axis_child; - + break; - + case 'd': if (name == PUGIXML_TEXT("descendant")) return axis_descendant; else if (name == PUGIXML_TEXT("descendant-or-self")) return axis_descendant_or_self; - + break; - + case 'f': if (name == PUGIXML_TEXT("following")) return axis_following; else if (name == PUGIXML_TEXT("following-sibling")) return axis_following_sibling; - + break; - + case 'n': if (name == PUGIXML_TEXT("namespace")) return axis_namespace; - + break; - + case 'p': if (name == PUGIXML_TEXT("parent")) return axis_parent; @@ -11022,13 +11022,13 @@ PUGI__NS_BEGIN return axis_preceding; else if (name == PUGIXML_TEXT("preceding-sibling")) return axis_preceding_sibling; - + break; - + case 's': if (name == PUGIXML_TEXT("self")) return axis_self; - + break; default: @@ -11066,7 +11066,7 @@ PUGI__NS_BEGIN return nodetest_type_text; break; - + default: break; } @@ -11139,12 +11139,12 @@ PUGI__NS_BEGIN { xpath_ast_node* args[2] = {0}; size_t argc = 0; - + xpath_lexer_string function = _lexer.contents(); _lexer.next(); - + xpath_ast_node* last_arg = 0; - + if (_lexer.current() != lex_open_brace) throw_error("Unrecognized function call"); _lexer.next(); @@ -11157,16 +11157,16 @@ PUGI__NS_BEGIN if (_lexer.current() != lex_comma) throw_error("No comma between function arguments"); _lexer.next(); - + xpath_ast_node* n = parse_expression(); - + if (argc < 2) args[argc] = n; else last_arg->set_next(n); argc++; last_arg = n; } - + _lexer.next(); return parse_function(function, argc, args); @@ -11178,7 +11178,7 @@ PUGI__NS_BEGIN return 0; } } - + // FilterExpr ::= PrimaryExpr | FilterExpr Predicate // Predicate ::= '[' PredicateExpr ']' // PredicateExpr ::= Expr @@ -11198,13 +11198,13 @@ PUGI__NS_BEGIN if (_lexer.current() != lex_close_square_brace) throw_error("Unmatched square brace"); - + _lexer.next(); } - + return n; } - + // Step ::= AxisSpecifier NodeTest Predicate* | AbbreviatedStep // AxisSpecifier ::= AxisName '::' | '@'? // NodeTest ::= NameTest | NodeType '(' ')' | 'processing-instruction' '(' Literal ')' @@ -11222,25 +11222,25 @@ PUGI__NS_BEGIN { axis = axis_attribute; axis_specified = true; - + _lexer.next(); } else if (_lexer.current() == lex_dot) { _lexer.next(); - + return new (alloc_node()) xpath_ast_node(ast_step, set, axis_self, nodetest_type_node, 0); } else if (_lexer.current() == lex_double_dot) { _lexer.next(); - + return new (alloc_node()) xpath_ast_node(ast_step, set, axis_parent, nodetest_type_node, 0); } - + nodetest_t nt_type = nodetest_none; xpath_lexer_string nt_name; - + if (_lexer.current() == lex_string) { // node name test @@ -11273,14 +11273,14 @@ PUGI__NS_BEGIN } else throw_error("Unrecognized node test"); } - + if (nt_type == nodetest_none) { // node type test or processing-instruction if (_lexer.current() == lex_open_brace) { _lexer.next(); - + if (_lexer.current() == lex_close_brace) { _lexer.next(); @@ -11288,18 +11288,18 @@ PUGI__NS_BEGIN nt_type = parse_node_test_type(nt_name); if (nt_type == nodetest_none) throw_error("Unrecognized node type"); - + nt_name = xpath_lexer_string(); } else if (nt_name == PUGIXML_TEXT("processing-instruction")) { if (_lexer.current() != lex_quoted_string) throw_error("Only literals are allowed as arguments to processing-instruction()"); - + nt_type = nodetest_pi; nt_name = _lexer.contents(); _lexer.next(); - + if (_lexer.current() != lex_close_brace) throw_error("Unmatched brace near processing-instruction()"); _lexer.next(); @@ -11314,7 +11314,7 @@ PUGI__NS_BEGIN if (nt_name.end - nt_name.begin > 2 && nt_name.end[-2] == ':' && nt_name.end[-1] == '*') // NCName:* { nt_name.end--; // erase * - + nt_type = nodetest_all_in_namespace; } else nt_type = nodetest_name; @@ -11327,37 +11327,37 @@ PUGI__NS_BEGIN _lexer.next(); } else throw_error("Unrecognized node test"); - + xpath_ast_node* n = new (alloc_node()) xpath_ast_node(ast_step, set, axis, nt_type, alloc_string(nt_name)); - + xpath_ast_node* last = 0; - + while (_lexer.current() == lex_open_square_brace) { _lexer.next(); - + xpath_ast_node* expr = parse_expression(); xpath_ast_node* pred = new (alloc_node()) xpath_ast_node(ast_predicate, 0, expr, predicate_default); - + if (_lexer.current() != lex_close_square_brace) throw_error("Unmatched square brace"); _lexer.next(); - + if (last) last->set_next(pred); else n->set_right(pred); - + last = pred; } return n; } - + // RelativeLocationPath ::= Step | RelativeLocationPath '/' Step | RelativeLocationPath '//' Step xpath_ast_node* parse_relative_location_path(xpath_ast_node* set) { xpath_ast_node* n = parse_step(set); - + while (_lexer.current() == lex_slash || _lexer.current() == lex_double_slash) { lexeme_t l = _lexer.current(); @@ -11365,13 +11365,13 @@ PUGI__NS_BEGIN if (l == lex_double_slash) n = new (alloc_node()) xpath_ast_node(ast_step, n, axis_descendant_or_self, nodetest_type_node, 0); - + n = parse_step(n); } - + return n; } - + // LocationPath ::= RelativeLocationPath | AbsoluteLocationPath // AbsoluteLocationPath ::= '/' RelativeLocationPath? | '//' RelativeLocationPath xpath_ast_node* parse_location_path() @@ -11379,7 +11379,7 @@ PUGI__NS_BEGIN if (_lexer.current() == lex_slash) { _lexer.next(); - + xpath_ast_node* n = new (alloc_node()) xpath_ast_node(ast_step_root, xpath_type_node_set); // relative location path can start from axis_attribute, dot, double_dot, multiply and string lexemes; any other lexeme means standalone root path @@ -11393,17 +11393,17 @@ PUGI__NS_BEGIN else if (_lexer.current() == lex_double_slash) { _lexer.next(); - + xpath_ast_node* n = new (alloc_node()) xpath_ast_node(ast_step_root, xpath_type_node_set); n = new (alloc_node()) xpath_ast_node(ast_step, n, axis_descendant_or_self, nodetest_type_node, 0); - + return parse_relative_location_path(n); } // else clause moved outside of if because of bogus warning 'control may reach end of non-void function being inlined' in gcc 4.0.1 return parse_relative_location_path(0); } - + // PathExpr ::= LocationPath // | FilterExpr // | FilterExpr '/' RelativeLocationPath @@ -11419,7 +11419,7 @@ PUGI__NS_BEGIN // '(' in case of it being an expression, string literal, number constant or // function call. - if (_lexer.current() == lex_var_ref || _lexer.current() == lex_open_brace || + if (_lexer.current() == lex_var_ref || _lexer.current() == lex_open_brace || _lexer.current() == lex_quoted_string || _lexer.current() == lex_number || _lexer.current() == lex_string) { @@ -11427,29 +11427,29 @@ PUGI__NS_BEGIN { // This is either a function call, or not - if not, we shall proceed with location path const char_t* state = _lexer.state(); - + while (PUGI__IS_CHARTYPE(*state, ct_space)) ++state; - + if (*state != '(') return parse_location_path(); // This looks like a function call; however this still can be a node-test. Check it. if (parse_node_test_type(_lexer.contents()) != nodetest_none) return parse_location_path(); } - + xpath_ast_node* n = parse_filter_expression(); if (_lexer.current() == lex_slash || _lexer.current() == lex_double_slash) { lexeme_t l = _lexer.current(); _lexer.next(); - + if (l == lex_double_slash) { if (n->rettype() != xpath_type_node_set) throw_error("Step has to be applied to node set"); n = new (alloc_node()) xpath_ast_node(ast_step, n, axis_descendant_or_self, nodetest_type_node, 0); } - + // select from location path return parse_relative_location_path(n); } @@ -11595,13 +11595,13 @@ PUGI__NS_BEGIN xpath_ast_node* parse() { xpath_ast_node* result = parse_expression(); - + if (_lexer.current() != lex_eof) { // there are still unparsed tokens left, error throw_error("Incorrect query"); } - + return result; } @@ -11689,7 +11689,7 @@ namespace pugi { assert(_result.error); } - + PUGI__FN const char* xpath_exception::what() const throw() { return _result.error; @@ -11700,15 +11700,15 @@ namespace pugi return _result; } #endif - + PUGI__FN xpath_node::xpath_node() { } - + PUGI__FN xpath_node::xpath_node(const xml_node& node_): _node(node_) { } - + PUGI__FN xpath_node::xpath_node(const xml_attribute& attribute_, const xml_node& parent_): _node(attribute_ ? parent_ : xml_node()), _attribute(attribute_) { } @@ -11717,12 +11717,12 @@ namespace pugi { return _attribute ? xml_node() : _node; } - + PUGI__FN xml_attribute xpath_node::attribute() const { return _attribute; } - + PUGI__FN xml_node xpath_node::parent() const { return _attribute ? _node : _node.parent(); @@ -11736,7 +11736,7 @@ namespace pugi { return (_node || _attribute) ? unspecified_bool_xpath_node : 0; } - + PUGI__FN bool xpath_node::operator!() const { return !(_node || _attribute); @@ -11746,7 +11746,7 @@ namespace pugi { return _node == n._node && _attribute == n._attribute; } - + PUGI__FN bool xpath_node::operator!=(const xpath_node& n) const { return _node != n._node || _attribute != n._attribute; @@ -11797,7 +11797,7 @@ namespace pugi } memcpy(storage, begin_, size_ * sizeof(xpath_node)); - + // deallocate old buffer if (_begin != &_storage) impl::xml_memory::deallocate(_begin); @@ -11836,12 +11836,12 @@ namespace pugi if (_begin != &_storage) impl::xml_memory::deallocate(_begin); } - + PUGI__FN xpath_node_set::xpath_node_set(const xpath_node_set& ns): _type(type_unsorted), _begin(&_storage), _end(&_storage) { _assign(ns._begin, ns._end, ns._type); } - + PUGI__FN xpath_node_set& xpath_node_set::operator=(const xpath_node_set& ns) { if (this == &ns) return *this; @@ -11874,17 +11874,17 @@ namespace pugi { return _type; } - + PUGI__FN size_t xpath_node_set::size() const { return _end - _begin; } - + PUGI__FN bool xpath_node_set::empty() const { return _begin == _end; } - + PUGI__FN const xpath_node& xpath_node_set::operator[](size_t index) const { assert(index < size()); @@ -11895,12 +11895,12 @@ namespace pugi { return _begin; } - + PUGI__FN xpath_node_set::const_iterator xpath_node_set::end() const { return _end; } - + PUGI__FN void xpath_node_set::sort(bool reverse) { _type = impl::xpath_sort(_begin, _end, _type, reverse); @@ -12280,21 +12280,21 @@ namespace pugi PUGI__FN bool xpath_query::evaluate_boolean(const xpath_node& n) const { if (!_impl) return false; - + impl::xpath_context c(n, 1, 1); impl::xpath_stack_data sd; #ifdef PUGIXML_NO_EXCEPTIONS if (setjmp(sd.error_handler)) return false; #endif - + return static_cast(_impl)->root->eval_boolean(c, sd.stack); } - + PUGI__FN double xpath_query::evaluate_number(const xpath_node& n) const { if (!_impl) return impl::gen_nan(); - + impl::xpath_context c(n, 1, 1); impl::xpath_stack_data sd; @@ -12323,7 +12323,7 @@ namespace pugi impl::xpath_string r = impl::evaluate_string_impl(static_cast(_impl), n, sd); size_t full_size = r.length() + 1; - + if (capacity > 0) { size_t size = (full_size < capacity) ? full_size : capacity; @@ -12332,7 +12332,7 @@ namespace pugi memcpy(buffer, r.c_str(), (size - 1) * sizeof(char_t)); buffer[size - 1] = 0; } - + return full_size; } @@ -12480,7 +12480,7 @@ namespace pugi * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND diff --git a/src/pugixml.hpp b/src/pugixml.hpp index e561490..5d5fe2b 100644 --- a/src/pugixml.hpp +++ b/src/pugixml.hpp @@ -133,13 +133,13 @@ namespace pugi // This flag determines if EOL characters are normalized (converted to #xA) during parsing. This flag is on by default. const unsigned int parse_eol = 0x0020; - + // This flag determines if attribute values are normalized using CDATA normalization rules during parsing. This flag is on by default. const unsigned int parse_wconv_attribute = 0x0040; // This flag determines if attribute values are normalized using NMTOKENS normalization rules during parsing. This flag is off by default. const unsigned int parse_wnorm_attribute = 0x0080; - + // This flag determines if document declaration (node_declaration) is added to the DOM tree. This flag is off by default. const unsigned int parse_declaration = 0x0100; @@ -189,16 +189,16 @@ namespace pugi }; // Formatting flags - + // Indent the nodes that are written to output stream with as many indentation strings as deep the node is in DOM tree. This flag is on by default. const unsigned int format_indent = 0x01; - + // Write encoding-specific BOM to the output stream. This flag is off by default. const unsigned int format_write_bom = 0x02; // Use raw output mode (no indentation and no line breaks are written). This flag is off by default. const unsigned int format_raw = 0x04; - + // Omit default XML declaration even if there is no declaration in the document. This flag is off by default. const unsigned int format_no_declaration = 0x08; @@ -230,7 +230,7 @@ namespace pugi class xml_node; class xml_text; - + #ifndef PUGIXML_NO_XPATH class xpath_node; class xpath_node_set; @@ -304,13 +304,13 @@ namespace pugi private: xml_attribute_struct* _attr; - + typedef void (*unspecified_bool_type)(xml_attribute***); public: // Default constructor. Constructs an empty attribute. xml_attribute(); - + // Constructs attribute from internal pointer explicit xml_attribute(xml_attribute_struct* attr); @@ -422,7 +422,7 @@ namespace pugi // Borland C++ workaround bool operator!() const; - + // Comparison operators (compares wrapped node pointers) bool operator==(const xml_node& r) const; bool operator!=(const xml_node& r) const; @@ -443,7 +443,7 @@ namespace pugi // Get node value, or "" if node is empty or it has no value // Note: For text node.value() does not return "text"! Use child_value() or text() methods to access text inside nodes. const char_t* value() const; - + // Get attribute list xml_attribute first_attribute() const; xml_attribute last_attribute() const; @@ -455,7 +455,7 @@ namespace pugi // Get next/previous sibling in the children list of the parent node xml_node next_sibling() const; xml_node previous_sibling() const; - + // Get parent node xml_node parent() const; @@ -483,7 +483,7 @@ namespace pugi // Set node name/value (returns false if node is empty, there is not enough memory, or node can not have name/value) bool set_name(const char_t* rhs); bool set_value(const char_t* rhs); - + // Add attribute with specified name. Returns added attribute, or empty attribute on errors. xml_attribute append_attribute(const char_t* name); xml_attribute prepend_attribute(const char_t* name); @@ -537,11 +537,11 @@ namespace pugi template xml_attribute find_attribute(Predicate pred) const { if (!_root) return xml_attribute(); - + for (xml_attribute attrib = first_attribute(); attrib; attrib = attrib.next_attribute()) if (pred(attrib)) return attrib; - + return xml_attribute(); } @@ -549,11 +549,11 @@ namespace pugi template xml_node find_child(Predicate pred) const { if (!_root) return xml_node(); - + for (xml_node node = first_child(); node; node = node.next_sibling()) if (pred(node)) return node; - + return xml_node(); } @@ -563,7 +563,7 @@ namespace pugi if (!_root) return xml_node(); xml_node cur = first_child(); - + while (cur._root && cur._root != _root) { if (pred(cur)) return cur; @@ -595,7 +595,7 @@ namespace pugi // Recursively traverse subtree with xml_tree_walker bool traverse(xml_tree_walker& walker); - + #ifndef PUGIXML_NO_XPATH // Select single node by evaluating XPath query. Returns first node from the resulting node set. xpath_node select_node(const char_t* query, xpath_variable_set* variables = 0) const; @@ -610,7 +610,7 @@ namespace pugi xpath_node select_single_node(const xpath_query& query) const; #endif - + // Print subtree using a writer object void print(xml_writer& writer, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, xml_encoding encoding = encoding_auto, unsigned int depth = 0) const; @@ -872,11 +872,11 @@ namespace pugi private: int _depth; - + protected: // Get current traversal depth int depth() const; - + public: xml_tree_walker(); virtual ~xml_tree_walker(); @@ -947,7 +947,7 @@ namespace pugi char_t* _buffer; char _memory[192]; - + // Non-copyable semantics xml_document(const xml_document&); xml_document& operator=(const xml_document&); @@ -1056,7 +1056,7 @@ namespace pugi // Non-copyable semantics xpath_variable(const xpath_variable&); xpath_variable& operator=(const xpath_variable&); - + public: // Get variable name const char_t* name() const; @@ -1152,21 +1152,21 @@ namespace pugi // Get query expression return type xpath_value_type return_type() const; - + // Evaluate expression as boolean value in the specified context; performs type conversion if necessary. // If PUGIXML_NO_EXCEPTIONS is not defined, throws std::bad_alloc on out of memory errors. bool evaluate_boolean(const xpath_node& n) const; - + // Evaluate expression as double value in the specified context; performs type conversion if necessary. // If PUGIXML_NO_EXCEPTIONS is not defined, throws std::bad_alloc on out of memory errors. double evaluate_number(const xpath_node& n) const; - + #ifndef PUGIXML_NO_STL // Evaluate expression as string value in the specified context; performs type conversion if necessary. // If PUGIXML_NO_EXCEPTIONS is not defined, throws std::bad_alloc on out of memory errors. string_t evaluate_string(const xpath_node& n) const; #endif - + // Evaluate expression as string value in the specified context; performs type conversion if necessary. // At most capacity characters are written to the destination buffer, full result size is returned (includes terminating zero). // If PUGIXML_NO_EXCEPTIONS is not defined, throws std::bad_alloc on out of memory errors. @@ -1193,7 +1193,7 @@ namespace pugi // Borland C++ workaround bool operator!() const; }; - + #ifndef PUGIXML_NO_EXCEPTIONS // XPath exception class class PUGIXML_CLASS xpath_exception: public std::exception @@ -1212,20 +1212,20 @@ namespace pugi const xpath_parse_result& result() const; }; #endif - + // XPath node class (either xml_node or xml_attribute) class PUGIXML_CLASS xpath_node { private: xml_node _node; xml_attribute _attribute; - + typedef void (*unspecified_bool_type)(xpath_node***); public: // Default constructor; constructs empty XPath node xpath_node(); - + // Construct XPath node from XML node/attribute xpath_node(const xml_node& node); xpath_node(const xml_attribute& attribute, const xml_node& parent); @@ -1233,13 +1233,13 @@ namespace pugi // Get node/attribute, if any xml_node node() const; xml_attribute attribute() const; - + // Get parent of contained node/attribute xml_node parent() const; // Safe bool conversion operator operator unspecified_bool_type() const; - + // Borland C++ workaround bool operator!() const; @@ -1265,13 +1265,13 @@ namespace pugi type_sorted, // Sorted by document order (ascending) type_sorted_reverse // Sorted by document order (descending) }; - + // Constant iterator type typedef const xpath_node* const_iterator; // We define non-constant iterator to be the same as constant iterator so that various generic algorithms (i.e. boost foreach) work typedef const xpath_node* iterator; - + // Default constructor. Constructs empty set. xpath_node_set(); @@ -1280,7 +1280,7 @@ namespace pugi // Destructor ~xpath_node_set(); - + // Copy constructor/assignment operator xpath_node_set(const xpath_node_set& ns); xpath_node_set& operator=(const xpath_node_set& ns); @@ -1293,31 +1293,31 @@ namespace pugi // Get collection type type_t type() const; - + // Get collection size size_t size() const; // Indexing operator const xpath_node& operator[](size_t index) const; - + // Collection iterators const_iterator begin() const; const_iterator end() const; // Sort the collection in ascending/descending order by document order void sort(bool reverse = false); - + // Get first node in the collection by document order xpath_node first() const; - + // Check if collection is empty bool empty() const; - + private: type_t _type; - + xpath_node _storage; - + xpath_node* _begin; xpath_node* _end; @@ -1330,7 +1330,7 @@ namespace pugi // Convert wide string to UTF8 std::basic_string, std::allocator > PUGIXML_FUNCTION as_utf8(const wchar_t* str); std::basic_string, std::allocator > PUGIXML_FUNCTION as_utf8(const std::basic_string, std::allocator >& str); - + // Convert UTF8 to wide string std::basic_string, std::allocator > PUGIXML_FUNCTION as_wide(const char* str); std::basic_string, std::allocator > PUGIXML_FUNCTION as_wide(const std::basic_string, std::allocator >& str); @@ -1338,13 +1338,13 @@ namespace pugi // Memory allocation function interface; returns pointer to allocated memory or NULL on failure typedef void* (*allocation_function)(size_t size); - + // Memory deallocation function interface typedef void (*deallocation_function)(void* ptr); // Override default memory management functions. All subsequent allocations/deallocations will be performed via supplied functions. void PUGIXML_FUNCTION set_memory_management_functions(allocation_function allocate, deallocation_function deallocate); - + // Get current memory management functions allocation_function PUGIXML_FUNCTION get_memory_allocation_function(); deallocation_function PUGIXML_FUNCTION get_memory_deallocation_function(); @@ -1393,7 +1393,7 @@ namespace std * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND diff --git a/tests/main.cpp b/tests/main.cpp index 00016a6..8eb55ed 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -45,7 +45,7 @@ static void* custom_allocate(size_t size) g_memory_total_size += memory_size(ptr); g_memory_total_count++; - + return ptr; } } @@ -68,7 +68,7 @@ static void custom_deallocate(void* ptr) g_memory_total_size -= memory_size(ptr); g_memory_total_count--; - + memory_deallocate(ptr); } @@ -105,9 +105,9 @@ static bool run_test(test_runner* test, const char* test_name, pugi::allocation_ g_memory_fail_triggered = false; test_runner::_memory_fail_threshold = 0; test_runner::_memory_fail_triggered = false; - + pugi::set_memory_management_functions(allocate, custom_deallocate); - + #ifdef _MSC_VER # pragma warning(push) # pragma warning(disable: 4611) // interaction between _setjmp and C++ object destruction is non-portable @@ -115,7 +115,7 @@ static bool run_test(test_runner* test, const char* test_name, pugi::allocation_ #endif volatile int result = setjmp(test_runner::_failure_buffer); - + #ifdef _MSC_VER # pragma warning(pop) #endif @@ -177,7 +177,7 @@ int main(int, char** argv) temp.erase((slash != std::string::npos) ? slash + 1 : 0); test_runner::_temp_path = temp.c_str(); - + replace_memory_management(); unsigned int total = 0; diff --git a/tests/test.hpp b/tests/test.hpp index fad555d..e700826 100644 --- a/tests/test.hpp +++ b/tests/test.hpp @@ -157,7 +157,7 @@ struct dummy_fixture {}; #if (defined(_MSC_VER) && _MSC_VER == 1200) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER == 800) || defined(__BORLANDC__) // NaN comparison on MSVC6 is incorrect, see http://www.nabble.com/assertDoubleEquals,-NaN---Microsoft-Visual-Studio-6-td9137859.html // IC8 and BCC are also affected by the same bug -# define MSVC6_NAN_BUG +# define MSVC6_NAN_BUG #endif inline wchar_t wchar_cast(unsigned int value) diff --git a/tests/test_document.cpp b/tests/test_document.cpp index 8573ce3..eba2fd4 100644 --- a/tests/test_document.cpp +++ b/tests/test_document.cpp @@ -109,7 +109,7 @@ TEST(document_load_stream_error) std::ifstream fs("filedoesnotexist"); CHECK(doc.load(fs).status == status_io_error); - + std::istringstream iss(""); test_runner::_memory_fail_threshold = 1; CHECK_ALLOC_FAIL(CHECK(doc.load(iss).status == status_out_of_memory)); @@ -499,7 +499,7 @@ TEST_XML(document_save_declaration_latin1, "") struct temp_file { char path[512]; - + temp_file() { static int index = 0; diff --git a/tests/test_dom_modify.cpp b/tests/test_dom_modify.cpp index e84f098..67d550b 100644 --- a/tests/test_dom_modify.cpp +++ b/tests/test_dom_modify.cpp @@ -74,7 +74,7 @@ TEST_XML(dom_attr_set_value, "") TEST_XML(dom_attr_assign_llong, "") { xml_node node = doc.child(STR("node")); - + node.append_attribute(STR("attr1")) = -9223372036854775807ll; node.append_attribute(STR("attr2")) = -9223372036854775807ll - 1; xml_attribute() = -9223372036854775807ll - 1; @@ -89,7 +89,7 @@ TEST_XML(dom_attr_assign_llong, "") TEST_XML(dom_attr_set_value_llong, "") { xml_node node = doc.child(STR("node")); - + CHECK(node.append_attribute(STR("attr1")).set_value(-9223372036854775807ll)); CHECK(node.append_attribute(STR("attr2")).set_value(-9223372036854775807ll - 1)); CHECK(!xml_attribute().set_value(-9223372036854775807ll - 1)); @@ -158,7 +158,7 @@ TEST_XML(dom_node_prepend_attribute, "") { CHECK(xml_node().prepend_attribute(STR("a")) == xml_attribute()); CHECK(doc.prepend_attribute(STR("a")) == xml_attribute()); - + xml_attribute a1 = doc.child(STR("node")).prepend_attribute(STR("a1")); CHECK(a1); a1 = STR("v1"); @@ -178,7 +178,7 @@ TEST_XML(dom_node_append_attribute, "") { CHECK(xml_node().append_attribute(STR("a")) == xml_attribute()); CHECK(doc.append_attribute(STR("a")) == xml_attribute()); - + xml_attribute a1 = doc.child(STR("node")).append_attribute(STR("a1")); CHECK(a1); a1 = STR("v1"); @@ -206,7 +206,7 @@ TEST_XML(dom_node_insert_attribute_after, " CHECK(node.insert_attribute_after(STR("a"), xml_attribute()) == xml_attribute()); CHECK(node.insert_attribute_after(STR("a"), a2) == xml_attribute()); - + xml_attribute a3 = node.insert_attribute_after(STR("a3"), a1); CHECK(a3 && a3 != a2 && a3 != a1); a3 = STR("v3"); @@ -236,7 +236,7 @@ TEST_XML(dom_node_insert_attribute_before, "")); } @@ -296,7 +296,7 @@ TEST_XML(dom_node_append_copy_attribute, " CHECK(xml_node().append_copy(doc.child(STR("node")).attribute(STR("a1"))) == xml_attribute()); CHECK(doc.append_copy(doc.child(STR("node")).attribute(STR("a1"))) == xml_attribute()); CHECK(doc.child(STR("node")).append_copy(xml_attribute()) == xml_attribute()); - + xml_node node = doc.child(STR("node")); xml_node child = node.child(STR("child")); @@ -316,13 +316,13 @@ TEST_XML(dom_node_append_copy_attribute, " a3.set_name(STR("a3")); a3 = STR("v3"); - + a4.set_name(STR("a4")); a4 = STR("v4"); - + a5.set_name(STR("a5")); a5 = STR("v5"); - + CHECK_NODE(doc, STR("")); } @@ -339,7 +339,7 @@ TEST_XML(dom_node_insert_copy_after_attribute, "")); } @@ -378,7 +378,7 @@ TEST_XML(dom_node_insert_copy_before_attribute, "< CHECK(node.insert_copy_before(a1, xml_attribute()) == xml_attribute()); CHECK(node.insert_copy_before(xml_attribute(), a1) == xml_attribute()); CHECK(node.insert_copy_before(a2, a2) == xml_attribute()); - + xml_attribute a3 = node.insert_copy_before(a1, a1); CHECK(a3 && a3 != a2 && a3 != a1); @@ -394,13 +394,13 @@ TEST_XML(dom_node_insert_copy_before_attribute, "< a3.set_name(STR("a3")); a3 = STR("v3"); - + a4.set_name(STR("a4")); a4 = STR("v4"); - + a5.set_name(STR("a5")); a5 = STR("v5"); - + CHECK_NODE(doc, STR("")); } @@ -408,7 +408,7 @@ TEST_XML(dom_node_remove_attribute, "") CHECK(attr1.next_attribute() == attr2); CHECK(attr2.next_attribute() == xml_attribute()); - + CHECK(attr1.previous_attribute() == xml_attribute()); CHECK(attr2.previous_attribute() == attr1); - + CHECK(xml_attribute().next_attribute() == xml_attribute()); CHECK(xml_attribute().previous_attribute() == xml_attribute()); } @@ -497,7 +497,7 @@ TEST_XML_FLAGS(dom_node_type, "pcdata CHECK((it++)->type() == node_element); xml_node_iterator cit = doc.child(STR("node")).begin(); - + CHECK((cit++)->type() == node_pcdata); CHECK((cit++)->type() == node_cdata); } @@ -516,7 +516,7 @@ TEST_XML_FLAGS(dom_node_name_value, "") TEST_XML(dom_node_path, "text") { CHECK(xml_node().path() == STR("")); - + CHECK(doc.path() == STR("")); CHECK(doc.child(STR("node")).path() == STR("/node")); CHECK(doc.child(STR("node")).child(STR("child1")).path() == STR("/node/child1")); CHECK(doc.child(STR("node")).child(STR("child1")).child(STR("child2")).path() == STR("/node/child1/child2")); CHECK(doc.child(STR("node")).child(STR("child1")).first_child().path() == STR("/node/child1/")); - + CHECK(doc.child(STR("node")).child(STR("child1")).path('\\') == STR("\\node\\child1")); } #endif @@ -743,7 +743,7 @@ TEST_XML(dom_node_first_element_by_path, "texttextpcd CHECK((it++)->offset_debug() == 38); xml_node_iterator cit = doc.child(STR("node")).begin(); - + CHECK((cit++)->offset_debug() == 43); CHECK((cit++)->offset_debug() == 58); } @@ -966,7 +966,7 @@ TEST_XML(dom_internal_object, "value") xml_node node = doc.child(STR("node")); xml_attribute attr = node.first_attribute(); xml_node value = node.first_child(); - + CHECK(xml_node().internal_object() == 0); CHECK(xml_attribute().internal_object() == 0); @@ -988,7 +988,7 @@ TEST_XML(dom_hash_value, "value") xml_node node = doc.child(STR("node")); xml_attribute attr = node.first_attribute(); xml_node value = node.first_child(); - + CHECK(xml_node().hash_value() == 0); CHECK(xml_attribute().hash_value() == 0); diff --git a/tests/test_memory.cpp b/tests/test_memory.cpp index 85d6e86..14c9aff 100644 --- a/tests/test_memory.cpp +++ b/tests/test_memory.cpp @@ -48,7 +48,7 @@ TEST(memory_custom_memory_management) CHECK(page_allocs == 0 && page_deallocs == 0); CHECK(doc.load_string(STR(""))); - + CHECK(page_allocs == 1 && page_deallocs == 0); // modify document (no new page) diff --git a/tests/test_parse.cpp b/tests/test_parse.cpp index 47f774e..68fd217 100644 --- a/tests/test_parse.cpp +++ b/tests/test_parse.cpp @@ -82,7 +82,7 @@ TEST(parse_pi_error) CHECK(doc.load_string(STR(""), parse_fragment | parse_pi).status == status_bad_pi); CHECK(doc.load_string(STR(""), parse_fragment | parse_pi).status == status_bad_pi); CHECK(doc.load_string(STR(""), parse_fragment | parse_pi).status == status_bad_pi); @@ -235,9 +235,9 @@ TEST(parse_ws_pcdata_skip) CHECK(!doc.first_child()); CHECK(doc.load_string(STR(" "), parse_minimal)); - + xml_node root = doc.child(STR("root")); - + CHECK(root.first_child() == root.last_child()); CHECK(!root.first_child().first_child()); } @@ -855,7 +855,7 @@ TEST(parse_declaration_error) CHECK(doc.load_string(STR(""), flags).status == status_bad_pi); CHECK(doc.load_string(STR(""), flags).status == status_bad_pi); } - + CHECK(doc.load_string(STR(""), parse_fragment | parse_declaration).status == status_bad_attribute); CHECK(doc.load_string(STR(""), parse_fragment | parse_declaration).status == status_bad_pi); } diff --git a/tests/test_xpath.cpp b/tests/test_xpath.cpp index 57fa95b..33c1696 100644 --- a/tests/test_xpath.cpp +++ b/tests/test_xpath.cpp @@ -196,7 +196,7 @@ TEST(xpath_long_numbers_parse) { const pugi::char_t* str_flt_max = STR("340282346638528860000000000000000000000"); const pugi::char_t* str_flt_max_dec = STR("340282346638528860000000000000000000000.000000"); - + const pugi::char_t* str_dbl_max = STR("179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"); const pugi::char_t* str_dbl_max_dec = STR("179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000"); @@ -225,7 +225,7 @@ TEST(xpath_long_numbers_stringize) { const pugi::char_t* str_flt_max = STR("340282346638528860000000000000000000000"); const pugi::char_t* str_flt_max_dec = STR("340282346638528860000000000000000000000.000000"); - + const pugi::char_t* str_dbl_max = STR("179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"); const pugi::char_t* str_dbl_max_dec = STR("179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000"); diff --git a/tests/test_xpath_api.cpp b/tests/test_xpath_api.cpp index e53c25a..ef7d4b2 100644 --- a/tests/test_xpath_api.cpp +++ b/tests/test_xpath_api.cpp @@ -31,12 +31,12 @@ TEST_XML(xpath_api_select_node, "" CHECK(n2.node().attribute(STR("id")).as_int() == 1); xpath_node n3 = doc.select_node(STR("node/bar")); - + CHECK(!n3); xpath_node n4 = doc.select_node(STR("node/head/following-sibling::foo")); xpath_node n5 = doc.select_node(STR("node/tail/preceding-sibling::foo")); - + CHECK(n4.node().attribute(STR("id")).as_int() == 1); CHECK(n5.node().attribute(STR("id")).as_int() == 1); } @@ -258,7 +258,7 @@ TEST(xpath_api_evaluate_string) // test for just enough space std::basic_string s1 = base; CHECK(q.evaluate_string(&s1[0], 11, xml_node()) == 11 && memcmp(&s1[0], STR("0123456789\0xxxxx"), 16 * sizeof(char_t)) == 0); - + // test for just not enough space std::basic_string s2 = base; CHECK(q.evaluate_string(&s2[0], 10, xml_node()) == 11 && memcmp(&s2[0], STR("012345678\0xxxxxx"), 16 * sizeof(char_t)) == 0); @@ -292,7 +292,7 @@ TEST(xpath_api_return_type) TEST(xpath_api_query_bool) { xpath_query q(STR("node")); - + CHECK(q); CHECK((!q) == false); } @@ -301,7 +301,7 @@ TEST(xpath_api_query_bool) TEST(xpath_api_query_bool_fail) { xpath_query q(STR("")); - + CHECK((q ? true : false) == false); CHECK((!q) == true); } diff --git a/tests/test_xpath_functions.cpp b/tests/test_xpath_functions.cpp index eb43bb5..211dbfb 100644 --- a/tests/test_xpath_functions.cpp +++ b/tests/test_xpath_functions.cpp @@ -6,7 +6,7 @@ TEST_XML(xpath_number_number, "123") { xml_node c; xml_node n = doc.child(STR("node")).first_child(); - + // number with 0 arguments CHECK_XPATH_NUMBER_NAN(c, STR("number()")); CHECK_XPATH_NUMBER(n, STR("number()"), 123); @@ -35,7 +35,7 @@ TEST_XML(xpath_number_number, "123") // number with 1 number argument CHECK_XPATH_NUMBER(c, STR("number(1)"), 1); - + // number with 2 arguments CHECK_XPATH_FAIL(STR("number(1, 2)")); } @@ -44,21 +44,21 @@ TEST_XML(xpath_number_sum, "123789") { xml_node c; xml_node n = doc.child(STR("node")); - + // sum with 0 arguments CHECK_XPATH_FAIL(STR("sum()")); // sum with 1 argument CHECK_XPATH_NUMBER(c, STR("sum(.)"), 0); CHECK_XPATH_NUMBER(n, STR("sum(.)"), 123789); // 123 .. 789 - + CHECK_XPATH_NUMBER(n, STR("sum(./descendant-or-self::node())"), 125490); // node + 123 + child + 789 = 123789 + 123 + 789 + 789 = 125490 CHECK_XPATH_NUMBER(n, STR("sum(.//node())"), 1701); // 123 + child + 789 = 123 + 789 + 789 CHECK_XPATH_NUMBER_NAN(doc.last_child(), STR("sum(.)")); // sum with 2 arguments CHECK_XPATH_FAIL(STR("sum(1, 2)")); - + // sum with 1 non-node-set argument CHECK_XPATH_FAIL(STR("sum(1)")); } @@ -155,7 +155,7 @@ TEST(xpath_number_round) TEST_XML(xpath_boolean_boolean, "") { xml_node c; - + // boolean with 0 arguments CHECK_XPATH_FAIL(STR("boolean()")); @@ -182,14 +182,14 @@ TEST_XML(xpath_boolean_boolean, "") TEST(xpath_boolean_not) { xml_node c; - + // not with 0 arguments CHECK_XPATH_FAIL(STR("not()")); // not with 1 argument CHECK_XPATH_BOOLEAN(c, STR("not(true())"), false); CHECK_XPATH_BOOLEAN(c, STR("not(false())"), true); - + // boolean with 2 arguments CHECK_XPATH_FAIL(STR("not(1, 2)")); } @@ -197,7 +197,7 @@ TEST(xpath_boolean_not) TEST(xpath_boolean_true) { xml_node c; - + // true with 0 arguments CHECK_XPATH_BOOLEAN(c, STR("true()"), true); @@ -208,7 +208,7 @@ TEST(xpath_boolean_true) TEST(xpath_boolean_false) { xml_node c; - + // false with 0 arguments CHECK_XPATH_BOOLEAN(c, STR("false()"), false); @@ -219,7 +219,7 @@ TEST(xpath_boolean_false) TEST_XML(xpath_boolean_lang, "") { xml_node c; - + // lang with 0 arguments CHECK_XPATH_FAIL(STR("lang()")); @@ -228,7 +228,7 @@ TEST_XML(xpath_boolean_lang, " \t\r\rval1 \rval2\r\nval3\ // normalize-space with 0 arguments CHECK_XPATH_STRING(c, STR("normalize-space()"), STR("")); CHECK_XPATH_STRING(n, STR("normalize-space()"), STR("val1 val2 val3 val4")); - + // normalize-space with 1 argument CHECK_XPATH_STRING(c, STR("normalize-space('')"), STR("")); CHECK_XPATH_STRING(c, STR("normalize-space('abcd')"), STR("abcd")); @@ -526,7 +526,7 @@ TEST_XML_FLAGS(xpath_string_normalize_space, " \t\r\rval1 \rval2\r\nval3\ CHECK_XPATH_STRING(c, STR("normalize-space('ab\r\n\tcd')"), STR("ab cd")); CHECK_XPATH_STRING(c, STR("normalize-space('ab cd')"), STR("ab cd")); CHECK_XPATH_STRING(c, STR("normalize-space('\07')"), STR("\07")); - + // normalize-space with 2 arguments CHECK_XPATH_FAIL(STR("normalize-space(1, 2)")); } @@ -537,13 +537,13 @@ TEST(xpath_string_translate) // translate with 0 arguments CHECK_XPATH_FAIL(STR("translate()")); - + // translate with 1 argument CHECK_XPATH_FAIL(STR("translate('a')")); // translate with 2 arguments CHECK_XPATH_FAIL(STR("translate('a', 'b')")); - + // translate with 3 arguments CHECK_XPATH_STRING(c, STR("translate('abc', '', '')"), STR("abc")); CHECK_XPATH_STRING(c, STR("translate('abc', '', 'foo')"), STR("abc")); @@ -604,7 +604,7 @@ TEST_XML(xpath_nodeset_position, "") // id with 0 arguments CHECK_XPATH_FAIL(STR("id()")); - + // id with 1 argument - no DTD => no id CHECK_XPATH_NODESET(n, STR("id('foo')")); @@ -656,7 +656,7 @@ TEST_XML_FLAGS(xpath_nodeset_local_name, "text< // local-name with 0 arguments CHECK_XPATH_STRING(c, STR("local-name()"), STR("")); CHECK_XPATH_STRING(n, STR("local-name()"), STR("node")); - + // local-name with 1 non-node-set argument CHECK_XPATH_FAIL(STR("local-name(1)")); @@ -681,7 +681,7 @@ TEST_XML_FLAGS(xpath_nodeset_namespace_uri, "te // namespace-uri with 0 arguments CHECK_XPATH_STRING(c, STR("namespace-uri()"), STR("")); CHECK_XPATH_STRING(n.child(STR("c2")).child(STR("foo:child")), STR("namespace-uri()"), STR("http://foo2")); - + // namespace-uri with 1 non-node-set argument CHECK_XPATH_FAIL(STR("namespace-uri(1)")); @@ -710,7 +710,7 @@ TEST_XML_FLAGS(xpath_nodeset_name, "text1-10.0004") CHECK_XPATH_NUMBER(doc, STR("number(4 div 10000)"), 0.0004); // +0 works around extended precision in div on x86 (this is needed for some configurations in MinGW 3.4) - CHECK_XPATH_BOOLEAN(doc, STR("(number(k) = (4 div 10000 + 0))"), true); + CHECK_XPATH_BOOLEAN(doc, STR("(number(k) = (4 div 10000 + 0))"), true); CHECK_XPATH_NUMBER(doc, STR("number(0.0001 * 4)"), 0.0004); CHECK_XPATH_BOOLEAN(doc, STR("(number(k) = (0.0001 * 4))"), true); } diff --git a/tests/writer_string.hpp b/tests/writer_string.hpp index 6bffc32..0c1089d 100644 --- a/tests/writer_string.hpp +++ b/tests/writer_string.hpp @@ -8,7 +8,7 @@ struct xml_writer_string: public pugi::xml_writer { std::string contents; - + virtual void write(const void* data, size_t size); std::string as_narrow() const; -- cgit v1.2.3