added support for \xHH escape sequences (unreleased)

also:
- fixed EOF bug in string parsing when exceptions are disabled
- fixed exception mode detection sometimes being incorrect on MSVC
- added short-form license preamble to all source files
- simplified license files
This commit is contained in:
Mark Gillard
2020-03-12 17:23:25 +02:00
parent 45bfff536b
commit 438970b412
32 changed files with 232 additions and 114 deletions

View File

@@ -1,3 +1,7 @@
//# This file is a part of toml++ and is subject to the the terms of the MIT license.
//# Copyright (c) 2019-2020 Mark Gillard <mark.gillard@outlook.com.au>
//# See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text.
#pragma once
//# Note: most of these would be included transitively but
@@ -51,7 +55,6 @@
#undef TOML_CONSTEVAL
#undef TOML_LIKELY
#undef TOML_UNLIKELY
#undef TOML_NO_UNIQUE_ADDRESS
#undef TOML_NODISCARD_CTOR
#undef TOML_MAKE_VERSION
#undef TOML_LANG_EFFECTIVE_VERSION
@@ -78,6 +81,7 @@
#undef TOML_ALL_INLINE
#undef TOML_IMPLEMENTATION
#undef TOML_INLINE_FUNC_IMPL
#undef TOML_COMPILER_EXCEPTIONS
#endif
/// \mainpage toml++
@@ -222,7 +226,6 @@
/// static constexpr auto source = R"(
/// [library]
/// name = "toml++"
/// version = "0.1.0"
/// authors = ["Mark Gillard <mark@notarealwebsite.com>"]
///
/// [dependencies]
@@ -253,7 +256,6 @@
/// [library]
/// authors = ["Mark Gillard <mark@notarealwebsite.com>"]
/// name = "toml++"
/// version = "0.1.0"
///
/// ... exactly as above, but twice
/// \eout
@@ -422,12 +424,8 @@
/// toml++ is licensed under the terms of the MIT license - see
/// [LICENSE](https://github.com/marzer/tomlplusplus/blob/master/LICENSE).
///
/// UTF-8 decoding is performed using a state machine based on Bjoern Hoehrmann's
/// 'Flexible and Economical UTF - 8 Decoder', which is also subject to the terms of the MIT license - see
/// [LICENSE-utf8-decoder](https://github.com/marzer/tomlplusplus/blob/master/LICENSE-utf8-decoder).
///
/// \m_class{m-note m-default}
///
/// If you're using the single-header version of the library you don't need to distribute these files;
/// their contents is included in the preamble at the top of the file.
/// If you're using the single-header version of the library you don't need to explicitly distribute the license file;
/// it is embedded in the preamble at the top of the header.
///

View File

@@ -1,3 +1,7 @@
//# This file is a part of toml++ and is subject to the the terms of the MIT license.
//# Copyright (c) 2019-2020 Mark Gillard <mark.gillard@outlook.com.au>
//# See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text.
#pragma once
#include "toml_value.h"

View File

@@ -1,3 +1,7 @@
//# This file is a part of toml++ and is subject to the the terms of the MIT license.
//# Copyright (c) 2019-2020 Mark Gillard <mark.gillard@outlook.com.au>
//# See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text.
#pragma once
#include "toml_array.h"

View File

