2021-10-23 09:22:41 +00:00
|
|
|
//# This file is a part of toml++ and is subject to the the terms of the MIT license.
|
|
|
|
//# Copyright (c) Mark Gillard <mark.gillard@outlook.com.au>
|
|
|
|
//# See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text.
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
#pragma once
|
2021-11-02 20:13:09 +00:00
|
|
|
|
2022-02-26 12:42:09 +00:00
|
|
|
#include "unicode_autogenerated.h"
|
2021-10-24 10:21:32 +00:00
|
|
|
#include "header_start.h"
|
2021-10-23 09:22:41 +00:00
|
|
|
/// \cond
|
2021-11-02 20:13:09 +00:00
|
|
|
|
2021-10-23 09:22:41 +00:00
|
|
|
TOML_IMPL_NAMESPACE_START
|
|
|
|
{
|
2021-11-04 22:43:42 +00:00
|
|
|
TOML_CONST_GETTER
|
|
|
|
constexpr bool is_string_delimiter(char32_t c) noexcept
|
2021-11-04 09:56:03 +00:00
|
|
|
{
|
2021-11-04 22:43:42 +00:00
|
|
|
return c == U'"' || c == U'\'';
|
2021-11-04 09:56:03 +00:00
|
|
|
}
|
|
|
|
|
2021-10-29 08:12:41 +00:00
|
|
|
TOML_CONST_GETTER
|
2021-11-04 22:43:42 +00:00
|
|
|
constexpr bool is_ascii_letter(char32_t c) noexcept
|
2021-10-23 09:22:41 +00:00
|
|
|
{
|
2021-11-04 22:43:42 +00:00
|
|
|
return (c >= U'a' && c <= U'z') || (c >= U'A' && c <= U'Z');
|
2021-10-23 09:22:41 +00:00
|
|
|
}
|
|
|
|
|
2021-10-29 08:12:41 +00:00
|
|
|
TOML_CONST_GETTER
|
2021-11-04 22:43:42 +00:00
|
|
|
constexpr bool is_binary_digit(char32_t c) noexcept
|
2021-10-23 09:22:41 +00:00
|
|
|
{
|
2021-11-04 22:43:42 +00:00
|
|
|
return c == U'0' || c == U'1';
|
2021-10-23 09:22:41 +00:00
|
|
|
}
|
|
|
|
|
2021-10-29 08:12:41 +00:00
|
|
|
TOML_CONST_GETTER
|
2021-11-04 22:43:42 +00:00
|
|
|
constexpr bool is_octal_digit(char32_t c) noexcept
|
2021-10-23 09:22:41 +00:00
|
|
|
{
|
2021-11-04 22:43:42 +00:00
|
|
|
return (c >= U'0' && c <= U'7');
|
2021-10-23 09:22:41 +00:00
|
|
|
}
|
|
|
|
|
2021-10-29 08:12:41 +00:00
|
|
|
TOML_CONST_GETTER
|
2021-11-04 22:43:42 +00:00
|
|
|
constexpr bool is_decimal_digit(char32_t c) noexcept
|
2021-10-23 09:22:41 +00:00
|
|
|
{
|
2021-11-04 22:43:42 +00:00
|
|
|
return (c >= U'0' && c <= U'9');
|
2021-10-23 09:22:41 +00:00
|
|
|
}
|
|
|
|
|
2021-10-29 08:12:41 +00:00
|
|
|
TOML_CONST_GETTER
|
2021-11-04 22:43:42 +00:00
|
|
|
constexpr bool is_hexadecimal_digit(char32_t c) noexcept
|
2021-10-23 09:22:41 +00:00
|
|
|
{
|
2021-11-04 22:43:42 +00:00
|
|
|
return U'0' <= c && c <= U'f' && (1ull << (static_cast<uint_least64_t>(c) - 0x30u)) & 0x7E0000007E03FFull;
|
2021-10-23 09:22:41 +00:00
|
|
|
}
|
|
|
|
|
2021-11-04 22:43:42 +00:00
|
|
|
template <typename T>
|
2021-10-29 08:12:41 +00:00
|
|
|
TOML_CONST_GETTER
|
2021-11-04 22:43:42 +00:00
|
|
|
constexpr uint_least32_t hex_to_dec(const T c) noexcept
|
2021-10-23 09:22:41 +00:00
|
|
|
{
|
2021-11-04 22:43:42 +00:00
|
|
|
if constexpr (std::is_same_v<remove_cvref<T>, uint_least32_t>)
|
|
|
|
return c >= 0x41u // >= 'A'
|
|
|
|
? 10u + (c | 0x20u) - 0x61u // - 'a'
|
|
|
|
: c - 0x30u // - '0'
|
|
|
|
;
|
|
|
|
else
|
|
|
|
return hex_to_dec(static_cast<uint_least32_t>(c));
|
2021-10-23 09:22:41 +00:00
|
|
|
}
|
|
|
|
|
2021-10-29 08:12:41 +00:00
|
|
|
TOML_CONST_GETTER
|
2021-11-04 22:43:42 +00:00
|
|
|
constexpr bool is_bare_key_character(char32_t c) noexcept
|
2021-10-23 09:22:41 +00:00
|
|
|
{
|
2021-11-04 22:43:42 +00:00
|
|
|
return is_ascii_bare_key_character(c)
|
2022-01-04 14:23:45 +00:00
|
|
|
#if TOML_LANG_UNRELEASED // toml/issues/687 (unicode bare keys)
|
2021-11-04 22:43:42 +00:00
|
|
|
|| is_non_ascii_bare_key_character(c)
|
2021-10-23 09:22:41 +00:00
|
|
|
#endif
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
2021-10-29 08:12:41 +00:00
|
|
|
TOML_CONST_GETTER
|
2021-11-04 22:43:42 +00:00
|
|
|
constexpr bool is_value_terminator(char32_t c) noexcept
|
2021-10-23 09:22:41 +00:00
|
|
|
{
|
2021-11-04 22:43:42 +00:00
|
|
|
return is_whitespace(c) || c == U']' || c == U'}' || c == U',' || c == U'#';
|
2021-10-23 09:22:41 +00:00
|
|
|
}
|
|
|
|
|
2022-01-04 14:23:45 +00:00
|
|
|
TOML_CONST_GETTER
|
|
|
|
constexpr bool is_control_character(char c) noexcept
|
|
|
|
{
|
|
|
|
return c <= '\u001F' || c == '\u007F';
|
|
|
|
}
|
|
|
|
|
2021-10-29 08:12:41 +00:00
|
|
|
TOML_CONST_GETTER
|
2021-11-04 22:43:42 +00:00
|
|
|
constexpr bool is_control_character(char32_t c) noexcept
|
2021-10-23 09:22:41 +00:00
|
|
|
{
|
2021-11-04 22:43:42 +00:00
|
|
|
return c <= U'\u001F' || c == U'\u007F';
|
2021-10-23 09:22:41 +00:00
|
|
|
}
|
|
|
|
|
2021-10-29 08:12:41 +00:00
|
|
|
TOML_CONST_GETTER
|
2021-11-04 22:43:42 +00:00
|
|
|
constexpr bool is_nontab_control_character(char32_t c) noexcept
|
2021-10-23 09:22:41 +00:00
|
|
|
{
|
2021-11-04 22:43:42 +00:00
|
|
|
return c <= U'\u0008' || (c >= U'\u000A' && c <= U'\u001F') || c == U'\u007F';
|
2021-10-23 09:22:41 +00:00
|
|
|
}
|
|
|
|
|
2021-10-29 08:12:41 +00:00
|
|
|
TOML_CONST_GETTER
|
2021-11-04 22:43:42 +00:00
|
|
|
constexpr bool is_unicode_surrogate(char32_t c) noexcept
|
2021-10-23 09:22:41 +00:00
|
|
|
{
|
2021-11-04 22:43:42 +00:00
|
|
|
return c >= 0xD800u && c <= 0xDFFF;
|
2021-10-23 09:22:41 +00:00
|
|
|
}
|
|
|
|
|
2021-10-26 18:03:56 +00:00
|
|
|
struct utf8_decoder
|
2021-10-23 09:22:41 +00:00
|
|
|
{
|
|
|
|
// utf8_decoder based on this: https://bjoern.hoehrmann.de/utf-8/decoder/dfa/
|
|
|
|
// Copyright (c) 2008-2009 Bjoern Hoehrmann <bjoern@hoehrmann.de>
|
|
|
|
|
|
|
|
uint_least32_t state{};
|
|
|
|
char32_t codepoint{};
|
|
|
|
|
|
|
|
static constexpr uint8_t state_table[]{
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1,
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7, 7,
|
|
|
|
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
|
|
|
7, 7, 7, 8, 8, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
|
|
|
2, 2, 2, 2, 2, 2, 2, 2, 10, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 3, 3, 11, 6, 6,
|
|
|
|
6, 5, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
|
|
|
|
|
|
|
|
0, 12, 24, 36, 60, 96, 84, 12, 12, 12, 48, 72, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 0, 12,
|
|
|
|
12, 12, 12, 12, 0, 12, 0, 12, 12, 12, 24, 12, 12, 12, 12, 12, 24, 12, 24, 12, 12, 12, 12, 12, 12, 12, 12,
|
|
|
|
12, 24, 12, 12, 12, 12, 12, 24, 12, 12, 12, 12, 12, 12, 12, 24, 12, 12, 12, 12, 12, 12, 12, 12, 12, 36, 12,
|
|
|
|
36, 12, 12, 12, 36, 12, 12, 12, 12, 12, 36, 12, 36, 12, 12, 12, 36, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12
|
|
|
|
};
|
|
|
|
|
2021-10-29 08:12:41 +00:00
|
|
|
TOML_PURE_INLINE_GETTER
|
2021-10-23 09:22:41 +00:00
|
|
|
constexpr bool error() const noexcept
|
|
|
|
{
|
|
|
|
return state == uint_least32_t{ 12u };
|
|
|
|
}
|
|
|
|
|
2021-10-29 08:12:41 +00:00
|
|
|
TOML_PURE_INLINE_GETTER
|
2021-10-23 09:22:41 +00:00
|
|
|
constexpr bool has_code_point() const noexcept
|
|
|
|
{
|
|
|
|
return state == uint_least32_t{};
|
|
|
|
}
|
|
|
|
|
2021-10-29 20:59:53 +00:00
|
|
|
TOML_PURE_INLINE_GETTER
|
2021-10-23 09:22:41 +00:00
|
|
|
constexpr bool needs_more_input() const noexcept
|
|
|
|
{
|
2021-11-04 22:43:42 +00:00
|
|
|
return !has_code_point() && !error();
|
2021-10-23 09:22:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
constexpr void operator()(uint8_t byte) noexcept
|
|
|
|
{
|
2021-11-14 17:24:19 +00:00
|
|
|
TOML_ASSERT_ASSUME(!error());
|
2021-10-23 09:22:41 +00:00
|
|
|
|
|
|
|
const auto type = state_table[byte];
|
|
|
|
|
|
|
|
codepoint = static_cast<char32_t>(has_code_point() ? (uint_least32_t{ 255u } >> type) & byte
|
|
|
|
: (byte & uint_least32_t{ 63u })
|
|
|
|
| (static_cast<uint_least32_t>(codepoint) << 6));
|
|
|
|
|
|
|
|
state = state_table[state + uint_least32_t{ 256u } + type];
|
|
|
|
}
|
2021-10-29 08:12:41 +00:00
|
|
|
|
2022-01-04 14:23:45 +00:00
|
|
|
TOML_ALWAYS_INLINE
|
|
|
|
constexpr void operator()(char c) noexcept
|
|
|
|
{
|
|
|
|
operator()(static_cast<uint8_t>(c));
|
|
|
|
}
|
|
|
|
|
2021-10-29 08:12:41 +00:00
|
|
|
TOML_ALWAYS_INLINE
|
|
|
|
constexpr void reset() noexcept
|
|
|
|
{
|
|
|
|
state = {};
|
|
|
|
}
|
2021-10-23 09:22:41 +00:00
|
|
|
};
|
2022-01-04 14:23:45 +00:00
|
|
|
|
|
|
|
TOML_PURE_GETTER
|
|
|
|
TOML_ATTR(nonnull)
|
|
|
|
bool is_ascii(const char* str, size_t len) noexcept;
|
2021-10-23 09:22:41 +00:00
|
|
|
}
|
|
|
|
TOML_IMPL_NAMESPACE_END;
|
|
|
|
|
2021-11-04 22:43:42 +00:00
|
|
|
#if TOML_GCC && TOML_GCC < 9
|
|
|
|
#pragma GCC pop_options
|
|
|
|
#endif
|
|
|
|
|
2021-11-02 20:13:09 +00:00
|
|
|
/// \endcond
|
2021-10-24 10:21:32 +00:00
|
|
|
#include "header_end.h"
|