forked from alibaba/PhotonLibOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SimpleDOM support for XML (with RapidXml) and JSON (with rapidjson) (a…
…libaba#445) * and change ```integration``` into ```ecosystem``` * Use fetchcontent instead of copy code --------- Co-authored-by: Coldwings <coldwings@me.com>
- Loading branch information
Showing
27 changed files
with
793 additions
and
391 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Fetch depend code for ecosystem | ||
# Here for header-only parts. | ||
|
||
include(FetchContent) | ||
|
||
# Rapidjson | ||
FetchContent_Declare( | ||
rapidjson | ||
URL ${PHOTON_RAPIDJSON_SOURCE} | ||
URL_HASH SHA256=8e00c38829d6785a2dfb951bb87c6974fa07dfe488aa5b25deec4b8bc0f6a3ab | ||
PATCH_COMMAND patch -p1 < ${CMAKE_CURRENT_SOURCE_DIR}/patches/rapidjson.patch | ||
DOWNLOAD_EXTRACT_TIMESTAMP ON | ||
UPDATE_DISCONNECTED 1) | ||
# Pre-set rapidjson build option, prevent building docs, examples and tests | ||
set(RAPIDJSON_BUILD_DOC OFF CACHE BOOL "Build rapidjson documentation.") | ||
set(RAPIDJSON_BUILD_EXAMPLES OFF CACHE BOOL "Build rapidjson documentation.") | ||
set(RAPIDJSON_BUILD_TESTS OFF CACHE BOOL "Build rapidjson perftests and unittests.") | ||
FetchContent_MakeAvailable(rapidjson) | ||
message(STATUS "Rapidjson source dir: ${rapidjson_SOURCE_DIR}") | ||
|
||
# RapidXml | ||
FetchContent_Declare( | ||
rapidxml | ||
URL ${PHOTON_RAPIDXML_SOURCE} | ||
URL_HASH | ||
SHA256=c3f0b886374981bb20fabcf323d755db4be6dba42064599481da64a85f5b3571 | ||
DOWNLOAD_EXTRACT_TIMESTAMP ON | ||
UPDATE_DISCONNECTED 1) | ||
FetchContent_MakeAvailable(rapidxml) | ||
message(STATUS "Rapidxml source dir: ${rapidxml_SOURCE_DIR}") | ||
|
||
# cpp-redis | ||
FetchContent_Declare( | ||
cpp-redis | ||
URL ${PHOTON_CPP_REDIS_SOURCE} | ||
URL_HASH | ||
SHA256=3859289d8254685fc775bda73de03dad27df923423b8ceb375b02d036c03b02f | ||
DOWNLOAD_EXTRACT_TIMESTAMP ON | ||
UPDATE_DISCONNECTED 1) | ||
# uses only a simple header, so do not add sub directory to avoid unnecessary build | ||
# do not use FetchContent_MakeAvailable, just populate it. | ||
FetchContent_GetProperties(cpp-redis) | ||
if(NOT cpp-redis_POPULATED) | ||
FetchContent_Populate(cpp-redis) | ||
endif() | ||
message(STATUS "cpp-redis source dir: ${cpp-redis_SOURCE_DIR}") | ||
|
||
add_library(ecosystem_deps INTERFACE) | ||
target_include_directories( | ||
ecosystem_deps | ||
INTERFACE ${rapidjson_SOURCE_DIR}/include ${rapidxml_SOURCE_DIR} | ||
${cpp-redis_SOURCE_DIR}/includes) | ||
get_property( | ||
incs | ||
TARGET ecosystem_deps | ||
PROPERTY INTERFACE_INCLUDE_DIRECTORIES) | ||
message(STATUS "ecosystem_deps incs: ${incs}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
diff --git a/include/rapidjson/reader.h b/include/rapidjson/reader.h | ||
index 19f8849b..618492a4 100644 | ||
--- a/include/rapidjson/reader.h | ||
+++ b/include/rapidjson/reader.h | ||
@@ -153,6 +153,7 @@ enum ParseFlag { | ||
kParseNumbersAsStringsFlag = 64, //!< Parse all numbers (ints/doubles) as strings. | ||
kParseTrailingCommasFlag = 128, //!< Allow trailing commas at the end of objects and arrays. | ||
kParseNanAndInfFlag = 256, //!< Allow parsing NaN, Inf, Infinity, -Inf and -Infinity as doubles. | ||
+ kParseBoolsAsStringFlag = 512, //!< Parse all booleans (true/false) as strings. | ||
kParseDefaultFlags = RAPIDJSON_PARSE_DEFAULT_FLAGS //!< Default parse flags. Can be customized by defining RAPIDJSON_PARSE_DEFAULT_FLAGS | ||
}; | ||
|
||
@@ -201,6 +202,8 @@ struct BaseReaderHandler { | ||
bool Default() { return true; } | ||
bool Null() { return static_cast<Override&>(*this).Default(); } | ||
bool Bool(bool) { return static_cast<Override&>(*this).Default(); } | ||
+ // enabled via kParseBoolsAsStringsFlag, string is not null-terminated (use length) | ||
+ bool RawBool(const Ch* str, SizeType len, bool copy) { return static_cast<Override&>(*this).Default(); } | ||
bool Int(int) { return static_cast<Override&>(*this).Default(); } | ||
bool Uint(unsigned) { return static_cast<Override&>(*this).Default(); } | ||
bool Int64(int64_t) { return static_cast<Override&>(*this).Default(); } | ||
@@ -714,13 +717,22 @@ private: | ||
RAPIDJSON_PARSE_ERROR(kParseErrorValueInvalid, is.Tell()); | ||
} | ||
|
||
+ template<unsigned parseFlags, typename InputStream, typename Handler> | ||
+ void ParseRawBools(InputStream& is, Handler& handler) { | ||
+ | ||
+ } | ||
+ | ||
template<unsigned parseFlags, typename InputStream, typename Handler> | ||
void ParseTrue(InputStream& is, Handler& handler) { | ||
RAPIDJSON_ASSERT(is.Peek() == 't'); | ||
+ auto begin = is.PutBegin(); | ||
is.Take(); | ||
|
||
if (RAPIDJSON_LIKELY(Consume(is, 'r') && Consume(is, 'u') && Consume(is, 'e'))) { | ||
- if (RAPIDJSON_UNLIKELY(!handler.Bool(true))) | ||
+ auto copy = !(parseFlags & kParseInsituFlag); | ||
+ bool ret = (parseFlags & kParseBoolsAsStringFlag) ? | ||
+ handler.RawBool(begin, 4, copy) : handler.Bool(true); | ||
+ if (RAPIDJSON_UNLIKELY(!ret)) | ||
RAPIDJSON_PARSE_ERROR(kParseErrorTermination, is.Tell()); | ||
} | ||
else | ||
@@ -730,10 +742,14 @@ private: | ||
template<unsigned parseFlags, typename InputStream, typename Handler> | ||
void ParseFalse(InputStream& is, Handler& handler) { | ||
RAPIDJSON_ASSERT(is.Peek() == 'f'); | ||
+ auto begin = is.PutBegin(); | ||
is.Take(); | ||
|
||
if (RAPIDJSON_LIKELY(Consume(is, 'a') && Consume(is, 'l') && Consume(is, 's') && Consume(is, 'e'))) { | ||
- if (RAPIDJSON_UNLIKELY(!handler.Bool(false))) | ||
+ auto copy = !(parseFlags & kParseInsituFlag); | ||
+ bool ret = (parseFlags & kParseBoolsAsStringFlag) ? | ||
+ handler.RawBool(begin, 5, copy) : handler.Bool(false); | ||
+ if (RAPIDJSON_UNLIKELY(!ret)) | ||
RAPIDJSON_PARSE_ERROR(kParseErrorTermination, is.Tell()); | ||
} | ||
else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.