@@ -1,3 +1,7 @@
//# This file is a part of toml++ and is subject to the the terms of the MIT license.
//# Copyright (c) 2019-2020 Mark Gillard <mark.gillard@outlook.com.au>
//# See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text.
#pragma once
////////// CONFIGURATION
@@ -70,14 +74,15 @@
#define TOML_ALWAYS_INLINE TOML_GCC_ATTR(__always_inline__) inline
#define TOML_ASSUME(cond) __builtin_assume(cond)
#define TOML_UNREACHABLE __builtin_unreachable()
#if __has_declspec_attribute(novtable)
#define TOML_INTERFACE __declspec(novtable)
#endif
#if __has_declspec_attribute(empty_bases)
#define TOML_EMPTY_BASES __declspec(empty_bases)
#endif
#ifdef __EXCEPTIONS
#define TOML_COMPILER_EXCEPTIONS 1
#endif
//floating-point from_chars and to_chars are not implemented in any version of clang as of 1/1/2020
#ifndef TOML_USE_STREAMS_FOR_FLOATS
@@ -97,10 +102,12 @@
#define TOML_UNREACHABLE __assume(0)
#define TOML_INTERFACE __declspec(novtable)
#define TOML_EMPTY_BASES __declspec(empty_bases)
#if !defined(TOML_RELOPS_REORDERING) && defined(__cpp_impl_three_way_comparison)
#define TOML_RELOPS_REORDERING 1
#endif
#ifdef _CPPUNWIND
#define TOML_COMPILER_EXCEPTIONS 1
#endif
#elif defined(__GNUC__)
@@ -116,6 +123,12 @@
#define TOML_POP_WARNINGS _Pragma("GCC diagnostic pop")
#define TOML_ALWAYS_INLINE TOML_GCC_ATTR(__always_inline__) inline
#define TOML_UNREACHABLE __builtin_unreachable()
#if !defined(TOML_RELOPS_REORDERING) && defined(__cpp_impl_three_way_comparison)
#define TOML_RELOPS_REORDERING 1
#endif
#ifdef __cpp_exceptions
#define TOML_COMPILER_EXCEPTIONS 1
#endif
// these pass the __has_attribute() test but cause warnings on if/else branches =/
#define TOML_LIKELY
@@ -126,10 +139,6 @@
#define TOML_USE_STREAMS_FOR_FLOATS 1
#endif
#if !defined(TOML_RELOPS_REORDERING) && defined(__cpp_impl_three_way_comparison)
#define TOML_RELOPS_REORDERING 1
#endif
#endif
#ifndef TOML_CPP_VERSION
@@ -148,16 +157,19 @@
#elif TOML_CPP_VERSION >= 201703L
#define TOML_CPP 17
#endif
#if !defined(__EXCEPTIONS) && !defined(__cpp_exceptions) && !defined(_CPPUNWIND)
#ifndef TOML_COMPILER_EXCEPTIONS
#define TOML_COMPILER_EXCEPTIONS 0
#endif
#if TOML_COMPILER_EXCEPTIONS
#ifndef TOML_EXCEPTIONS
#define TOML_EXCEPTIONS 1
#endif
#else
#if defined(TOML_EXCEPTIONS) && TOML_EXCEPTIONS
#error TOML_EXCEPTIONS was explicitly enabled but exceptions are disabled/unsupported by the compiler.
#endif
#undef TOML_EXCEPTIONS
#define TOML_EXCEPTIONS 0
#else
#ifndef TOML_EXCEPTIONS
#define TOML_EXCEPTIONS 1
#endif
#endif
#if TOML_EXCEPTIONS
#define TOML_MAY_THROW
@@ -214,9 +226,6 @@
#if !defined(TOML_UNLIKELY) && __has_cpp_attribute(unlikely)
#define TOML_UNLIKELY [[unlikely]]
#endif
#if !defined(TOML_NO_UNIQUE_ADDRESS) && __has_cpp_attribute(no_unique_address)
#define TOML_NO_UNIQUE_ADDRESS [[no_unique_address]]
#endif
#if __has_cpp_attribute(nodiscard) >= 201907L
#define TOML_NODISCARD_CTOR [[nodiscard]]
#endif
@@ -227,9 +236,6 @@
#ifndef TOML_UNLIKELY
#define TOML_UNLIKELY
#endif
#ifndef TOML_NO_UNIQUE_ADDRESS
#define TOML_NO_UNIQUE_ADDRESS
#endif
#ifndef TOML_NODISCARD_CTOR
#define TOML_NODISCARD_CTOR
#endif

View File

@@ -1,3 +1,7 @@
//# This file is a part of toml++ and is subject to the the terms of the MIT license.
//# Copyright (c) 2019-2020 Mark Gillard <mark.gillard@outlook.com.au>
//# See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text.
#pragma once
#include "toml_common.h"

View File

@@ -1,3 +1,7 @@
//# This file is a part of toml++ and is subject to the the terms of the MIT license.
//# Copyright (c) 2019-2020 Mark Gillard <mark.gillard@outlook.com.au>
//# See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text.
#pragma once
#include "toml_formatter.h"
#include "toml_table.h"

View File

@@ -1,3 +1,7 @@
//# This file is a part of toml++ and is subject to the the terms of the MIT license.
//# Copyright (c) 2019-2020 Mark Gillard <mark.gillard@outlook.com.au>
//# See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text.
#pragma once
#include "toml_print_to_stream.h"

View File

@@ -1,3 +1,7 @@
//# This file is a part of toml++ and is subject to the the terms of the MIT license.
//# Copyright (c) 2019-2020 Mark Gillard <mark.gillard@outlook.com.au>
//# See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text.
#pragma once
#include "toml_value.h"
#include "toml_node_view.h"

View File

@@ -1,3 +1,7 @@
//# This file is a part of toml++ and is subject to the the terms of the MIT license.
//# Copyright (c) 2019-2020 Mark Gillard <mark.gillard@outlook.com.au>
//# See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text.
#pragma once
#include "toml_formatter.h"

View File

@@ -1,3 +1,7 @@
//# This file is a part of toml++ and is subject to the the terms of the MIT license.
//# Copyright (c) 2019-2020 Mark Gillard <mark.gillard@outlook.com.au>
//# See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text.
#pragma once
#include "toml_common.h"

View File

