diff --git a/CMakeLists.txt b/CMakeLists.txt index 3f23fa18..ca9390cb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,7 @@ c4_project(VERSION 0.9.0 STANDALONE #------------------------------------------------------- option(RYML_WITH_TAB_TOKENS "Enable parsing of tabs after ':' and '-'. This is costly and disabled by default." OFF) +option(RYML_WITH_BACKL_BACKP "Double scalars: decode \L and \P (respectively to \u2028 and \u2029). They decode to a larger size, and require complex logic to deal with. Disabled by default." OFF) option(RYML_DEFAULT_CALLBACKS "Enable ryml's default implementation of callbacks: allocate(), free(), error()" ON) if(RYML_DEFAULT_CALLBACKS) option(RYML_DEFAULT_CALLBACK_USES_EXCEPTIONS "Throw exceptions instead of calling abort in the default error handler provided by ryml" OFF) @@ -87,6 +88,10 @@ if(RYML_WITH_TAB_TOKENS) target_compile_definitions(ryml PUBLIC RYML_WITH_TAB_TOKENS) endif() +if(RYML_WITH_BACKL_BACKP) + target_compile_definitions(ryml PUBLIC RYML_WITH_BACKL_BACKP) +endif() + if(NOT RYML_DEFAULT_CALLBACKS) target_compile_definitions(ryml PRIVATE RYML_NO_DEFAULT_CALLBACKS) else() diff --git a/src/c4/yml/parse_engine.def.hpp b/src/c4/yml/parse_engine.def.hpp index 1f389cc2..e8ecb29c 100644 --- a/src/c4/yml/parse_engine.def.hpp +++ b/src/c4/yml/parse_engine.def.hpp @@ -26,6 +26,12 @@ #define _RYML_WITH_OR_WITHOUT_TAB_TOKENS(with, without) without #endif +#if defined(RYML_WITH_BACKL_BACKP) +#define _RYML_WITH_OR_WITHOUT_BACKL_BACKP(with, without) with +#else +#define _RYML_WITH_OR_WITHOUT_BACKL_BACKP(with, without) without +#endif + // scaffold: #define _c4dbgnextline() \ @@ -2753,6 +2759,10 @@ void ParseEngine::_filter_dquoted_backslash(FilterProcessor &C4_RE } else if(next == 'L') // unicode line separator \u2028 { + #ifndef RYML_WITH_BACKL_BACKP + _c4err("\\L cannot be decoded as it would expand the source buffer. " + "use \\u2028 instead, or #define RYML_WITH_BACKL_BACKP while compiling."); + #else // https://www.utf8-chartable.de/unicode-utf8-table.pl?start=8192&number=1024&names=-&utf8=0x&unicodeinhtml=hex const char payload[] = { _RYML_CHCONST(-0x1e, 0xe2), @@ -2760,9 +2770,14 @@ void ParseEngine::_filter_dquoted_backslash(FilterProcessor &C4_RE _RYML_CHCONST(-0x58, 0xa8), }; proc.translate_esc_extending(payload, /*nwrite*/3, /*nread*/1); + #endif } else if(next == 'P') // unicode paragraph separator \u2029 { + #ifndef RYML_WITH_BACKL_BACKP + _c4err("\\N cannot be decoded as it would expand the source buffer. " + "use \\u2029 instead, or #define RYML_WITH_BACKL_BACKP while compiling."); + #else // https://www.utf8-chartable.de/unicode-utf8-table.pl?start=8192&number=1024&names=-&utf8=0x&unicodeinhtml=hex const char payload[] = { _RYML_CHCONST(-0x1e, 0xe2), @@ -2770,6 +2785,7 @@ void ParseEngine::_filter_dquoted_backslash(FilterProcessor &C4_RE _RYML_CHCONST(-0x57, 0xa9), }; proc.translate_esc_extending(payload, /*nwrite*/3, /*nread*/1); + #endif } else if(next == '\0') {