From 0e734cb3b6ee3c21cafb2b076eaf6167ae5e33d2 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Fri, 7 Feb 2025 00:49:26 +0900 Subject: [PATCH] feat: add syntax for each escape seqs --- include/toml11/fwd/syntax_fwd.hpp | 4 ++++ include/toml11/impl/syntax_impl.hpp | 23 ++++++++++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/include/toml11/fwd/syntax_fwd.hpp b/include/toml11/fwd/syntax_fwd.hpp index 3560821..80bcc29 100644 --- a/include/toml11/fwd/syntax_fwd.hpp +++ b/include/toml11/fwd/syntax_fwd.hpp @@ -226,6 +226,10 @@ sequence offset_datetime(const spec& s); // =========================================================================== // String +sequence escaped_x2(const spec& s); +sequence escaped_u4(const spec& s); +sequence escaped_U8(const spec& s); + sequence escaped(const spec& s); either basic_char(const spec& s); diff --git a/include/toml11/impl/syntax_impl.hpp b/include/toml11/impl/syntax_impl.hpp index f5180f3..638a7de 100644 --- a/include/toml11/impl/syntax_impl.hpp +++ b/include/toml11/impl/syntax_impl.hpp @@ -398,6 +398,19 @@ TOML11_INLINE sequence offset_datetime(const spec& s) // =========================================================================== // String +TOML11_INLINE sequence escaped_x2(const spec& s) +{ + return sequence(character('x'), repeat_exact(2, hexdig(s))); +} +TOML11_INLINE sequence escaped_u4(const spec& s) +{ + return sequence(character('u'), repeat_exact(4, hexdig(s))); +} +TOML11_INLINE sequence escaped_U8(const spec& s) +{ + return sequence(character('U'), repeat_exact(8, hexdig(s))); +} + TOML11_INLINE sequence escaped(const spec& s) { const auto escape_char = [&s] { @@ -416,17 +429,17 @@ TOML11_INLINE sequence escaped(const spec& s) { return either( escape_char(), - sequence(character('u'), repeat_exact(4, hexdig(s))), - sequence(character('U'), repeat_exact(8, hexdig(s))), - sequence(character('x'), repeat_exact(2, hexdig(s))) + escaped_u4(s), + escaped_U8(s), + escaped_x2(s) ); } else { return either( escape_char(), - sequence(character('u'), repeat_exact(4, hexdig(s))), - sequence(character('U'), repeat_exact(8, hexdig(s))) + escaped_u4(s), + escaped_U8(s) ); } };