@@ -1,3 +1,7 @@
//# This file is a part of toml++ and is subject to the the terms of the MIT license.
//# Copyright (c) 2019-2020 Mark Gillard <mark.gillard@outlook.com.au>
//# See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text.
#pragma once
#include "toml_node.h"

View File

@@ -1,3 +1,7 @@
//# This file is a part of toml++ and is subject to the the terms of the MIT license.
//# Copyright (c) 2019-2020 Mark Gillard <mark.gillard@outlook.com.au>
//# See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text.
#pragma once
#include "toml_table.h"
#include "toml_array.h"

View File

@@ -1,3 +1,7 @@
//# This file is a part of toml++ and is subject to the the terms of the MIT license.
//# Copyright (c) 2019-2020 Mark Gillard <mark.gillard@outlook.com.au>
//# See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text.
#pragma once
#include "toml_table.h"
#include "toml_utf8.h"

View File

@@ -1,3 +1,7 @@
//# This file is a part of toml++ and is subject to the the terms of the MIT license.
//# Copyright (c) 2019-2020 Mark Gillard <mark.gillard@outlook.com.au>
//# See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text.
#pragma once
#include "toml_parser.h"
@@ -444,14 +448,24 @@ TOML_IMPL_START
case U'\\': str += TOML_STRING_PREFIX('\\'); break;
// unicode scalar sequences
case U'x':
#if TOML_LANG_HIGHER_THAN(0, 5, 0)
[[fallthrough]];
#else
abort_with_error("Escape sequence '\\x' is not supported "
"in TOML 0.5.0 and earlier."sv
);
break;
#endif
case U'u': [[fallthrough]];
case U'U':
{
uint32_t place_value = escaped_codepoint == U'U' ? 0x10000000u : 0x1000u;
uint32_t place_value = escaped_codepoint == U'U' ? 0x10000000u : (escaped_codepoint == U'u' ? 0x1000u : 0x10u);
uint32_t sequence_value{};
while (place_value)
{
eof_check();
TOML_ERROR_CHECK({});
if (!is_hexadecimal_digit(*cp))
abort_with_error(
@@ -497,7 +511,6 @@ TOML_IMPL_START
str += static_cast<string_char>(0x80u | ((sequence_value >> 6) & 0x3Fu));
str += static_cast<string_char>(0x80u | (sequence_value & 0x3Fu));
}
break;
}

View File

@@ -1,3 +1,7 @@
//# This file is a part of toml++ and is subject to the the terms of the MIT license.
//# Copyright (c) 2019-2020 Mark Gillard <mark.gillard@outlook.com.au>
//# See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text.
#pragma once
#include "toml_date_time.h"

View File

@@ -1,3 +1,7 @@
//# This file is a part of toml++ and is subject to the the terms of the MIT license.
//# Copyright (c) 2019-2020 Mark Gillard <mark.gillard@outlook.com.au>
//# See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text.
#pragma once
#include "toml_array.h"

View File

@@ -1,3 +1,7 @@
//# This file is a part of toml++ and is subject to the the terms of the MIT license.
//# Copyright (c) 2019-2020 Mark Gillard <mark.gillard@outlook.com.au>
//# See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text.
#pragma once
#include "toml_table.h"
#include "toml_node_view.h"

View File

@@ -1,3 +1,8 @@
//# This file is a part of toml++ and is subject to the the terms of the MIT license.
//# Copyright (c) 2019-2020 Mark Gillard <mark.gillard@outlook.com.au>
//# Copyright (c) 2008-2010 Bjoern Hoehrmann <bjoern@hoehrmann.de> (utf8_decoder)
//# See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text.
#pragma once
#include "toml_common.h"
#include "toml_utf8_generated.h"

View File

@@ -1,4 +1,9 @@
//# this file was generated by generate_unicode_functions.py
//# This file is a part of toml++ and is subject to the the terms of the MIT license.
//# Copyright (c) 2019-2020 Mark Gillard <mark.gillard@outlook.com.au>
//# See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text.
//#-----
//# this file was generated by generate_unicode_functions.py - do not modify it directly
#pragma once
#include "toml_common.h"

View File

@@ -1,3 +1,7 @@
//# This file is a part of toml++ and is subject to the the terms of the MIT license.
//# Copyright (c) 2019-2020 Mark Gillard <mark.gillard@outlook.com.au>
//# See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text.
#pragma once
#include "toml_node.h"
#include "toml_print_to_stream.h"

View File

@@ -1,8 +1,12 @@
//# This file is a part of toml++ and is subject to the the terms of the MIT license.
//# Copyright (c) 2019-2020 Mark Gillard <mark.gillard@outlook.com.au>
//# See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text.
#pragma once
#define TOML_LIB_MAJOR 0
#define TOML_LIB_MINOR 4
#define TOML_LIB_PATCH 3
#define TOML_LIB_PATCH 4
#define TOML_LANG_MAJOR 0
#define TOML_LANG_MINOR 5