preprocessor + CI cleanup

also:
- minor refactors in path
- updated conformance tests
This commit is contained in:
Mark Gillard 2022-07-31 15:47:42 +03:00
parent e2edd69399
commit 501a80e231
28 changed files with 2202 additions and 1896 deletions

View File

@ -24,11 +24,12 @@ AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: Yes
AttributeMacros:
- TOML_ABSTRACT_BASE
- TOML_ABSTRACT_INTERFACE
- TOML_CALLCONV
- TOML_CLOSED_ENUM
- TOML_CLOSED_FLAGS_ENUM
- TOML_EMPTY_BASES
- TOML_EXPORTED_CLASS
- TOML_FLAGS_ENUM
- TOML_LIKELY_CASE
- TOML_OPEN_ENUM
@ -132,7 +133,6 @@ PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 1000000
PenaltyIndentedWhitespace: 0
PointerAlignment: Left
ReferenceAlignment: Left
ReflowComments: true
SortIncludes: false
SortJavaStaticImport: Before
@ -161,6 +161,8 @@ SpaceBeforeSquareBrackets: false
BitFieldColonSpacing: Both
Standard: Latest
StatementMacros:
- __pragma
- _Pragma
- TOML_ALWAYS_INLINE
- TOML_API
- TOML_ATTR
@ -177,6 +179,13 @@ StatementMacros:
- TOML_NEVER_INLINE
- TOML_NODISCARD
- TOML_NODISCARD_CTOR
- TOML_PRAGMA_CLANG
- TOML_PRAGMA_CLANG_GE_9
- TOML_PRAGMA_CLANG_GE_10
- TOML_PRAGMA_CLANG_GE_11
- TOML_PRAGMA_GCC
- TOML_PRAGMA_MSVC
- TOML_PRAGMA_ICC
- TOML_PURE_GETTER
- TOML_PURE_INLINE_GETTER
- TOML_RETURNS_BY_THROWING
@ -190,13 +199,16 @@ WhitespaceSensitiveMacros:
- BOOST_PP_STRINGIZE
- TOML_ATTR
- TOML_CONCAT
- TOML_HAS_INCLUDE
- TOML_LIKELY
- TOML_MAKE_RAW_STRING
- TOML_MAKE_STRING
- TOML_MAKE_STRING_VIEW
- TOML_PRAGMA_CLANG
- TOML_PRAGMA_CLANG_GE_9
- TOML_PRAGMA_CLANG_GE_10
- TOML_PRAGMA_CLANG_GE_11
- TOML_PRAGMA_GCC
- TOML_PRAGMA_MSVC
- TOML_PRAGMA_ICC
- TOML_UNLIKELY
...

View File

@ -29,6 +29,10 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
clang_version: '14'
gcc_version: '11'
jobs:
linux:
strategy:
@ -48,22 +52,56 @@ jobs:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Install dependencies
- name: Install base dependencies
run: |
sudo apt -y update
if [ ${{ matrix.compiler }} = clang++ ]; then compiler=clang; else compiler=${{ matrix.compiler }}; fi
sudo apt -y install --no-install-recommends $compiler ${{ matrix.linker }} pkgconf git ca-certificates locales-all python3 python3-pip python3-setuptools python3-wheel ninja-build
sudo pip3 install --upgrade meson
sudo apt -y install --no-install-recommends ${{ matrix.linker }} git python3 python3-pip ninja-build locales-all
sudo -H pip3 install --no-cache-dir --upgrade meson
- uses: actions/checkout@v3
- name: Check toml.hpp
run: |
sudo pip3 install --upgrade --requirement tools/requirements.txt
cd tools
sudo -H pip3 install --upgrade --requirement ./requirements.txt
python3 ci_single_header_check.py
- name: Update LLVM package repository
if: ${{ startsWith(matrix.compiler, 'clang') || startsWith(matrix.linker, 'lld') }}
run: |
sudo apt -y install --no-install-recommends software-properties-common wget
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
codename=$(lsb_release -sc)
sudo add-apt-repository --yes --no-update "deb http://apt.llvm.org/${codename}/ llvm-toolchain-${codename}-${{ env.clang_version }} main"
sudo apt -y update
- name: Install clang
if: ${{ startsWith(matrix.compiler, 'clang') }}
run: |
sudo apt -y install --no-install-recommends clang-${{ env.clang_version }}
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-${{ env.clang_version }} 1000
- name: Install g++
if: ${{ startsWith(matrix.compiler, 'g++') }}
run: |
sudo apt -y install --no-install-recommends g++-${{ env.gcc_version }}
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-${{ env.gcc_version }} 1000
- name: Install lld
if: ${{ startsWith(matrix.linker, 'lld') }}
run: |
sudo apt -y install --no-install-recommends lld-${{ env.clang_version }}
sudo update-alternatives --install /usr/bin/ld.lld ld.lld /usr/bin/ld.lld-${{ env.clang_version }} 1000
- name: Configure locales
run: |
sudo locale-gen 'en_US.utf8' 'ja_JP.utf8' 'de_DE.utf8' 'it_IT.utf8' 'tr_TR.utf8' 'fi_FI.utf8' 'fr_FR.utf8' 'zh_CN.utf8'
- name: Configure Meson
run: |
CXX=${{ matrix.compiler }} CXX_LD=${{ matrix.linker }} meson setup build --buildtype=${{ matrix.type }} -Dcompile_library=${{ matrix.compile_library }} -Dpedantic=true -Dbuild_tests=true -Dbuild_examples=true -Dgenerate_cmake_config=false -Db_lto=false -Dubsan_examples=true -Dasan_examples=true
@ -97,7 +135,7 @@ jobs:
python3 -m pip install -U pip==21.3.1
pip3 install meson ninja
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ilammy/msvc-dev-cmd@v1
@ -114,13 +152,14 @@ jobs:
tipi-build-linux:
name: tipi.build project build and dependency resolution
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master'
container: tipibuild/tipi-ubuntu
env:
HOME: /root
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- run: mkdir -p ~/.tipi
# checking if the tomlplusplus project builds and passes tests

View File

