Add support for \e (toml-lang/toml/pull/790)

This commit is contained in:
Mark Gillard 2022-03-06 16:09:14 +02:00
parent 1c26ce1dcf
commit 5b79305c6e
5 changed files with 38 additions and 18 deletions

View File

@ -181,7 +181,8 @@ defines `TOML_LANG_MAJOR`, `TOML_LANG_MINOR` and `TOML_LANG_PATCH`.
- [#644]: Support `+` in key names
- [#671]: Local time of day format should support `09:30` as opposed to `09:30:00`
- [#687]: Relax bare key restrictions to allow additional unicode characters
- [#796]: Include an \xHH escape code sequence
- [#790]: Include an `\e` escape code sequence (shorthand for `\u001B`)
- [#796]: Include an `\xHH` escape code sequence
> ️ _`#define TOML_ENABLE_UNRELEASED_FEATURES 1` to enable these features (see [Configuration](#Configuration))._
@ -272,7 +273,8 @@ though you're welcome to reach out via other means. In order of likely response
[#665]: https://github.com/toml-lang/toml/issues/665
[#671]: https://github.com/toml-lang/toml/issues/671
[#687]: https://github.com/toml-lang/toml/issues/687
[#796]: https://github.com/toml-lang/toml/pull/796
[#766]: https://github.com/toml-lang/toml/issues/766
[#790]: https://github.com/toml-lang/toml/pull/790
[#796]: https://github.com/toml-lang/toml/pull/796
[something better than std::optional]: https://github.com/TartanLlama/optional
[m.css]: https://mcss.mosra.cz/documentation/doxygen

View File

@ -1388,14 +1388,23 @@ TOML_IMPL_NAMESPACE_START
case U'"': str += '"'; break;
case U'\\': str += '\\'; break;
// unicode scalar sequences
case U'x':
#if TOML_LANG_UNRELEASED // toml/pull/796 (\xHH unicode scalar sequences)
[[fallthrough]];
#if TOML_LANG_UNRELEASED // toml/pull/790 (\e shorthand for \x1B)
case U'e': str += '\x1B'; break;
#else
case U'e':
set_error_and_return_default(
"escape sequence '\\e' is not supported in TOML 1.0.0 and earlier"sv);
#endif
#if TOML_LANG_UNRELEASED // toml/pull/796 (\xHH unicode scalar sequences)
case U'x': [[fallthrough]];
#else
case U'x':
set_error_and_return_default(
"escape sequence '\\x' is not supported in TOML 1.0.0 and earlier"sv);
#endif
// unicode scalar sequences
case U'u': [[fallthrough]];
case U'U':
{

View File

@ -175,9 +175,5 @@ TOML_IMPL_NAMESPACE_START
}
TOML_IMPL_NAMESPACE_END;
#if TOML_GCC && TOML_GCC < 9
#pragma GCC pop_options
#endif
/// \endcond
#include "header_end.h"

View File

@ -164,6 +164,14 @@ str = ''''That's still pointless', she said.'''
parsing_should_fail(FILE_LINE_ARGS, R"(str = "\x00\x10\x20\x30\x40\x50\x60\x70\x80\x90\x11\xFF\xEE")"sv);
#endif
// toml/pull/790
#if TOML_LANG_UNRELEASED
parse_expected_value(FILE_LINE_ARGS, R"("\e[31mfoo\e[0m")"sv, "\x1B[31mfoo\x1B[0m"sv);
#else
parsing_should_fail(FILE_LINE_ARGS, R"("\e[31mfoo\e[0m")"sv);
#endif
// check 8-digit \U scalars with insufficient digits
parsing_should_fail(FILE_LINE_ARGS, R"(str = "\U1234567")"sv);
parsing_should_fail(FILE_LINE_ARGS, R"(str = "\U123456")"sv);

View File

@ -8138,10 +8138,6 @@ TOML_IMPL_NAMESPACE_START
}
TOML_IMPL_NAMESPACE_END;
#if TOML_GCC && TOML_GCC < 9
#pragma GCC pop_options
#endif
#ifdef _MSC_VER
#pragma pop_macro("min")
#pragma pop_macro("max")
@ -12197,14 +12193,23 @@ TOML_IMPL_NAMESPACE_START
case U'"': str += '"'; break;
case U'\\': str += '\\'; break;
// unicode scalar sequences
case U'x':
#if TOML_LANG_UNRELEASED // toml/pull/796 (\xHH unicode scalar sequences)
[[fallthrough]];
#if TOML_LANG_UNRELEASED // toml/pull/790 (\e shorthand for \x1B)
case U'e': str += '\x1B'; break;
#else
case U'e':
set_error_and_return_default(
"escape sequence '\\e' is not supported in TOML 1.0.0 and earlier"sv);
#endif
#if TOML_LANG_UNRELEASED // toml/pull/796 (\xHH unicode scalar sequences)
case U'x': [[fallthrough]];
#else
case U'x':
set_error_and_return_default(
"escape sequence '\\x' is not supported in TOML 1.0.0 and earlier"sv);
#endif
// unicode scalar sequences
case U'u': [[fallthrough]];
case U'U':
{