Skip to content

Commit

Permalink
Merge pull request #18 from dwd/v2
Browse files Browse the repository at this point in the history
The Great v2 Rewrite
  • Loading branch information
dwd authored Jul 17, 2024
2 parents 4dd8694 + 5d9924e commit 10e3e9d
Show file tree
Hide file tree
Showing 12 changed files with 3,998 additions and 3,212 deletions.
10 changes: 9 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.8)
project(rapidxml)

# GoogleTest requires at least C++14
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

include(FetchContent)
Expand All @@ -12,6 +12,8 @@ FetchContent_Declare(
)
FetchContent_MakeAvailable(googletest)

file(DOWNLOAD https://www.w3.org/TR/xml/REC-xml-20081126.xml ${CMAKE_CURRENT_BINARY_DIR}/REC-xml-20081126.xml)

enable_testing()
add_executable(rapidxml-test
test/parse-simple.cpp
Expand All @@ -20,6 +22,11 @@ add_executable(rapidxml-test
rapidxml_utils.hpp
rapidxml.hpp
test/manipulations.cpp
test/round-trips.cpp
test/low-level-parse.cpp
test/perf.cpp
rapidxml_wrappers.hpp
test/iterators.cpp
)
target_link_libraries(rapidxml-test
GTest::gtest_main
Expand All @@ -28,5 +35,6 @@ target_include_directories(rapidxml-test
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
)
target_compile_definitions(rapidxml-test PRIVATE RAPIDXML_TESTING=1)
include(GoogleTest)
gtest_discover_tests(rapidxml-test)
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,48 @@ Hey! This is RapidXML, an ancient C++ library for parsing XML quickly and flexib

There's a lot of forks of this around, and I (Dave Cridland) didn't write the vast majority of this library - instead, it was written by someone called Marcin Kalicinski, and his copyright is dated 2009.

## Version 2, Breaking Changes

This is version 2.x. You might not want this.

It has breaking changes, the largest of which are:
* No more case insensitive option. Really, nobody should be using XML case insensitively anyway, but it was too difficult to keep around, sorry.
* Instead of passing around potentially unterminated character pointers with optional lengths, we now use std::basic_string_view
* There is no need for string termination, now, so the parse function never terminates, and that option has vanished.
* Return values that were previously bare pointers are now a safe wrapped pointer which ordinarily will check/throw for nullptr.
* append/prepend/insert_node now also have an append/prepend/insert_element shorthand, which will allow an XML namespace to be included if wanted.
* Parsing data can be done from a container as well as a NUL-terminated buffer. A NUL-terminated buffer is slightly faster still, and will be used if possible.

Not breaking, but kind of nice:
* The parse buffer is now treated as const, and will never be mutated. This incurs a slight performance penalty for handling long text values that have an encoded entity late in the string.
* The iterators library is now included by default, and updated to handle most idiomatic modern C++ operations.

Internal changes:
* There is no longer a internal::measure or internal::compare; these just use the std::char_traits<Ch> functions as used by the string_views.
* Reserialization (that is, using the rapidxml::print family on a tree that is mostly or entirely from parsing) is now much faster, and will optimize itself to use simple buffer copies where the data is unchanged from parsing.
* Alignment of the allocator uses C++11's alignof/std::align, and so sould be more portable.

### Fun

The rapidxml_iterators library is now included in rapidxml.hpp, and you can do amusing things like:

```c++
for (auto & child : node.children()) {
if (child.name() == "potato") scream_for(joy);
}
```

More in tests/iterators.cpp

For those of us who lose track of the buffer sometimes, clone_node() now takes an optional second argument of "true" if you want to also clone the strings. Otherwise, nodes will use string_views which reference the original parsed buffer.

### Gotchas

The functions like find_node and name(...) that took a Ch * and optional length now take only a
std::basic_string_view<Ch>. Typical usage passed in 0, NULL, or nullptr for unwanted values; this will now segfault on C++20
and earlier - use C++23 ideally, but you can pass in {} instead. This should probably be a
std::optional<std::basic_string_view<Ch>> instead.

## Changes

I needed a library for fast XMPP processing (reading, processing, and reserializing), and this mostly fit the bill. However, not entirely, so this version adds:
Expand Down
Loading

0 comments on commit 10e3e9d

Please sign in to comment.