Header-only TOML config file parser and serializer for C++17.
Go to file
Mark Gillard 930bf0ad58 new file: .circleci/config.yml
new file:   .editorconfig
new file:   .gitattributes
new file:   .gitignore
new file:   .gitmodules
new file:   LICENSE
new file:   README.md
new file:   examples/example.cpp
new file:   examples/example.toml
new file:   examples/meson.build
new file:   include/toml++/toml.h
new file:   include/toml++/toml_array.h
new file:   include/toml++/toml_common.h
new file:   include/toml++/toml_formatter.h
new file:   include/toml++/toml_node.h
new file:   include/toml++/toml_node_view.h
new file:   include/toml++/toml_parser.h
new file:   include/toml++/toml_table.h
new file:   include/toml++/toml_utf8.h
new file:   include/toml++/toml_utf8_generated.h
new file:   include/toml++/toml_value.h
new file:   meson.build
new file:   python/ci_single_header_check.py
new file:   python/generate_single_header.py
new file:   python/generate_unicode_functions.py
new file:   tests/catch2
new file:   tests/catch2.h
new file:   tests/lifetimes.cpp
new file:   tests/main.cpp
new file:   tests/meson.build
new file:   tests/parsing_arrays.cpp
new file:   tests/parsing_booleans.cpp
new file:   tests/parsing_comments.cpp
new file:   tests/parsing_dates_and_times.cpp
new file:   tests/parsing_floats.cpp
new file:   tests/parsing_integers.cpp
new file:   tests/parsing_key_value_pairs.cpp
new file:   tests/parsing_spec_example.cpp
new file:   tests/parsing_strings.cpp
new file:   tests/parsing_tables.cpp
new file:   tests/tests.cpp
new file:   tests/tests.h
new file:   toml.hpp
new file:   vs/.runsettings
new file:   vs/example.vcxproj
new file:   vs/test_char.vcxproj
new file:   vs/test_char8.vcxproj
new file:   vs/test_char8_noexcept.vcxproj
new file:   vs/test_char_noexcept.vcxproj
new file:   vs/test_strict_char.vcxproj
new file:   vs/test_strict_char8.vcxproj
new file:   vs/test_strict_char8_noexcept.vcxproj
new file:   vs/test_strict_char_noexcept.vcxproj
new file:   vs/toml++.natvis
new file:   vs/toml++.props
new file:   vs/toml++.sln
new file:   vs/toml++.vcxproj
new file:   vs/toml++.vcxproj.filters
2020-01-04 16:21:38 +02:00
.circleci new file: .circleci/config.yml 2020-01-04 16:21:38 +02:00
examples new file: .circleci/config.yml 2020-01-04 16:21:38 +02:00
include/toml++ new file: .circleci/config.yml 2020-01-04 16:21:38 +02:00
python new file: .circleci/config.yml 2020-01-04 16:21:38 +02:00
tests new file: .circleci/config.yml 2020-01-04 16:21:38 +02:00
vs new file: .circleci/config.yml 2020-01-04 16:21:38 +02:00
.editorconfig new file: .circleci/config.yml 2020-01-04 16:21:38 +02:00
.gitattributes new file: .circleci/config.yml 2020-01-04 16:21:38 +02:00
.gitignore new file: .circleci/config.yml 2020-01-04 16:21:38 +02:00
.gitmodules new file: .circleci/config.yml 2020-01-04 16:21:38 +02:00
LICENSE new file: .circleci/config.yml 2020-01-04 16:21:38 +02:00
meson.build new file: .circleci/config.yml 2020-01-04 16:21:38 +02:00
README.md new file: .circleci/config.yml 2020-01-04 16:21:38 +02:00
toml.hpp new file: .circleci/config.yml 2020-01-04 16:21:38 +02:00

toml++ (tomlplusplus)

Header-only TOML v0.5.0 parsing lib for C++17 and later.

CircleCI