@ -1,6 +1,6 @@
#define TOML_ABI_NAMESPACE_BOOL(...) static_assert(true)
#define TOML_ABI_NAMESPACE_END static_assert(true)
#define TOML_ABSTRACT_BASE
#define TOML_ABSTRACT_INTERFACE
#define TOML_ALWAYS_INLINE inline
#define TOML_ANON_NAMESPACE_END static_assert(true)
#define TOML_ANON_NAMESPACE_START namespace

View File

@ -86,6 +86,7 @@ string_literals = [ '_toml' ]
'(?:toml::)?node[_ ]views?' = 'classtoml_1_1node__view.html'
'(?:toml::)?parse[_ ]errors?' = 'classtoml_1_1parse__error.html'
'(?:toml::)?parse[_ ]results?' = 'classtoml_1_1parse__result.html'
'(?:toml::)?path[_ ]components?' = 'classtoml_1_1path__component.html'
'(?:toml::)?source[_ ]positions?' = 'structtoml_1_1source__position.html'
'(?:toml::)?source[_ ]regions?' = 'structtoml_1_1source__region.html'
'(?:toml::)?time[_ ]offsets?' = 'structtoml_1_1time__offset.html'

View File

@ -139,6 +139,7 @@ TOML_NAMESPACE_START
return elems_.insert(pos, std::move(elem));
}
TOML_PURE_GETTER
TOML_EXTERNAL_LINKAGE
bool array::is_homogeneous(node_type ntype) const noexcept
{
@ -155,6 +156,7 @@ TOML_NAMESPACE_START
return true;
}
TOML_PURE_GETTER
TOML_EXTERNAL_LINKAGE
bool array::is_homogeneous(node_type ntype, node * &first_nonmatch) noexcept
{
@ -176,6 +178,7 @@ TOML_NAMESPACE_START
return true;
}
TOML_PURE_GETTER
TOML_EXTERNAL_LINKAGE
bool array::is_homogeneous(node_type ntype, const node*& first_nonmatch) const noexcept
{
@ -188,7 +191,7 @@ TOML_NAMESPACE_START
TOML_EXTERNAL_LINKAGE
node& array::at(size_t index)
{
#if TOML_COMPILER_EXCEPTIONS
#if TOML_COMPILER_HAS_EXCEPTIONS
return *elems_.at(index);

View File

@ -87,7 +87,7 @@ TOML_NAMESPACE_START
: base{ &source, nullptr, constants, { flags, " "sv } }
{}
#if defined(DOXYGEN) || (TOML_ENABLE_PARSER && !TOML_EXCEPTIONS)
#if TOML_DOXYGEN || (TOML_ENABLE_PARSER && !TOML_EXCEPTIONS)
/// \brief Constructs a JSON formatter and binds it to a toml::parse_result.
///

View File

@ -290,10 +290,10 @@ TOML_NAMESPACE_START
/// \name Iteration
/// @{
/// A const iterator for iterating over the characters in the key.
/// \brief A const iterator for iterating over the characters in the key.
using const_iterator = const char*;
/// A const iterator for iterating over the characters in the key.
/// \brief A const iterator for iterating over the characters in the key.
using iterator = const_iterator;
/// \brief Returns an iterator to the first character in the key's backing string.

View File

@ -15,7 +15,7 @@ TOML_NAMESPACE_START
///
/// \detail A parsed TOML document forms a tree made up of tables, arrays and values.
/// This type is the base of each of those, providing a lot of the polymorphic plumbing.
class TOML_ABSTRACT_BASE TOML_EXPORTED_CLASS node
class TOML_ABSTRACT_INTERFACE TOML_EXPORTED_CLASS node
{
private:
/// \cond

View File

@ -115,6 +115,7 @@ TOML_NAMESPACE_END;
TOML_IMPL_NAMESPACE_START
{
TOML_PURE_GETTER
TOML_EXTERNAL_LINKAGE
bool TOML_CALLCONV node_deep_equality(const node* lhs, const node* rhs) noexcept
{

View File

@ -12,7 +12,7 @@
#include "print_to_stream.h"
#include "header_start.h"
#if defined(DOXYGEN) || !TOML_EXCEPTIONS
#if TOML_DOXYGEN || !TOML_EXCEPTIONS
#define TOML_PARSE_ERROR_BASE
#else
#define TOML_PARSE_ERROR_BASE : public std::runtime_error

View File

@ -5,7 +5,7 @@
#pragma once
#include "preprocessor.h"
#if defined(DOXYGEN) || (TOML_ENABLE_PARSER && !TOML_EXCEPTIONS)
#if TOML_DOXYGEN || (TOML_ENABLE_PARSER && !TOML_EXCEPTIONS)
#include "table.h"
#include "parse_error.h"
@ -170,6 +170,8 @@ TOML_NAMESPACE_START
/// @}
/// \name Successful parses
/// \warning It is undefined behaviour to call these functions when the result respresents a failed parse.
/// Check #failed(), #succeeded or #operator bool() to determine the result's state.
/// @{
/// \brief Returns the internal toml::table.
@ -220,6 +222,8 @@ TOML_NAMESPACE_START
/// @}
/// \name Failed parses
/// \warning It is undefined behaviour to call these functions when the result respresents a successful parse.
/// Check #failed(), #succeeded or #operator bool() to determine the result's state.
/// @{
/// \brief Returns the internal toml::parse_error.

View File

@ -112,7 +112,7 @@ TOML_ANON_NAMESPACE_START
public:
TOML_NODISCARD_CTOR
explicit utf8_byte_stream(std::istream& stream) noexcept(!TOML_COMPILER_EXCEPTIONS) //
explicit utf8_byte_stream(std::istream& stream) noexcept(!TOML_COMPILER_HAS_EXCEPTIONS) //
: source_{ &stream }
{
if (!*this) // eof, bad
@ -147,14 +147,14 @@ TOML_ANON_NAMESPACE_START
}
TOML_NODISCARD
bool peek_eof() const noexcept(!TOML_COMPILER_EXCEPTIONS)
bool peek_eof() const noexcept(!TOML_COMPILER_HAS_EXCEPTIONS)
{
return eof() || source_->peek() == std::istream::traits_type::eof();
}
TOML_NODISCARD
TOML_ATTR(nonnull)
size_t operator()(void* dest, size_t num) noexcept(!TOML_COMPILER_EXCEPTIONS)
size_t operator()(void* dest, size_t num) noexcept(!TOML_COMPILER_HAS_EXCEPTIONS)
{
TOML_ASSERT(*this);
@ -185,16 +185,16 @@ TOML_ANON_NAMESPACE_START
static_assert(std::is_trivial_v<utf8_codepoint>);
static_assert(std::is_standard_layout_v<utf8_codepoint>);
struct TOML_ABSTRACT_BASE utf8_reader_interface
struct TOML_ABSTRACT_INTERFACE utf8_reader_interface
{
TOML_NODISCARD
virtual const source_path_ptr& source_path() const noexcept = 0;
TOML_NODISCARD
virtual const utf8_codepoint* read_next() noexcept(!TOML_COMPILER_EXCEPTIONS) = 0;
virtual const utf8_codepoint* read_next() noexcept(!TOML_COMPILER_HAS_EXCEPTIONS) = 0;
TOML_NODISCARD
virtual bool peek_eof() const noexcept(!TOML_COMPILER_EXCEPTIONS) = 0;
virtual bool peek_eof() const noexcept(!TOML_COMPILER_HAS_EXCEPTIONS) = 0;
#if !TOML_EXCEPTIONS
@ -257,7 +257,7 @@ TOML_ANON_NAMESPACE_START
optional<parse_error> err_;
#endif
bool read_next_block() noexcept(!TOML_COMPILER_EXCEPTIONS)
bool read_next_block() noexcept(!TOML_COMPILER_HAS_EXCEPTIONS)
{
TOML_ASSERT(stream_);
@ -435,7 +435,7 @@ TOML_ANON_NAMESPACE_START
}
TOML_NODISCARD
const utf8_codepoint* read_next() noexcept(!TOML_COMPILER_EXCEPTIONS) final
const utf8_codepoint* read_next() noexcept(!TOML_COMPILER_HAS_EXCEPTIONS) final
{
utf8_reader_error_check({});
@ -454,7 +454,7 @@ TOML_ANON_NAMESPACE_START
}
TOML_NODISCARD
bool peek_eof() const noexcept(!TOML_COMPILER_EXCEPTIONS) final
bool peek_eof() const noexcept(!TOML_COMPILER_HAS_EXCEPTIONS) final
{
return stream_.peek_eof();
}
@ -521,7 +521,7 @@ TOML_ANON_NAMESPACE_START
}
TOML_NODISCARD
const utf8_codepoint* read_next() noexcept(!TOML_COMPILER_EXCEPTIONS)
const utf8_codepoint* read_next() noexcept(!TOML_COMPILER_HAS_EXCEPTIONS)
{
utf8_buffered_reader_error_check({});
@ -575,7 +575,7 @@ TOML_ANON_NAMESPACE_START
}
TOML_NODISCARD
bool peek_eof() const noexcept(!TOML_COMPILER_EXCEPTIONS)
bool peek_eof() const noexcept(!TOML_COMPILER_HAS_EXCEPTIONS)
{
return reader_.peek_eof();
}
@ -2622,7 +2622,7 @@ TOML_IMPL_NAMESPACE_START
char32_t chars[utf8_buffered_reader::max_history_length];
size_t char_count = {}, advance_count = {};
bool eof_while_scanning = false;
const auto scan = [&]() noexcept(!TOML_COMPILER_EXCEPTIONS)
const auto scan = [&]() noexcept(!TOML_COMPILER_HAS_EXCEPTIONS)
{
if (is_eof())
return;

View File

@ -38,8 +38,7 @@ TOML_NAMESPACE_START
static bool TOML_CALLCONV equal(const path_component&, const path_component&) noexcept;
template <typename Type>
TOML_NODISCARD
TOML_ALWAYS_INLINE
TOML_PURE_INLINE_GETTER
static Type* get_as(storage_t& s) noexcept
{
return TOML_LAUNDER(reinterpret_cast<Type*>(s.bytes));
@ -50,7 +49,7 @@ TOML_NAMESPACE_START
::new (static_cast<void*>(storage_.bytes)) std::string{ key };
}
static void store_index(size_t index, storage_t& storage_)
static void store_index(size_t index, storage_t& storage_) noexcept
{
::new (static_cast<void*>(storage_.bytes)) std::size_t{ index };
}
@ -62,28 +61,20 @@ TOML_NAMESPACE_START
}
TOML_NODISCARD
size_t& index() & noexcept
size_t& index_ref() noexcept
{
TOML_ASSERT_ASSUME(type_ == path_component_type::array_index);
return *get_as<size_t>(value_storage_);
}
TOML_NODISCARD
std::string& key() & noexcept
std::string& key_ref() noexcept
{
TOML_ASSERT_ASSUME(type_ == path_component_type::key);
return *get_as<std::string>(value_storage_);
}
/// \brief Returns the key string (const rvalue overload).
TOML_NODISCARD
std::string&& key() && noexcept
{
TOML_ASSERT_ASSUME(type_ == path_component_type::key);
return static_cast<std::string&&>(*get_as<std::string>(value_storage_));
}
/// \endcond
public:
/// \brief Default constructor (creates an empty key).
TOML_NODISCARD_CTOR
@ -102,7 +93,9 @@ TOML_NAMESPACE_START
#if TOML_ENABLE_WINDOWS_COMPAT
/// \brief Constructor for a path component that is a key specified witha wide-char string
/// \brief Constructor for a path component that is a key string
///
/// \availability This constructor is only available when #TOML_ENABLE_WINDOWS_COMPAT is enabled.
TOML_NODISCARD_CTOR
TOML_EXPORTED_MEMBER_FUNCTION
path_component(std::wstring_view key);
@ -121,11 +114,29 @@ TOML_NAMESPACE_START
/// \brief Copy-assignment operator.
TOML_EXPORTED_MEMBER_FUNCTION
path_component& operator=(const path_component & rhs);
path_component& operator=(const path_component& rhs);
/// \brief Move-assignment operator.
TOML_EXPORTED_MEMBER_FUNCTION
path_component& operator=(path_component && rhs) noexcept;
path_component& operator=(path_component&& rhs) noexcept;
/// \brief Assigns an array index to this path component.
TOML_EXPORTED_MEMBER_FUNCTION
path_component& operator=(size_t new_index) noexcept;
/// \brief Assigns a path key to this path component.
TOML_EXPORTED_MEMBER_FUNCTION
path_component& operator=(std::string_view new_key);
#if TOML_ENABLE_WINDOWS_COMPAT
/// \brief Assigns a path key to this path component.
///
/// \availability This overload is only available when #TOML_ENABLE_WINDOWS_COMPAT is enabled.
TOML_EXPORTED_MEMBER_FUNCTION
path_component& operator=(std::wstring_view new_key);
#endif
/// \brief Destructor.
~path_component() noexcept
@ -133,61 +144,43 @@ TOML_NAMESPACE_START
destroy();
}
/// \name Array index accessors and casts
/// \name Array index accessors
/// \warning It is undefined behaviour to call these functions when the path component does not represent an array index.
/// Check #type() to determine the component's value type.
/// @{
/// \brief Returns the array index (const lvalue overload).
TOML_NODISCARD
const size_t& index() const& noexcept
TOML_PURE_GETTER
size_t index() const noexcept
{
TOML_ASSERT_ASSUME(type_ == path_component_type::array_index);
return *get_as<const size_t>(value_storage_);
}
/// \brief Returns the array index (const lvalue).
TOML_NODISCARD
/* implicit */ operator const size_t&() const noexcept
TOML_PURE_INLINE_GETTER
explicit operator size_t() const noexcept
{
return index();
}
/// @}
/// \name Key accessors and casts
/// \name Key accessors
/// \warning It is undefined behaviour to call these functions when the path component does not represent a key.
/// Check #type() to determine the component's value type.
/// @{
/// \brief Returns the key string (const lvalue overload).
TOML_NODISCARD
const std::string& key() const& noexcept
/// \brief Returns the key string.
TOML_PURE_GETTER
const std::string& key() const noexcept
{
TOML_ASSERT_ASSUME(type_ == path_component_type::key);
return *get_as<const std::string>(value_storage_);
}
/// \brief Returns the key string (const rvalue overload).
TOML_NODISCARD
const std::string&& key() const&& noexcept
{
TOML_ASSERT_ASSUME(type_ == path_component_type::key);
return static_cast<const std::string&&>(*get_as<const std::string>(value_storage_));
}
/// \brief Returns the key string.
TOML_NODISCARD
explicit operator const std::string&() noexcept
{
return key();
}
/// \brief Returns the key string (rvalue overload).
TOML_NODISCARD
explicit operator const std::string&&() noexcept
{
return std::move(key());
}
/// \brief Returns the key string (const lvalue overload).
TOML_NODISCARD
TOML_PURE_INLINE_GETTER
explicit operator const std::string&() const noexcept
{
return key();
@ -202,6 +195,9 @@ TOML_NAMESPACE_START
return type_;
}
/// \name Equality
/// @{
/// \brief Returns true if two path components represent the same key or array index.
TOML_PURE_INLINE_GETTER
friend bool operator==(const path_component& lhs, const path_component& rhs) noexcept
@ -216,22 +212,7 @@ TOML_NAMESPACE_START
return !equal(lhs, rhs);
}
/// \brief Assigns an array index to this path component. Index must castable to size_t
TOML_EXPORTED_MEMBER_FUNCTION
path_component& operator=(size_t new_index) noexcept;
/// \brief Assigns a path key to this path component. Key must be a string type
TOML_EXPORTED_MEMBER_FUNCTION
path_component& operator=(std::string_view new_key);
#if TOML_ENABLE_WINDOWS_COMPAT
/// \brief Assigns a path key to this path component using window wide char strings. Key must be a wide char string type
TOML_EXPORTED_MEMBER_FUNCTION
path_component& operator=(std::wstring_view new_key);
#endif
/// @}
};
/// \brief A TOML path.
@ -322,17 +303,19 @@ TOML_NAMESPACE_START
return components_.empty();
}
/// \brief Fetch a path component by index for modification
/// \brief Fetch a path component by index.
TOML_PURE_INLINE_GETTER
path_component& operator[](size_t index) noexcept
{
TOML_ASSERT(index < size());
return components_[index];
}
/// \brief Fetch a path component by index
/// \brief Fetch a path component by index (const overload).
TOML_PURE_INLINE_GETTER
const path_component& operator[](size_t index) const noexcept
{
TOML_ASSERT(index < size());
return components_[index];
}
@ -592,16 +575,14 @@ TOML_NAMESPACE_START
/// @{
/// \brief Returns whether two paths are the same.
TOML_NODISCARD
TOML_ALWAYS_INLINE
TOML_PURE_INLINE_GETTER
friend bool operator==(const path& lhs, const path& rhs) noexcept
{
return equal(lhs, rhs);
}
/// \brief Returns whether two paths are not the same.
TOML_NODISCARD
TOML_ALWAYS_INLINE
TOML_PURE_INLINE_GETTER
friend bool operator!=(const path& lhs, const path& rhs) noexcept
{
return !equal(lhs, rhs);
@ -685,24 +666,74 @@ TOML_NAMESPACE_START
/// @}
/// \brief Erases the contents of the path
TOML_EXPORTED_MEMBER_FUNCTION
void clear() noexcept;
/// \name Iteration
/// @{
/// \brief Iterator at the start of the vector of path components (see #toml::path_component)
TOML_NODISCARD
auto begin() const noexcept
/// An iterator for iterating over the components in the path.
/// \see #toml::path_component
using iterator = std::vector<path_component>::iterator;
/// A const iterator for iterating over the components in the path.
/// \see #toml::path_component
using const_iterator = std::vector<path_component>::const_iterator;
/// \brief Returns an iterator to the first component in the path.
/// \see #toml::path_component
TOML_PURE_INLINE_GETTER
iterator begin() noexcept
{
return components_.begin();
}
/// \brief Iterator at the end of the vector of path components (see #toml::path_component)
TOML_NODISCARD
auto end() const noexcept
/// \brief Returns an iterator to one-past-the-last component in the path.
/// \see #toml::path_component
TOML_PURE_INLINE_GETTER
iterator end() noexcept
{
return components_.end();
}
/// \brief Returns a const iterator to the first component in the path.
/// \see #toml::path_component
TOML_PURE_INLINE_GETTER
const_iterator begin() const noexcept
{
return components_.begin();
}
/// \brief Returns a const iterator to one-past-the-last component in the path.
/// \see #toml::path_component
TOML_PURE_INLINE_GETTER
const_iterator end() const noexcept
{
return components_.end();
}
/// \brief Returns a const iterator to the first component in the path.
/// \see #toml::path_component
TOML_PURE_INLINE_GETTER
const_iterator cbegin() const noexcept
{
return components_.begin();
}
/// \brief Returns a const iterator to one-past-the-last component in the path.
/// \see #toml::path_component
TOML_PURE_INLINE_GETTER
const_iterator cend() const noexcept
{
return components_.end();
}
/// @}
/// \name Subpaths and Truncation
/// @{
/// \brief Erases the contents of the path.
TOML_EXPORTED_MEMBER_FUNCTION
void clear() noexcept;
/// \brief Removes the number of terminal path components specified by n
TOML_EXPORTED_MEMBER_FUNCTION
path& truncate(size_t n);
@ -726,14 +757,15 @@ TOML_NAMESPACE_START
/// range of path components from [start, end).
TOML_NODISCARD
TOML_EXPORTED_MEMBER_FUNCTION
path subpath(std::vector<path_component>::const_iterator start,
std::vector<path_component>::const_iterator end) const;
path subpath(const_iterator start, const_iterator end) const;
/// \brief Returns a toml::path object that is a specified subpath of the current path, representing the
/// range of path components with indexes from [start, start + length].
TOML_NODISCARD
TOML_EXPORTED_MEMBER_FUNCTION
path subpath(size_t start, size_t length) const;
/// @}
};
inline namespace literals

View File

@ -54,12 +54,12 @@ TOML_NAMESPACE_START
TOML_EXTERNAL_LINKAGE
path_component::path_component(std::wstring_view key) //
: path_component(impl::narrow(key))
{ }
{}
#endif
#endif
TOML_EXTERNAL_LINKAGE
path_component::path_component(const path_component & pc) //
path_component::path_component(const path_component& pc) //
: type_{ pc.type_ }
{
if (type_ == path_component_type::array_index)
@ -73,9 +73,9 @@ TOML_NAMESPACE_START
: type_{ pc.type_ }
{
if (type_ == path_component_type::array_index)
store_index(pc.index(), value_storage_);
store_index(pc.index_ref(), value_storage_);
else
store_key(std::move(pc).key(), value_storage_);
store_key(std::move(pc.key_ref()), value_storage_);
}
TOML_EXTERNAL_LINKAGE
@ -94,9 +94,9 @@ TOML_NAMESPACE_START
else
{
if (type_ == path_component_type::array_index)
index() = rhs.index();
index_ref() = rhs.index();
else
key() = rhs.key();
key_ref() = rhs.key();
}
return *this;
}
@ -110,20 +110,21 @@ TOML_NAMESPACE_START
type_ = rhs.type_;
if (type_ == path_component_type::array_index)
store_index(std::move(rhs).index(), value_storage_);
store_index(rhs.index(), value_storage_);
else
store_key(std::move(rhs).key(), value_storage_);
store_key(std::move(rhs.key_ref()), value_storage_);
}
else
{
if (type_ == path_component_type::array_index)
index() = std::move(rhs).index();
index_ref() = rhs.index();
else
key() = std::move(rhs).key();
key_ref() = std::move(rhs.key_ref());
}
return *this;
}
TOML_PURE_GETTER
TOML_EXTERNAL_LINKAGE
bool TOML_CALLCONV path_component::equal(const path_component& lhs, const path_component& rhs) noexcept
{
@ -138,7 +139,7 @@ TOML_NAMESPACE_START
}
TOML_EXTERNAL_LINKAGE
path_component& path_component::operator= (size_t new_index) noexcept
path_component& path_component::operator=(size_t new_index) noexcept
{
// If currently a key, string will need to be destroyed regardless
destroy();
@ -150,26 +151,26 @@ TOML_NAMESPACE_START
}
TOML_EXTERNAL_LINKAGE
path_component& path_component::operator= (std::string_view new_key)
path_component& path_component::operator=(std::string_view new_key)
{
if (type_ == path_component_type::key)
key() = new_key;
key_ref() = new_key;
else
{
type_ = path_component_type::key;
store_key(new_key, value_storage_);
}
return *this;
}
#if TOML_ENABLE_WINDOWS_COMPAT
TOML_EXTERNAL_LINKAGE
path_component& path_component::operator= (std::wstring_view new_key)
path_component& path_component::operator=(std::wstring_view new_key)
{
if (type_ == path_component_type::key)
key() = impl::narrow(new_key);
key_ref() = impl::narrow(new_key);
else
{
type_ = path_component_type::key;
@ -180,7 +181,6 @@ TOML_NAMESPACE_START
}
#endif
}
TOML_NAMESPACE_END;
@ -246,6 +246,7 @@ TOML_NAMESPACE_START
}
}
TOML_PURE_GETTER
TOML_EXTERNAL_LINKAGE
bool TOML_CALLCONV path::equal(const path& lhs, const path& rhs) noexcept
{

File diff suppressed because it is too large Load Diff

View File

@ -10,7 +10,7 @@ TOML_DISABLE_WARNINGS;
#include <string>
TOML_ENABLE_WARNINGS;
#if defined(DOXYGEN) \
#if TOML_DOXYGEN \
|| (defined(__cpp_char8_t) && __cpp_char8_t >= 201811 && defined(__cpp_lib_char8_t) \
&& __cpp_lib_char8_t >= 201907)
#define TOML_HAS_CHAR8 1

View File

@ -1474,13 +1474,13 @@ TOML_NAMESPACE_START
ipos->second = std::move(static_cast<ValueArgs&&>(args)...);
else
{
#if TOML_COMPILER_EXCEPTIONS
#if TOML_COMPILER_HAS_EXCEPTIONS
try
{
#endif
ipos->second.reset(
new impl::wrap_node<unwrapped_type>{ static_cast<ValueArgs&&>(args)... });
#if TOML_COMPILER_EXCEPTIONS
#if TOML_COMPILER_HAS_EXCEPTIONS
}
catch (...)
{

View File

@ -106,6 +106,7 @@ TOML_NAMESPACE_START
return *this;
}
TOML_PURE_GETTER
TOML_EXTERNAL_LINKAGE
bool table::is_homogeneous(node_type ntype) const noexcept
{
@ -125,6 +126,7 @@ TOML_NAMESPACE_START
return true;
}
TOML_PURE_GETTER
TOML_EXTERNAL_LINKAGE
bool table::is_homogeneous(node_type ntype, node * &first_nonmatch) noexcept
{
@ -147,6 +149,7 @@ TOML_NAMESPACE_START
return true;
}
TOML_PURE_GETTER
TOML_EXTERNAL_LINKAGE
bool table::is_homogeneous(node_type ntype, const node*& first_nonmatch) const noexcept
{
@ -156,6 +159,7 @@ TOML_NAMESPACE_START
return result;
}
TOML_PURE_GETTER
TOML_EXTERNAL_LINKAGE
node* table::get(std::string_view key) noexcept
{
@ -169,7 +173,7 @@ TOML_NAMESPACE_START
{
auto n = get(key);
#if TOML_COMPILER_EXCEPTIONS
#if TOML_COMPILER_HAS_EXCEPTIONS
if (!n)
{
@ -188,18 +192,21 @@ TOML_NAMESPACE_START
return *n;
}
TOML_PURE_GETTER
TOML_EXTERNAL_LINKAGE
table::map_iterator table::get_lower_bound(std::string_view key) noexcept
{
return map_.lower_bound(key);
}
TOML_PURE_GETTER
TOML_EXTERNAL_LINKAGE
table::iterator table::find(std::string_view key) noexcept
{
return iterator{ map_.find(key) };
}
TOML_PURE_GETTER
TOML_EXTERNAL_LINKAGE
table::const_iterator table::find(std::string_view key) const noexcept
{
@ -277,6 +284,7 @@ TOML_NAMESPACE_START
return map_.emplace_hint(const_map_iterator{ hint }, std::move(k), std::move(v));
}
TOML_PURE_GETTER
TOML_EXTERNAL_LINKAGE
bool TOML_CALLCONV table::equal(const table& lhs, const table& rhs) noexcept
{

View File

@ -99,7 +99,7 @@ TOML_NAMESPACE_START
: base{ &source, nullptr, constants, { flags, " "sv } }
{}
#if defined(DOXYGEN) || (TOML_ENABLE_PARSER && !TOML_EXCEPTIONS)
#if TOML_DOXYGEN || (TOML_ENABLE_PARSER && !TOML_EXCEPTIONS)
/// \brief Constructs a TOML formatter and binds it to a toml::parse_result.
///

View File

@ -17,6 +17,7 @@
TOML_IMPL_NAMESPACE_START
{
TOML_PURE_GETTER
TOML_EXTERNAL_LINKAGE
bool is_ascii(const char* str, size_t len) noexcept
{

View File

@ -86,7 +86,7 @@ TOML_NAMESPACE_START
: base{ &source, nullptr, constants, { flags, " "sv } }
{}
#if defined(DOXYGEN) || (TOML_ENABLE_PARSER && !TOML_EXCEPTIONS)
#if TOML_DOXYGEN || (TOML_ENABLE_PARSER && !TOML_EXCEPTIONS)
/// \brief Constructs a YAML formatter and binds it to a toml::parse_result.
///

View File

@ -85,7 +85,7 @@ TOML_POP_WARNINGS;
#undef TOML_ABI_NAMESPACE_END
#undef TOML_ABI_NAMESPACE_START
#undef TOML_ABI_NAMESPACES
#undef TOML_ABSTRACT_BASE
#undef TOML_ABSTRACT_INTERFACE
#undef TOML_ALWAYS_INLINE
#undef TOML_ANON_NAMESPACE
#undef TOML_ANON_NAMESPACE_END
@ -99,11 +99,14 @@ TOML_POP_WARNINGS;
#undef TOML_CLANG
#undef TOML_CLOSED_ENUM
#undef TOML_CLOSED_FLAGS_ENUM
#undef TOML_COMPILER_EXCEPTIONS
#undef TOML_COMPILER_HAS_EXCEPTIONS
#undef TOML_COMPILER_HAS_RTTI
#undef TOML_CONST
#undef TOML_CONST_GETTER
#undef TOML_CONST_INLINE_GETTER
#undef TOML_CONSTRAINED_TEMPLATE
#undef TOML_CPP_VERSION
#undef TOML_CPP
#undef TOML_DECLSPEC
#undef TOML_DELETE_DEFAULTS
#undef TOML_DISABLE_ARITHMETIC_WARNINGS
#undef TOML_DISABLE_CODE_ANALYSIS_WARNINGS
@ -113,6 +116,7 @@ TOML_POP_WARNINGS;
#undef TOML_DISABLE_SUGGEST_ATTR_WARNINGS
#undef TOML_DISABLE_SWITCH_WARNINGS
#undef TOML_DISABLE_WARNINGS
#undef TOML_DOXYGEN
#undef TOML_EMPTY_BASES
#undef TOML_ENABLE_IF
#undef TOML_ENABLE_WARNINGS
@ -126,8 +130,11 @@ TOML_POP_WARNINGS;
#undef TOML_FP16
#undef TOML_GCC
#undef TOML_HAS_ATTR
#undef TOML_HAS_BUILTIN
#undef TOML_HAS_CHAR8
#undef TOML_HAS_CPP_ATTR
#undef TOML_HAS_CUSTOM_OPTIONAL_TYPE
#undef TOML_HAS_FEATURE
#undef TOML_HAS_INCLUDE
#undef TOML_HAS_SSE2
#undef TOML_HAS_SSE4_1
@ -152,6 +159,10 @@ TOML_POP_WARNINGS;
#undef TOML_LIKELY_CASE
#undef TOML_MAKE_FLAGS
#undef TOML_MAKE_FLAGS_
#undef TOML_MAKE_FLAGS_1
#undef TOML_MAKE_FLAGS_2
#undef TOML_MAKE_STRING
#undef TOML_MAKE_STRING_1
#undef TOML_MAKE_VERSION
#undef TOML_MSVC
#undef TOML_NAMESPACE
@ -162,6 +173,14 @@ TOML_POP_WARNINGS;
#undef TOML_OPEN_FLAGS_ENUM
#undef TOML_PARSER_TYPENAME
#undef TOML_POP_WARNINGS
#undef TOML_PRAGMA_CLANG
#undef TOML_PRAGMA_CLANG_GE_10
#undef TOML_PRAGMA_CLANG_GE_11
#undef TOML_PRAGMA_CLANG_GE_9
#undef TOML_PRAGMA_GCC
#undef TOML_PRAGMA_ICC
#undef TOML_PRAGMA_MSVC
#undef TOML_PURE
#undef TOML_PURE_GETTER
#undef TOML_PURE_INLINE_GETTER
#undef TOML_PUSH_WARNINGS
@ -187,6 +206,7 @@ TOML_POP_WARNINGS;
#undef TOML_UNLIKELY_CASE
#undef TOML_UNREACHABLE
#undef TOML_UNUSED
#undef TOML_WINDOWS
#endif
#endif // TOMLPLUSPLUS_H

View File

@ -1,5 +1,8 @@
#ifndef TOML_IMPLEMENTATION
#define TOML_IMPLEMENTATION
#endif
#ifndef TOML_HEADER_ONLY
#define TOML_HEADER_ONLY 0
#endif
#include <toml++/toml.h>

View File

@ -9,6 +9,14 @@
namespace
{
static constexpr auto array_double_comma_1 = R"(array = [1,,2])"sv;
static constexpr auto array_double_comma_2 = R"(array = [1,2,,])"sv;
static constexpr auto array_extending_table = R"(a = [{ b = 1 }]
# Cannot extend tables within static arrays
# https://github.com/toml-lang/toml/issues/908
[a.c]
foo = 1)"sv;
static constexpr auto array_missing_separator = R"(wrong = [ 1 2 3 ])"sv;
static constexpr auto array_no_close_2 = R"(x = [42 #)"sv;
static constexpr auto array_no_close_table_2 = R"(x = [{ key = 42 #)"sv;
@ -276,16 +284,21 @@ key""" = 1)"sv;
static constexpr auto key_no_eol = R"(a = 1 b = 2)"sv;
static constexpr auto key_open_bracket = R"([abc = 1)"sv;
static constexpr auto key_partial_quoted = R"(partial"quoted" = 5)"sv;
static constexpr auto key_quoted_unclosed_1 = R"("key = x)"sv;
static constexpr auto key_quoted_unclosed_2 = R"("key)"sv;
static constexpr auto key_single_open_bracket = R"([)"sv;
static constexpr auto key_space = R"(a b = 1)"sv;
static constexpr auto key_start_bracket = R"([a]
[xyz = 5
[b])"sv;
static constexpr auto key_start_dot = R"(.key = 1)"sv;
static constexpr auto key_two_equals = R"(key= = 1)"sv;
static constexpr auto key_two_equals2 = R"(a==1)"sv;
static constexpr auto key_two_equals3 = R"(a=b=1)"sv;
static constexpr auto key_without_value_1 = R"(key)"sv;
static constexpr auto key_without_value_2 = R"(key = )"sv;
static constexpr auto key_without_value_3 = R"("key")"sv;
static constexpr auto key_without_value_4 = R"("key" = )"sv;
#if !TOML_LANG_UNRELEASED && UNICODE_LITERALS_OK
@ -303,7 +316,11 @@ key""" = 1)"sv;
second line")"sv;
static constexpr auto string_bad_slash_escape =
R"(invalid-escape = "This string has a bad \/ escape character.")"sv;
static constexpr auto string_bad_uni_esc = R"(str = "val\ue")"sv;
static constexpr auto string_bad_uni_esc_1 = R"(str = "val\ue")"sv;
static constexpr auto string_bad_uni_esc_2 = R"(str = "val\Ux")"sv;
static constexpr auto string_bad_uni_esc_3 = R"(str = "val\U0000000")"sv;
static constexpr auto string_bad_uni_esc_4 = R"(str = "val\U0000")"sv;
static constexpr auto string_bad_uni_esc_5 = R"(str = "val\Ugggggggg")"sv;
static constexpr auto string_basic_multiline_out_of_range_unicode_escape_1 = R"(a = """\UFFFFFFFF""")"sv;
static constexpr auto string_basic_multiline_out_of_range_unicode_escape_2 = R"(a = """\U00D80000""")"sv;
static constexpr auto string_basic_multiline_quotes = R"(str5 = """Here are three quotation marks: """.""")"sv;
@ -428,6 +445,12 @@ answer = 42)"sv;
TEST_CASE("conformance - burntsushi/invalid")
{
parsing_should_fail(FILE_LINE_ARGS, array_double_comma_1); // array-double-comma-1
parsing_should_fail(FILE_LINE_ARGS, array_double_comma_2); // array-double-comma-2
parsing_should_fail(FILE_LINE_ARGS, array_extending_table); // array-extending-table
parsing_should_fail(FILE_LINE_ARGS, array_missing_separator); // array-missing-separator
parsing_should_fail(FILE_LINE_ARGS, array_no_close_2); // array-no-close-2
@ -758,12 +781,18 @@ TEST_CASE("conformance - burntsushi/invalid")
parsing_should_fail(FILE_LINE_ARGS, key_partial_quoted); // key-partial-quoted
parsing_should_fail(FILE_LINE_ARGS, key_quoted_unclosed_1); // key-quoted-unclosed-1
parsing_should_fail(FILE_LINE_ARGS, key_quoted_unclosed_2); // key-quoted-unclosed-2
parsing_should_fail(FILE_LINE_ARGS, key_single_open_bracket); // key-single-open-bracket
parsing_should_fail(FILE_LINE_ARGS, key_space); // key-space
parsing_should_fail(FILE_LINE_ARGS, key_start_bracket); // key-start-bracket
parsing_should_fail(FILE_LINE_ARGS, key_start_dot); // key-start-dot
parsing_should_fail(FILE_LINE_ARGS, key_two_equals); // key-two-equals
parsing_should_fail(FILE_LINE_ARGS, key_two_equals2); // key-two-equals2
@ -774,6 +803,10 @@ TEST_CASE("conformance - burntsushi/invalid")
parsing_should_fail(FILE_LINE_ARGS, key_without_value_2); // key-without-value-2
parsing_should_fail(FILE_LINE_ARGS, key_without_value_3); // key-without-value-3
parsing_should_fail(FILE_LINE_ARGS, key_without_value_4); // key-without-value-4
#if !TOML_LANG_UNRELEASED && UNICODE_LITERALS_OK
parsing_should_fail(FILE_LINE_ARGS, key_special_character); // key-special-character
@ -794,7 +827,15 @@ TEST_CASE("conformance - burntsushi/invalid")
parsing_should_fail(FILE_LINE_ARGS, string_bad_slash_escape); // string-bad-slash-escape
parsing_should_fail(FILE_LINE_ARGS, string_bad_uni_esc); // string-bad-uni-esc
parsing_should_fail(FILE_LINE_ARGS, string_bad_uni_esc_1); // string-bad-uni-esc-1
parsing_should_fail(FILE_LINE_ARGS, string_bad_uni_esc_2); // string-bad-uni-esc-2
parsing_should_fail(FILE_LINE_ARGS, string_bad_uni_esc_3); // string-bad-uni-esc-3
parsing_should_fail(FILE_LINE_ARGS, string_bad_uni_esc_4); // string-bad-uni-esc-4
parsing_should_fail(FILE_LINE_ARGS, string_bad_uni_esc_5); // string-bad-uni-esc-5
parsing_should_fail(
FILE_LINE_ARGS,

View File

@ -30,7 +30,14 @@ comments = [
static constexpr auto array_mixed_string_table = R"(contributors = [
"Foo Bar <foo@example.com>",
{ name = "Baz Qux", email = "bazqux@example.com", url = "https://example.com/bazqux" }
])"sv;
]
# Start with a table as the first element. This tests a case that some libraries
# might have where they will check if the first entry is a table/map/hash/assoc
# array and then encode it as a table array. This was a reasonable thing to do
# before TOML 1.0 since arrays could only contain one type, but now it's no
# longer.
mixed = [{k="a"}, "b", 1])"sv;
static constexpr auto array_nested_double = R"(nest = [
[
["a"],
@ -361,8 +368,13 @@ plain = 3
[table.withdot]
plain = 5
"key.with.dots" = 6)"sv;
static constexpr auto key_space = R"("a b" = 1)"sv;
static constexpr auto key_special_chars = R"("~!@$^&*()_+-`1234567890[]|/?><.,;:'" = 1)"sv;
static constexpr auto key_space = R"(# Keep whitespace inside quotes keys at all positions.
"a b" = 1
" c d " = 2
[ " tbl " ]
"\ttab\ttab\t" = "tab")"sv;
static constexpr auto key_special_chars = R"("=~!@$^&*()_+-`1234567890[]|/?><.,;:'=" = 1)"sv;
static constexpr auto key_special_word = R"(false = false
true = 1
inf = 100000000
@ -822,6 +834,14 @@ TEST_CASE("conformance - burntsushi/valid")
{ R"(url)"sv, R"(https://example.com/bazqux)"sv },
},
} },
{ R"(mixed)"sv,
toml::array{
toml::table{
{ R"(k)"sv, R"(a)"sv },
},
R"(b)"sv,
1,
} },
};
REQUIRE(tbl == expected);
});
@ -1949,6 +1969,11 @@ another line)"sv },
[](toml::table&& tbl) // key-space
{
const auto expected = toml::table{
{ R"( c d )"sv, 2 },
{ R"( tbl )"sv,
toml::table{
{ R"( tab tab )"sv, R"(tab)"sv },
} },
{ R"(a b)"sv, 1 },
};
REQUIRE(tbl == expected);
@ -1959,7 +1984,7 @@ another line)"sv },
[](toml::table&& tbl) // key-special-chars
{
const auto expected = toml::table{
{ R"(~!@$^&*()_+-`1234567890[]|/?><.,;:')"sv, 1 },
{ R"(=~!@$^&*()_+-`1234567890[]|/?><.,;:'=)"sv, 1 },
};
REQUIRE(tbl == expected);
});

