Skip to content

Commit 2219fd2

Browse files
committed
release 0.1.0
- added `toml::is_number<>` - added `toml::node_type::none` - added initializer_list and vector relops to `toml::array` - added constructors for `time_offset` and `date_time` - added much to `node_view` - added tests for `node_view` value relops - added lots more documentation - removed `time_offset::from_hh_mm` - removed the handling of `\s` literals (looks like it's not going be accepted as-is)
1 parent 0b4eca3 commit 2219fd2

21 files changed

+1019
-513
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,14 @@ addition of unreleased features from the [TOML master] and some sane cherry-pick
9696
[TOML issues list] where the discussion strongly indicates inclusion in a near-future release.
9797
9898
The library advertises the most recent numbered language version it fully supports via the preprocessor
99-
defines `TOML_LANG_MAJOR`, `TOML_LANG_MINOR` and `TOML_LANG_REVISION`.
99+
defines `TOML_LANG_MAJOR`, `TOML_LANG_MINOR` and `TOML_LANG_PATCH`.
100100
101101
### **🔸Unreleased TOML features:**
102102
- [#356]: Allow leading zeros in the exponent part of a float
103103
- [#516]: Allow newlines and trailing commas in inline tables
104104
- [#562]: Allow hex floatingpoint values
105105
- [#567]: Clarify that control characters are not permitted in comments
106106
- [#571]: Allow raw tabs inside strings
107-
- [#622]: Add short escaping alias `\s` for space (`\u0020`)
108107
- [#644]: Support `+` in key names
109108
- [#665]: Make arrays heterogeneous
110109
- [#671]: Local time of day format should support `09:30` as opposed to `09:30:00`
@@ -167,7 +166,7 @@ cd ../build-clang && ninja && ninja test
167166
UTF-8 decoding is performed using a state machine based on Bjoern Hoehrmann's '[Flexible and Economical UTF-8 Decoder]',
168167
which is also subject to the terms of the MIT license - see [LICENSE-utf8-decoder].
169168

170-
[API documentation]: https://marzer.github.io/tomlplusplus/namespacetoml.html
169+
[API documentation]: https://marzer.github.io/tomlplusplus/
171170
[unreleased TOML language features]: https://github.com/marzer/tomlplusplus#unreleased-features
172171
[numbered version]: https://github.com/toml-lang/toml/releases
173172
[char8_t]: https://en.cppreference.com/w/cpp/keyword/char8_t

docs/tomlplusplus.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ pre.m-code + pre
8989
{
9090
margin-top: -1.0rem;
9191
color: #bababa; /* is yououou */
92-
background-color: #282e36aa;
92+
background-color: #383e46;
93+
border-top: 2px solid #181e26;
9394
font-size: 0.8rem;
9495
}
9596

include/toml++/toml.h

Lines changed: 244 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,24 +52,217 @@
5252
#undef TOML_STRING_PREFIX
5353
#undef TOML_UNDEF_MACROS
5454
#undef TOML_DOXYGEN
55+
#undef TOML_RELOPS_REORDERING
56+
#undef TOML_ASYMMETRICAL_EQUALITY_OPS
5557
#endif
5658

5759
/// \mainpage toml++
5860
///
59-
/// This is the home of the API documentation for toml++, a [TOML](https://github.com/toml-lang/toml) parser for C++17 and later.
60-
/// If you're looking for information about how to add toml++ to your project etc, see the
61-
/// see [README](https://github.com/marzer/tomlplusplus/blob/master/README.md) on GitHub.
62-
/// Otherwise, browse the docs using the links at the top of the page. You can search from anywhere by pressing the TAB key.
61+
/// This is the home of toml++, a header-only [TOML](https://github.com/toml-lang/toml) parser and serializer for C++17 and later.
62+
///
63+
/// \tableofcontents
6364
///
64-
/// <em>Obviously this page is pretty sparse and could do with some more content. If you have concrete suggestions for what
65-
/// should go here, please [let me know](https://github.com/marzer/tomlplusplus/issues)!</em>
65+
///////////////////////////////////////////////////////////////////////
6666
///
67+
/// \section mainpage-features Features
68+
/// - C++17 (plus some C++20 features where supported, e.g. char8_t strings)
69+
/// - Proper UTF-8 handling (incl. BOM)
70+
/// - Works with or without exceptions
71+
/// - Doesn't require RTTI
72+
/// - First-class support for serializing to JSON
73+
/// - Fully [TOML v0.5.0](https://github.com/toml-lang/toml/blob/master/versions/en/toml-v0.5.0.md)-compliant
74+
/// - Supports a number of 'unreleased' TOML features (optional; these can be disabled)
75+
///
76+
///////////////////////////////////////////////////////////////////////
77+
///
78+
/// \section mainpage-adding-lib Adding toml++ to your project
79+
/// Clone [the repository](https://github.com/marzer/tomlplusplus/) from GitHub. It's header-only so there's not much you have to do after that,
80+
/// other than some very minor (optional) configuration. See the [README](https://github.com/marzer/tomlplusplus/blob/master/README.md) for more info.
81+
///
82+
///////////////////////////////////////////////////////////////////////
83+
///
84+
/// \section mainpage-api-documentation API Documentation
85+
/// You're looking at it! Browse the docs using the links at the top of the page. You can search from anywhere by pressing the TAB key.
86+
///
87+
/// <em>toml++ is still pretty hot off the presses so there's going to be some omissions, typos and general sparseness throughout the docs.
88+
/// If you spot something or have a suggestion, please [let me know](https://github.com/marzer/tomlplusplus/issues)!</em>
89+
///
90+
///////////////////////////////////////////////////////////////////////
91+
///
92+
/// \section mainpage-example Basic examples
93+
///
94+
///////////////////////////////////
95+
///
96+
/// \subsection mainpage-example-parsing-files Parsing TOML files
97+
/// toml++ works whether you have exceptions enabled or not. For the most part the usage is the same,
98+
/// the main difference being how parsing errors are reported to the caller. When exceptions are enabled
99+
/// a toml::parse_error is thrown directly from the site of the error:
67100
/// \cpp
68101
/// #include <iostream>
102+
/// #include <fstream> //required for parse_file()
69103
/// #include <toml++/toml.h>
104+
/// using namespace std::string_view_literals;
70105
///
71106
/// int main()
72107
/// {
108+
/// toml::table tbl;
109+
/// try
110+
/// {
111+
/// tbl = toml::parse_file("configuration.toml");
112+
/// }
113+
/// catch (const toml::parse_error& err)
114+
/// {
115+
/// std::cerr
116+
/// << "Error parsing file '"sv << *err.source().path
117+
/// << "':\n"sv << err.description()
118+
/// << "\n ("sv << err.source().begin << ")"sv
119+
/// << std::endl;
120+
/// return 1;
121+
/// }
122+
///
123+
/// do_stuff_with_your_config(tbl);
124+
/// return 0;
125+
/// }
126+
///
127+
/// \ecpp
128+
///
129+
/// When exceptions are disabled parsing methods return a toml::parse_error and it is up to the caller
130+
/// to check if parsing has been successful by examining the return value:
131+
/// \cpp
132+
/// #include <iostream>
133+
/// #include <fstream> //required for parse_file()
134+
/// #include <toml++/toml.h>
135+
/// using namespace std::string_view_literals;
136+
///
137+
/// int main()
138+
/// {
139+
/// toml::parse_result tbl = toml::parse_file("configuration.toml");
140+
/// if (!tbl)
141+
/// {
142+
/// std::cerr
143+
/// << "Error parsing file '"sv << *tbl.error().source().path
144+
/// << "':\n"sv << tbl.error().description()
145+
/// << "\n ("sv << tbl.error().source().begin << ")"sv
146+
/// << std::endl;
147+
/// return 1;
148+
/// }
149+
///
150+
/// do_stuff_with_your_config(tbl); //toml::parse_result is convertible to toml::table
151+
/// return 0;
152+
/// }
153+
/// \ecpp
154+
/// \see toml::parse_file()
155+
///
156+
///////////////////////////////////
157+
///
158+
/// \subsection mainpage-example-parsing-strings Parsing TOML directly from strings
159+
///
160+
/// \cpp
161+
/// #include <iostream>
162+
/// #include <toml++/toml.h>
163+
/// using namespace std::string_view_literals;
164+
///
165+
/// int main()
166+
/// {
167+
/// // parse error handling omitted for brevity.
168+
/// static constexpr auto source = R"(
169+
/// [library]
170+
/// name = "toml++"
171+
/// version = "0.1.0"
172+
/// authors = ["Mark Gillard <[email protected]>"]
173+
///
174+
/// [dependencies]
175+
/// cpp = 17
176+
/// )"sv;
177+
/// auto tbl = toml::parse(source);
178+
/// std::cout << tbl << std::endl;
179+
/// return 0;
180+
/// }
181+
/// \ecpp
182+
///
183+
/// \out
184+
/// [dependencies]
185+
/// cpp = 17
186+
///
187+
/// [library]
188+
/// authors = ["Mark Gillard <[email protected]>"]
189+
/// name = "toml++"
190+
/// version = "0.1.0"
191+
/// \eout
192+
/// \see toml::parse()
193+
///
194+
///////////////////////////////////
195+
///
196+
/// \subsection mainpage-example-manipulations Traversing and manipulating data
197+
///
198+
/// \cpp
199+
/// #include <iostream>
200+
/// #include <toml++/toml.h>
201+
/// using namespace std::string_view_literals;
202+
///
203+
/// int main()
204+
/// {
205+
/// static constexpr auto source = R"(
206+
/// numbers = [ 1, 2, 3, "four", 5.0 ]
207+
/// vegetables = [ "tomato", "onion", "mushroom", "lettuce" ]
208+
/// minerals = [ "quartz", "iron", "copper", "diamond" ]
209+
///
210+
/// [animals]
211+
/// cats = [ "tiger", "lion", "puma" ]
212+
/// birds = [ "macaw", "pigeon", "canary" ]
213+
/// fish = [ "salmon", "trout", "carp" ]
214+
///
215+
/// )"sv;
216+
/// auto tbl = toml::parse(source);
217+
///
218+
/// auto numbers = tbl["numbers"];
219+
/// std::cout << "table has 'numbers': "sv << !!numbers << std::endl;
220+
/// if (numbers)
221+
/// {
222+
/// std::cout << "'numbers' is a: "sv << numbers.type() << std::endl;
223+
/// std::cout << "'numbers': "sv << numbers << std::endl;
224+
/// for (auto& node : *numbers.as_array())
225+
/// {
226+
/// node.visit([=](auto&& n) noexcept
227+
/// {
228+
/// if constexpr (toml::is_number<decltype(n)>)
229+
/// (*n)++;
230+
/// else if constexpr (toml::is_string<decltype(n)>)
231+
/// n = "five"sv;
232+
/// });
233+
/// }
234+
/// numbers.as_array()->push_back(7);
235+
/// numbers.as_array()->emplace_back<toml::array>(8, 9);
236+
/// std::cout << "'numbers': "sv << numbers << std::endl;
237+
/// }
238+
///
239+
/// std::cout << "'cats': "sv << tbl["animals"]["cats"] << std::endl;
240+
/// std::cout << "'dinosaurs': "sv << tbl["animals"]["dinosaurs"] << std::endl; //no dinosaurs :(
241+
///
242+
/// return 0;
243+
/// }
244+
/// \ecpp
245+
///
246+
/// \out
247+
/// table has 'numbers': true
248+
/// 'numbers' is an: array
249+
/// 'numbers': [1, 2, 3, "four", 5.0]
250+
/// 'numbers': [2, 3, 4, "five", 6.0, 7, [8, 9]]
251+
/// 'cats': ["tiger", "lion", "puma"]
252+
/// 'dinosaurs':
253+
/// \eout
254+
///
255+
/// \see toml::node, toml::node_view, toml::array, toml::table
256+
///
257+
///////////////////////////////////
258+
///
259+
/// \subsection mainpage-example-serialization Serializing as TOML and JSON
260+
/// \cpp
261+
/// #include <iostream>
262+
/// #include <toml++/toml.h>
263+
///
264+
/// int main()
265+
/// {
73266
/// auto tbl = toml::table{{
74267
/// { "lib", "toml++" },
75268
/// { "cpp", toml::array{ 17, 20, "and beyond" } },
@@ -82,21 +275,62 @@
82275
/// }}
83276
/// },
84277
/// }};
278+
///
279+
/// std::cout << "###### TOML ######"sv << std::endl;
280+
/// std::cout << tbl << std::endl << std::endl;
85281
///
86-
/// std::cout << tbl << std::endl;
282+
/// std::cout << "###### JSON ######"sv << std::endl;
283+
/// std::cout << toml::json_formatter{ tbl } << std::endl;
87284
/// return 0;
88285
/// }
89286
/// \ecpp
90-
///
287+
///
91288
/// \out
92-
/// cpp = [ 17, 20, "and beyond" ]
289+
/// ###### TOML ######
290+
/// cpp = [17, 20, "and beyond"]
93291
/// lib = "toml++"
94292
/// repo = "https://github.com/marzer/tomlplusplus/"
95-
/// toml = [ "0.5.0", "and beyond" ]
293+
/// toml = ["0.5.0", "and beyond"]
96294
///
97295
/// [author]
98296
/// github = "https://github.com/marzer"
99297
/// name = "Mark Gillard"
100298
/// twitter = "https://twitter.com/marzer8789"
299+
///
300+
/// ###### JSON ######
301+
/// {
302+
/// "author" : {
303+
/// "github" : "https://github.com/marzer",
304+
/// "name" : "Mark Gillard",
305+
/// "twitter" : "https://twitter.com/marzer8789"
306+
/// },
307+
/// "cpp" : [
308+
/// 17,
309+
/// 20,
310+
/// "and beyond"
311+
/// ],
312+
/// "lib" : "toml++",
313+
/// "repo" : "https://github.com/marzer/tomlplusplus/",
314+
/// "toml" : [
315+
/// "0.5.0",
316+
/// "and beyond"
317+
/// ]
318+
/// }
101319
/// \eout
320+
/// \see toml::default_formatter, toml::json_formatter
321+
///
322+
///////////////////////////////////////////////////////////////////////
323+
///
324+
/// \section mainpage-contributing Contributing
325+
/// See the [Contributing](https://github.com/marzer/tomlplusplus/blob/master/README.md#contributing) section of the repository README.
326+
///
327+
///////////////////////////////////////////////////////////////////////
328+
///
329+
/// \section mainpage-license License
330+
///
331+
/// toml++ is licensed under the terms of the MIT license - see [LICENSE](https://github.com/marzer/tomlplusplus/blob/master/LICENSE).
332+
///
333+
/// UTF-8 decoding is performed using a state machine based on Bjoern Hoehrmann's 'Flexible and Economical UTF - 8 Decoder', which is also subject
334+
/// to the terms of the MIT license - see [LICENSE-utf8-decoder](https://github.com/marzer/tomlplusplus/blob/master/LICENSE-utf8-decoder).
335+
///
102336
///

0 commit comments

Comments
 (0)