Usage

toml++ comes in two flavours: Regular and Single-header.

Regular mode

  1. Add tomlplusplus/include to your include paths
  2. #include <toml++/toml.h>

Single-header mode

  1. Drop toml.hpp somewhere in your source tree
  2. There is no step two

The API is the same regardless of how you consume the library. You'll find code examples in the examples directory.


Configuration

A number of configurable options are exposed in the form of preprocessor macros. Most likely you won't need to mess with these at all, but in the event you do, set your overrides prior to including toml++.

Option Type Default Description
TOML_ASSERT(expr) function macro assert(expr)
(or undefined)
Sets the assert function used by the library.
TOML_CHAR_8_STRINGS boolean 0 Uses C++20 char8_t-based strings as the toml string data type.
TOML_CONFIG_HEADER string literal undefined Includes the given header file before the rest of the library.
TOML_UNDEF_MACROS boolean 1 #undefs the library's internal macros at the end of the header.
TOML_UNRELEASED_FEATURES boolean 1 Enables support for unreleased TOML language features not yet part of a numbered version.

TOML Language Support

At any given time toml++ aims to implement whatever the numbered version of TOML is, with the addition of unreleased features from the TOML master and some sane cherry-picks from the TOML issues list where the discussion strongly indicates inclusion in a near-future release.

The library advertises the most recent numbered language version it fully supports via the preprocessor defines TOML_LANG_MAJOR, TOML_LANG_MINOR and TOML_LANG_REVISION.

🔸Unreleased features:

  • #356: Allow leading zeros in the exponent part of a float
  • #516: Allow newlines and trailing commas in inline tables
  • #562: Allow hex floatingpoint values
  • #567: Clarify that control characters are not permitted in comments
  • #571: Allow raw tabs inside strings
  • #622: Add short escaping alias \s for space (\u0020)
  • #644: Support + in key names
  • #665: Make arrays heterogeneous
  • #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

These can be disabled (and thus strict TOML v0.5.0 compliance enforced) by specifying TOML_UNRELEASED_FEATURES = 0 (see Configuration).

🔹v0.5.0 and earlier:

  • All features as of << release date >>.

Contributing

Contributions are welcome, either by reporting issues or submitting pull requests. If you wish to submit a PR, please be aware that:

  • The single-header file toml.hpp is generated by a script; make your changes in the files in include, not in toml.hpp.
  • Your changes should compile warning-free on at least gcc 8.3.0, clang 8.0, and MSVC 19.2X (Visual Studio 2019).
  • You should regenerate the single-header file as part of your PR (a CI check will fail if you don't).

Regenerating toml.hpp

  1. Make your changes as necessary
  2. If you've added a new header file that isn't going to be transitively included by one of the others, add an include directive to include/toml++/toml.h
  3. Run python/generate_single_header.py

Building and testing

Testing is done using catch2, included in the respository as a submodule under tests/catch2. The first time you want to begin testing you'll need to ensure submodules have been fetched:

git submodule update --init --recursive

Windows

Install Visual Studio 2019 and Test Adapter for Catch2, then open vs/toml++.sln and build the projects in the tests solution folder. Visual Studio's Test Explorer should pick these up and allow you to run the tests directly.

If test discovery fails, you can usually fix it by clicking enabling Auto Detect runsettings Files (settings gear icon > Configure Run Settings).

Linux

Install meson and ninja if necessary, then test with both gcc and clang:

CXX=g++ meson build-gcc
CXX=clang++ meson build-clang
cd build-gcc
ninja && ninja test
cd ../build-clang
ninja && ninja test

License and Attribution

toml++ is licensed under the terms of the MIT license - See LICENSE.

UTF-8 decoding is performed using a state machine based on Bjoern Hoehrmann's 'Flexible and Economical UTF-8 Decoder', which is itself subject to the terms of the MIT license. The license text is included in the relevant part of the toml++ source.