View File

@ -581,5 +581,4 @@ TEST_CASE("path - accessing")
CHECK(tbl["d"][""]);
CHECK(tbl["d"][""] == tbl[toml::path("d.")]);
}
}

View File

@ -26,11 +26,11 @@
#if defined(TOML_INT128) ^ defined(TOML_UINT128)
#error TOML_INT128 and TOML_UINT128 must both be defined, or neither be defined
#endif
#if TOML_COMPILER_EXCEPTIONS ^ SHOULD_HAVE_EXCEPTIONS
#error TOML_COMPILER_EXCEPTIONS was not deduced correctly
#if TOML_COMPILER_HAS_EXCEPTIONS ^ SHOULD_HAVE_EXCEPTIONS
#error TOML_COMPILER_HAS_EXCEPTIONS was not deduced correctly
#endif
#if TOML_COMPILER_EXCEPTIONS ^ TOML_EXCEPTIONS
#error TOML_EXCEPTIONS does not match TOML_COMPILER_EXCEPTIONS (default behaviour should be to match)
#if TOML_COMPILER_HAS_EXCEPTIONS ^ TOML_EXCEPTIONS
#error TOML_EXCEPTIONS does not match TOML_COMPILER_HAS_EXCEPTIONS (default behaviour should be to match)
#endif
#if defined(_WIN32) ^ TOML_ENABLE_WINDOWS_COMPAT
#error TOML_ENABLE_WINDOWS_COMPAT does not match _WIN32 (default behaviour should be to match)

1759
toml.hpp

File diff suppressed because it is too large Load Diff