summaryrefslogtreecommitdiff
path: root/tomlplusplus/examples
diff options
context:
space:
mode:
Diffstat (limited to 'tomlplusplus/examples')
-rw-r--r--tomlplusplus/examples/CMakeLists.txt27
-rw-r--r--tomlplusplus/examples/benchmark_data.toml578
-rw-r--r--tomlplusplus/examples/error_printer.cpp210
-rw-r--r--tomlplusplus/examples/error_printer.vcxproj61
-rw-r--r--tomlplusplus/examples/example.toml102
-rw-r--r--tomlplusplus/examples/examples.hpp62
-rw-r--r--tomlplusplus/examples/merge_base.toml5
-rw-r--r--tomlplusplus/examples/merge_overrides.toml8
-rw-r--r--tomlplusplus/examples/meson.build31
-rw-r--r--tomlplusplus/examples/parse_benchmark.cpp81
-rw-r--r--tomlplusplus/examples/parse_benchmark.vcxproj62
-rw-r--r--tomlplusplus/examples/simple_parser.cpp36
-rw-r--r--tomlplusplus/examples/simple_parser.vcxproj62
-rw-r--r--tomlplusplus/examples/toml_generator.cpp322
-rw-r--r--tomlplusplus/examples/toml_generator.vcxproj62
-rw-r--r--tomlplusplus/examples/toml_merger.cpp101
-rw-r--r--tomlplusplus/examples/toml_merger.vcxproj63
-rw-r--r--tomlplusplus/examples/toml_to_json_transcoder.cpp36
-rw-r--r--tomlplusplus/examples/toml_to_json_transcoder.vcxproj62
19 files changed, 1971 insertions, 0 deletions
diff --git a/tomlplusplus/examples/CMakeLists.txt b/tomlplusplus/examples/CMakeLists.txt
new file mode 100644
index 0000000000..5cc5fe25d2
--- /dev/null
+++ b/tomlplusplus/examples/CMakeLists.txt
@@ -0,0 +1,27 @@
+cmake_minimum_required(VERSION 3.14)
+
+project(Examples LANGUAGES CXX)
+
+include(../cmake/project-is-top-level.cmake)
+
+if(PROJECT_IS_TOP_LEVEL)
+ find_package(tomlplusplus REQUIRED)
+endif()
+
+add_custom_target(run_examples COMMENT "Running all examples")
+
+function(add_example name)
+ cmake_parse_arguments(PARSE_ARGV 1 "" "" "" ARGS)
+ add_executable("${name}" "${name}.cpp")
+ target_link_libraries("${name}" PRIVATE tomlplusplus::tomlplusplus)
+ target_compile_features("${name}" PRIVATE cxx_std_17)
+ add_custom_target("run_${name}" COMMAND "${name}" ${_ARGS} VERBATIM)
+ add_dependencies(run_examples "run_${name}")
+endfunction()
+
+add_example(error_printer)
+add_example(parse_benchmark)
+add_example(simple_parser)
+add_example(toml_generator)
+add_example(toml_merger)
+add_example(toml_to_json_transcoder ARGS "${PROJECT_SOURCE_DIR}/example.toml")
diff --git a/tomlplusplus/examples/benchmark_data.toml b/tomlplusplus/examples/benchmark_data.toml
new file mode 100644
index 0000000000..78a653bb85
--- /dev/null
+++ b/tomlplusplus/examples/benchmark_data.toml
@@ -0,0 +1,578 @@
+boiling-morning = 947
+capable-adhesive = 09:20:44
+cure = 0.4747 # broken
+deserted = 0.3939
+finger-surprise = true
+flimsy-hook = { wistful-vengeful-complex = [ 2012-06-01T14:49:11+09:41 ] } # experience
+naughty = 1928-08-08T22:22:07+06:02
+remarkable-umbrella-flagrant = 1910-09-26
+silky-ski-threatening = 'bore regret' # reject
+soap-decisive = ''
+want = 0.4848
+
+[[babies-lewd-relation.playground-snow-rotten]]
+addition-cobweb = 0.8157
+bore = 'acceptable stale adhesive stale curtain deserted'
+close-hard-to-find = {} # finicky righteous
+contain-train = { ball-license-babies = 22:44:01, string-cross = 0.4102, used-rest = 2014-09-05T17:02:28 }
+flat-cheerful = {}
+license-gleaming-laughable = 2009-06-03
+rich-title-fuel = 'close tacky stale bake'
+
+ [babies-lewd-relation.playground-snow-rotten.aromatic-overjoyed]
+ whip-addition = {} # insidious
+
+ [babies-lewd-relation.playground-snow-rotten.morning-adorable-gleaming] # deeply spicy
+ legal-imperfect-worried = 06:23:39
+ modern = 1968-01-21
+ skip-sprout-zealous = ''
+ step-history = {}
+
+[[babies-lewd-relation.playground-snow-rotten]]
+draconian-addition-threatening = 'behave experience impossible' # high-pitched unbecoming
+stingy-equable-clean = 1975-03-17 # protective
+versed-bake = 505
+
+[[babies-lewd-relation.playground-snow-rotten]]
+night = 0.778
+prefer-torpid-ski = [ 0.6483, false, 1982-01-23T16:10:13-01:55 ]
+soap = { fix = 2019-07-24T07:38:55+01:19, umbrella = 1947-02-13T18:02:46 }
+soap-blind = 1964-05-23 # run prefer
+used-ancient-delightful = false
+worried-string = [ [ 'borrow unbecoming geese' ] ]
+
+# title tacky dull draconian lewd dreary
+# deeply anxious surprise torpid unite relation kindhearted
+# skip dull room train experience
+# borrow satisfy scintillating neck impossible aromatic high-pitched
+# week respect ghost capable
+# satisfy deserted capable rabbit string threatening
+
+ [babies-lewd-relation.playground-snow-rotten.protective-kindhearted-train] # best
+ hard-to-find = 'terrible'
+ picture = 'ball history'
+ step-decisive = 02:54:51
+
+ [babies-lewd-relation.playground-snow-rotten.protective-kindhearted-train.crowded-protective] # leather unbecoming
+ blind = 1905-03-22
+ clean-wilderness-leather = 09:45:08 # scatter
+ impossible-ski = 536 # sprout
+ license = [ 1952-02-22T17:07:05.000005978+10:25, 1996-07-04T14:01:50 ] # stale stingy
+ surprise-fuel = { borrow-kindhearted = 1986-03-23T20:44:26+07:51 } # playground
+
+ [babies-lewd-relation.playground-snow-rotten.protective-kindhearted-train.playground-bore] # hook flagrant
+ addition-scatter-tacky = 02:17:38
+ close = { crown-respect-prefer = 03:27:27 }
+ incandescent = 10:04:01
+ march-dreary-room = true
+ mark-influence = true
+ picture-squirrel-surprise = 901
+ scene-rest-capable = [ 'torpid light attempt', 12:09:26.000008459 ] # addition
+ unbecoming-decisive = { bat = [ 1913-12-15T13:13:49, '' ], march-experience-tank = 1911-12-04T18:29:34-04:06, relation-remarkable = false }
+ whip-actually = [ [], [ 1996-05-28 ] ] # umbrella imperfect
+
+# stale voyage run popcorn threatening bore
+# fabulous respect chubby ancient wistful creature
+# surprise prefer dull curious whip
+# used blue-eyed furtive torpid selfish chubby nondescript
+# curious complex geese jail
+
+ [[babies-lewd-relation.playground-snow-rotten.protective-kindhearted-train.playground-bore.influence-scintillating-vengeful]]
+ babies-surprise-stingy = { surprise-contain-weary = 14:56:22 }
+ borrow = 1996-06-04 # ancient
+ fuel-miss-rich = [ 0.1081, 0.8454 ]
+ grandfather = false
+ haircut-versed-innocent = { boiling-innocent-blue-eyed = { blood-capable = 853, overjoyed-kindhearted = 0.2161 }, regret-ignore = 1905-02-06 }
+ step-insidious-adhesive = [ 1950-01-06, {}, false ]
+ unbiased = 784 # unite title
+ uptight-itch-curtain = false
+
+ [[babies-lewd-relation.playground-snow-rotten.protective-kindhearted-train.playground-bore.influence-scintillating-vengeful]] # title relation
+ deadpan = 1958-06-22T18:31:51+10:16
+ fix = 0.3198 # heavy sulky
+ page-stingy-selfish = 1930-06-19T02:38:48.000016194
+ picture-lackadaisical = false # ghost
+ tank-contain = 'memory consist helpless'
+ versed-leather-ghost = 'influence wistful flat'
+ wretched-march = 'place enthusiastic decisive'
+
+ [babies-lewd-relation.playground-snow-rotten.protective-kindhearted-train.vengeful-worried]
+ capable-bake-room = 1988-10-22 # actually unite
+ cycle = false
+ high-pitched-vengeful = 0.0822
+ tank-license = 1953-02-12T14:43:36.00003003-00:35
+ threatening = 03:43:23
+
+# vessel remarkable pumped step draconian scary
+# pear selfish birds regret license stingy playground
+# pear babies geese rice ignore
+# run reject rapid reject
+
+ [babies-lewd-relation.playground-snow-rotten.protective-kindhearted-train.vengeful-worried.ghost-heavy] # respect
+ advise-bore = true
+ broken-lewd = true
+ scatter = 6 # neck
+ scintillating-regret-unadvised = 1936-07-25T17:22:32-05:14
+ versed-miss = 0.9028
+ weary = []
+
+ [babies-lewd-relation.playground-snow-rotten.protective-kindhearted-train.vengeful-worried.pumped-wistful]
+ contain-modern = 1923-09-23T01:22:09-02:20
+ curious-silky-borrow = 1959-11-06T04:37:54-02:58 # rotten
+ hilarious = 1903-12-02
+ insidious-tacky = 'harm spiritual laughable cycle influence messy enthusiastic'
+ wall-sprout-scary = 10:44:31
+ week-dull = {} # leather enthusiastic
+
+ [babies-lewd-relation.playground-snow-rotten.protective-kindhearted-train.vengeful-worried.unadvised-gold-unadvised]
+ attempt = 1957-09-11
+ flagrant-miss-tent = 0.8814
+ legal-versed-sprout = false
+
+ [[babies-lewd-relation.playground-snow-rotten.protective-kindhearted-train.vengeful-worried.scene-naughty-spare]]
+ deserted-hilarious = {}
+ scatter-attempt = 'blind pear'
+
+ [[babies-lewd-relation.playground-snow-rotten.protective-kindhearted-train.blue-eyed]] # blue-eyed run
+ borrow-run-mark = 0.5925
+ complex-profuse = 1907-02-26T23:54:24.000028223+10:35
+ crown-ticket = 'babies helpless'
+ dull = 1942-11-26
+ furtive = 816
+ respect = 20:07:11
+ string-cheerful-satisfy = 10:15:06
+ unbecoming-furtive-unite = 2008-09-02T16:34:04+08:40
+
+ [[babies-lewd-relation.playground-snow-rotten.protective-kindhearted-train.blue-eyed.naughty-laughable-actually]]
+ legal-attempt-light = 1934-09-24T20:24:29-10:18
+ remarkable = 2020-10-02T19:53:38
+ three-cure-innocent = [ 0.2179 ]
+ versed-attempt = 1917-11-11
+ week-draconian = 797
+
+ [[babies-lewd-relation.playground-snow-rotten.protective-kindhearted-train.blue-eyed.naughty-laughable-actually]] # skip
+ fabulous-ignore = 2005-08-06
+ messy = 242 # gusty worried
+
+ [[babies-lewd-relation.playground-snow-rotten.protective-kindhearted-train.blue-eyed]]
+ fabulous = 0.8882
+ fix = 1928-07-04T15:46:25-06:46
+ rabbit-gold = 0.8035
+ royal = 1989-09-26T07:06:21-08:43 # complex borrow
+ terrible-capable-crowded = {}
+ unbecoming = 201
+ view = 12:19:31 # ignore
+ wilderness-tent-week = [ 384 ]
+
+ [babies-lewd-relation.playground-snow-rotten.whip-enthusiastic-ignore]
+ afraid = 2010-08-09
+ ball = 17:51:13 # vengeful
+ blind-heavy = 'cheerful profuse innocent dreary' # legal hard-to-find
+ deserted-itch = 1984-03-02
+ skip-protective = 22:27:14
+ spare-view-hook = { flimsy-partner-fuel = 727, memory-blue-eyed = 0.9457 }
+
+ [[babies-lewd-relation.playground-snow-rotten.whip-enthusiastic-ignore.skip-bake-incandescent]]
+
+ [babies-lewd-relation.playground-snow-rotten.whip-enthusiastic-ignore.skip-bake-incandescent.influence-bat-actually]
+ broken-surprise = 21:24:24.000002983
+ leather-taboo-dull = { deeply = [ 813, 07:48:43.000014695 ], run-bake = 'march used scatter attempt close chubby innocent', tacky-party = 2005-02-06 } # cross
+ productive = { page = 361, three-tank-wistful = [ 2016-07-20, 13:18:08, 'light curtain morning rabbit harm sisters high-pitched' ] }
+ terrible-partner-room = 1915-06-07
+ train = 0.4414
+
+# innocent string contain regret crime decisive wall
+# spiritual naughty tacky stale attempt
+# deadpan cure experience royal ancient cure voyage
+# remarkable whip ski best haircut
+
+ [babies-lewd-relation.playground-snow-rotten.whip-enthusiastic-ignore.skip-bake-incandescent.rice-skip-used]
+ bake-pear-train = 813 # vengeful
+ clean-ancient = 2012-11-13
+ complex = { naughty-deadpan-actually = 06:52:59, room-boiling = 0.1027 }
+ haircut = true # tacky prefer
+ rejoice-uptight = 0.6769
+ spicy = true
+ surprise = false # deadpan worried
+ threatening = 1978-02-04
+ title-acceptable = 1956-02-22
+
+ [[babies-lewd-relation.playground-snow-rotten.whip-enthusiastic-ignore.skip-bake-incandescent.selfish]] # license incandescent
+ acceptable-decisive = 'skip flat gold influence morning unbiased'
+ deadpan = 0.7201 # finicky
+ dull-borrow = 1900-12-08 # dreary capable
+ hilarious-vengeful = {} # furtive
+ jail-consist-scatter = 0.1787
+ scene-vessel-complex = 1971-02-15
+ taboo-dull = 0.1922
+ taboo-ignore = 2019-04-22 # deadpan
+ unadvised-scene = 03:16:52
+
+ [[babies-lewd-relation.playground-snow-rotten.whip-enthusiastic-ignore.skip-bake-incandescent]]
+ contain = false
+ legal-hilarious = []
+ rejoice = [ 1979-08-21T05:58:09-06:39, 'creature memory' ]
+ wall-flagrant-self = 0.4976
+
+ [[babies-lewd-relation.playground-snow-rotten.wall]] # protective
+ capable = [] # wilderness snow
+ clean = 1963-02-17
+ complex-umbrella = { familiar-innocent-consist = 175, stale = 07:03:20.00002881 }
+ creature-gleaming-sisters = 1984-05-19 # gleaming
+ crowded-squirrel = 1974-10-07
+ enthusiastic-three-tent = { capable-crowded = 1931-03-05T09:28:53-07:42, flat-broken-clean = {} }
+ light-snow = false # silky
+ wilderness-light-curious = 989 # actually
+
+ [babies-lewd-relation.playground-snow-rotten.wall.threatening]
+ chubby-overjoyed = 0.7252 # cheerful
+ cream-addition = 0.8832
+ familiar-high-pitched = 2013-11-10
+ laughable-geese-borrow = {}
+ overjoyed-bake = 1919-07-25
+ respect-umbrella = 1947-09-18 # charming
+ scene-rapid = false
+ surprise-delightful-stingy = { creature-pause = 0.9945, room-advise = '', tent-snow = '' } # rabbit
+
+ [[babies-lewd-relation.playground-snow-rotten.wall]]
+ crown-unbiased = 06:10:11 # jail
+ impossible-flimsy = 1992-09-13T01:39:28.000005689-05:33
+ rejoice = [ false ]
+ ski-ball-run = 'finicky haircut vessel spicy'
+ tacky = 9 # ignore
+ vengeful-rabbit = true # lackadaisical fix
+
+# jail excuse enthusiastic cream complex
+# train satisfy fix broken
+# threatening boiling attempt train delightful cheerful vengeful
+# rich actually fabulous contain deadpan harm curious
+# fabulous scene furtive acceptable blood
+# meaty used curious mark surprise curtain hard-to-find
+
+ [babies-lewd-relation.playground-snow-rotten.wall.terrible]
+ aromatic = 1937-12-11T00:23:12 # addition whip
+ glorious-wretched = { tank-adorable-gold = false, wilderness-cure-history = [ 1957-11-25T20:10:27.000016213+04:26, 2008-02-17, 20:40:09 ] }
+ squirrel-flagrant-boiling = { skip-room = { nondescript-morning-excuse = 1904-05-01T16:47:38+10:26 } }
+ surprise = 0.3398
+ worried = 'wretched experience ancient'
+
+# week hilarious miss sprout
+
+ [babies-lewd-relation.playground-snow-rotten.wall.terrible.anxious] # crown tacky
+ fabulous-impossible = false # spare
+ fuel = 1908-09-09 # stale charming
+ license-ticket = [] # regret rejoice
+ sprout-mark-selfish = { page = 23:36:46.0000114, weary-deserted-history = [ true ] }
+ voyage = { meaty-helpless = 1980-04-20 }
+
+# bore babies influence overjoyed advise light
+# righteous remarkable leather stingy partner actually advise
+# scary familiar deadpan gleaming adhesive broken experience
+# mark unbiased popcorn squirrel close capable
+# scintillating ski productive unbecoming haircut
+# tank attempt scene rabbit high-pitched sprout
+# gusty attempt flimsy ski pear terrible rice
+
+ [babies-lewd-relation.playground-snow-rotten.wall.terrible.boiling] # flimsy glorious
+ charming-royal = 04:14:31.000005876
+ curtain = 2005-08-17T06:45:00 # equable
+ draconian-clean-enthusiastic = 'history'
+ fix = 19:53:23
+ influence-week-reject = 581 # spiritual bore
+ self-protective = 2004-01-19T01:00:26.000016471+00:16
+ step-overjoyed-history = [ 'curious satisfy', [ 'overjoyed bat advise grandfather', 0.5762 ], 1947-06-28T09:03:40-08:39 ]
+
+ [babies-lewd-relation.playground-snow-rotten.wall.terrible.laughable-crime] # babies
+ umbrella = 1938-06-10
+
+# furtive actually cross creature
+# rest ghost mark selfish deadpan wistful torpid
+
+ [[babies-lewd-relation.playground-snow-rotten.wall.terrible.versed-overjoyed]] # hilarious
+ blind-familiar = 73 # gold respect
+ clean-train = { borrow-flagrant = 0.6438, unbecoming-fabulous-cheerful = false } # week
+ flimsy-pumped-umbrella = { string-boiling = { insidious-sisters = 10:33:25 }, weary = { behave-rejoice-threatening = 0.9151, protective-grandfather = 'haircut', view-regret-partner = false } } # unadvised finger
+ modern = 0.1885
+ place-cross = [ {} ]
+ tank = false
+ terrible-enthusiastic = 'hook' # train
+ threatening-best = 1908-09-20 # ticket
+ unbecoming-high-pitched = 09:47:03 # selfish productive
+
+ [[babies-lewd-relation.playground-snow-rotten.wall.terrible.versed-overjoyed]]
+ anxious = [] # equable
+ clean-satisfy = [ 0.8894, 153 ]
+ scene = 17:37:43 # clean ancient
+
+# voyage wall deserted furtive rest aromatic
+# cross flat cure productive cheerful
+
+ [[babies-lewd-relation.playground-snow-rotten.wall.terrible.versed-overjoyed]] # charming laughable
+ ball-deserted = 'voyage' # crown
+ deadpan-prefer-deeply = 104
+ fabulous-influence-wall = 0.0613
+ ignore = 1982-07-11
+ modern = { helpless-imperfect-leather = [ 'unbiased familiar place', 06:33:07.00002173, 0.5918 ], worried-crowded = false } # helpless want
+ party-complex-laughable = 11:39:52 # rice light
+ rich-three = 1929-11-07T03:53:23
+ royal-behave-babies = { fabulous-mark = [ 659, true ], unbecoming-messy = [] } # rich broken
+ spare = [ 1935-09-28T14:49:51-02:02 ]
+
+ [[babies-lewd-relation.playground-snow-rotten.wall]] # threatening
+ contain = [ 1918-09-06 ]
+ haircut-selfish-gusty = 976 # spicy stale
+ rotten = [ true, 'afraid overjoyed kindhearted threatening jail deadpan cure' ]
+ scene-charming-delightful = 'rice crown room'
+ scintillating-umbrella-crowded = true
+ selfish = 1986-11-28
+ stale = 0.3828
+ title-equable-partner = 508 # zealous
+
+[[terrible]]
+boiling-anxious-heavy = 1975-02-23
+
+ [terrible.capable-tent]
+ behave-ski-geese = true
+ borrow = true
+ capable-blue-eyed = 0.96
+ delightful-fabulous = 14:05:34
+ glorious = [ # finger spicy
+ { best = 0.3935, cycle-acceptable = 05:55:20, spiritual-zealous-high-pitched = 'borrow actually taboo unadvised deadpan' },
+ false
+ ]
+ hilarious = [ 0.0929 ]
+ spiritual-tank-sprout = 1969-10-20
+ week = false
+ wretched-step = { close-reject-excuse = 'taboo popcorn party', finger-soap-best = 0.5234 }
+
+ [terrible.capable-tent.contain-spiritual-squirrel]
+ delightful-torpid-three = 'rejoice'
+ haircut-regret-curious = 0.7427
+ morning-babies = 'hilarious voyage royal complex crown complex'
+ rest-impossible-borrow = '' # deserted behave
+ scatter-rest-impossible = { rich-close-actually = 878, vengeful = 0.2007 } # tank run
+ tacky-neck-cheerful = [ {}, [] ]
+
+ [terrible.capable-tent.week-week-zealous]
+ bat-zealous = 'morning lewd consist familiar morning crowded laughable' # uptight ski
+ delightful-tank = 1948-04-17 # charming
+ excuse = 1939-09-20T05:39:20.000019588+07:59
+ gold = 1901-05-16T23:53:21-05:25
+ royal = '' # remarkable
+ self = { train-birds-stingy = 'insidious scene gold', vessel = 0.5759 }
+ soap = { dull-history = false, scary = false }
+ taboo-ancient-itch = { gusty-snow-pear = { protective-scatter-high-pitched = 1996-11-03 }, rejoice-ignore-finger = 1918-11-22T19:37:38, squirrel-high-pitched-nondescript = 1995-07-17T04:54:13 }
+ umbrella-partner = []
+
+ [terrible.capable-tent.wilderness-aromatic]
+ attempt-night = 23:28:50 # borrow
+ cross-spare-hook = [ 1919-06-28T19:24:17-04:44, 08:23:11 ]
+ pear-helpless-profuse = true
+ productive-whip = 349
+ rapid-scary = 23:34:33
+ rotten-wistful = 1944-11-27
+ threatening = false # chubby
+ view-afraid = false
+
+# neck draconian innocent innocent unbecoming advise
+# voyage aromatic train gold broken harm memory
+# fuel broken string unbecoming
+# party party stale ski advise lewd
+
+ [terrible.capable-tent.wilderness-aromatic.tank]
+ cheerful-zealous-experience = 41
+ memory = 890 # deadpan
+ naughty = 1991-07-27T16:21:58+02:12
+ sisters = true # royal
+ tent-threatening-threatening = 0.1835
+
+# attempt rabbit boiling train laughable wistful
+# soap excuse spare neck babies unbiased fix
+# legal unbecoming flagrant rest excuse uptight royal
+
+ [[terrible.capable-tent.wilderness-aromatic.tank.terrible]]
+ birds = [ true, 12:01:59, 1993-12-06 ]
+ scintillating-vengeful = 'snow party train unbiased innocent'
+ sulky = 'popcorn'
+
+ [[terrible.capable-tent.wilderness-aromatic.tank.terrible]]
+ wistful-innocent-morning = 482
+
+ [[terrible.capable-tent.wilderness-aromatic.tank.terrible]]
+ adorable = [ false, [ 1986-08-22T06:58:04, 211 ] ]
+ crowded = [ 06:00:22, 15:39:55 ]
+ dreary-decisive = 1937-08-23
+ familiar-taboo-unite = false
+ glorious = true # room messy
+ license-anxious-prefer = ''
+ pumped = 2010-02-06T18:30:43-07:27
+ royal = 1949-03-01T15:27:36
+
+ [[terrible.capable-tent.wilderness-aromatic.birds]]
+ hook-dull-familiar = 2020-05-09T10:12:18-00:21
+ imperfect = false
+ pear = 'vengeful worried self close worried'
+
+ [[terrible.capable-tent.wilderness-aromatic.birds]]
+ bore-unite-flimsy = { finicky-legal-view = [ 749 ] }
+ grandfather-unbiased = 'modern delightful actually cream' # versed
+ haircut-soap = 2004-05-01T21:12:27+01:34
+ innocent-crime-unbiased = 'three flimsy'
+ lewd-adorable = 05:25:31 # best fuel
+ neck = 17:07:42
+ rabbit-versed = 11:23:17.000021208
+ step-overjoyed-anxious = 0.2862
+ weary-creature-itch = [ 2012-05-13T05:12:55+10:38, 1983-01-06T06:23:03-04:47 ] # skip ticket
+
+ [[terrible.capable-tent.wilderness-aromatic.birds]]
+ hook-rest-impossible = [ 21:02:47.000007906, 0.9952, [ 1977-05-22, true, true ] ]
+ sisters-rotten = 276
+
+ [terrible.capable-tent.wilderness-aromatic.birds.naughty-blind]
+ bake-scatter-cross = [
+ 234,
+ { attempt-selfish-ghost = 08:43:45, draconian-ski-scintillating = 1911-03-24T12:01:06-01:20, dreary = 266 },
+ 'innocent broken equable adhesive spiritual title respect'
+ ] # hard-to-find protective
+ ticket-enthusiastic-delightful = [ 428, 12:49:26, [ 07:10:40, 'neck unadvised finicky stale rest', true ] ]
+
+ [terrible.capable-tent.wilderness-aromatic.birds.popcorn-cross-unbecoming]
+ capable-best = [ { fabulous = 0.0328 }, 1959-07-11T18:30:11-10:19, [ false, 1943-02-01T14:46:20+04:32 ] ]
+ contain = { harm-babies-actually = 1927-05-26, lackadaisical-cobweb-ticket = { license-stale = true }, zealous = 14:34:49 }
+ dreary-rejoice = false
+ ignore-cobweb = true
+ jail = false
+ legal = {}
+
+ [terrible.capable-tent.wilderness-aromatic.birds.rotten]
+ innocent = 2012-07-13
+ stingy = 12:22:46
+ wilderness = true
+
+ [[terrible.capable-tent.taboo-snow-fix]]
+ consist = 0.5019
+ deadpan-title-equable = []
+ enthusiastic = 'jail step deserted' # neck
+ high-pitched-ski-jail = {}
+ lackadaisical-page = 2011-04-21
+ leather-grandfather-lackadaisical = 'kindhearted kindhearted rich babies' # umbrella
+ relation-high-pitched = 1995-11-05 # blue-eyed cream
+ self-deeply-crown = 0.6038 # pumped relation
+ spare-behave-royal = 1955-01-15T04:19:40.000024836-03:27
+
+ [terrible.history-wistful-insidious]
+ deadpan-run = 1961-12-04T21:19:22
+ impossible-itch-hilarious = []
+ wall-silky-zealous = false
+
+ [terrible.history-wistful-insidious.broken-bore]
+ decisive-spicy = 01:43:10
+ finger-deeply = 03:52:20
+ jail = [ 'week title curtain week snow' ]
+ jail-borrow = true # flimsy
+ kindhearted-tent-harm = 1979-06-03
+ playground-unbecoming = 0.3341
+ used-unbecoming-cobweb = 0.7474
+
+ [terrible.history-wistful-insidious.broken-bore.draconian.silky] # afraid unbiased
+ bat-vessel-enthusiastic = 1988-05-20T20:51:44+00:23
+ decisive-close-rest = 1979-07-27T21:30:02-07:46
+ messy = 0.2638 # excuse
+ stingy-self-rejoice = 0.0179
+ tacky-mark = 'wilderness furtive incandescent delightful close rotten' # best
+ vessel = 2006-06-28T20:54:53 # umbrella
+
+ [[terrible.history-wistful-insidious.cobweb-finicky]]
+ attempt-selfish-skip = []
+ ball-ball = 0.1378 # aromatic best
+ blind-curtain = 06:26:13
+ fuel-fix-geese = 1918-06-21T14:07:38
+ high-pitched-three = 16:58:45
+ innocent-rabbit = 'train'
+ miss = 'glorious chubby cobweb skip dreary scene ball'
+ morning = 'unbiased ticket deeply anxious skip terrible dreary'
+ playground = 'sisters run' # scene cycle
+
+ [[terrible.history-wistful-insidious.cobweb-finicky]]
+ fabulous = [ 'flimsy spare tent rejoice curtain mark', true ]
+ rabbit = {}
+ ticket = false
+
+# unadvised sulky acceptable righteous broken profuse terrible
+# ancient crown gleaming wistful ball rest
+# picture deadpan mark flimsy scatter decisive
+# close memory skip bat tent haircut
+# run attempt morning vengeful delightful legal itch
+
+ [terrible.productive]
+ itch = ''
+
+[[terrible]]
+babies-sisters = 62
+boiling = { deserted = 'adorable', lackadaisical-wilderness = 671 }
+decisive-itch = 1943-07-24 # cross rest
+ignore-best = [ 1916-02-18T15:56:45+02:04 ]
+overjoyed = 17:49:57
+place-familiar = true
+sisters = []
+used-rotten = 1985-08-10T07:39:42+05:17
+
+ [[terrible.regret-sisters-terrible]]
+
+ [[terrible.regret-sisters-terrible]]
+ bake = 0.8399
+ cross = 427
+ leather = [ 02:56:44.000030194, 1974-09-24 ]
+ nondescript-attempt-bore = 1900-07-03T04:56:46.000004029+07:22
+ rejoice = true
+
+# geese snow relation worried
+
+ [terrible.regret-sisters-terrible.ancient]
+ boiling-messy-stingy = { fabulous-wretched-mark = [], wall-familiar-furtive = 2003-09-16 }
+ cobweb-fix = 1988-05-07T07:01:15-10:34
+ excuse-gleaming = { familiar = [ true, 1929-01-01T13:47:11+02:44, 04:04:47.00000846 ] } # heavy cheerful
+ fix-acceptable-string = 15:39:49.000006614 # actually imperfect
+ hard-to-find = false
+ imperfect = 1960-11-24T22:00:37 # overjoyed
+ rabbit-terrible-innocent = [] # threatening
+ rabbit-train-ski = 0.6229 # profuse
+ wilderness-advise = 1982-08-20
+
+ [[terrible.regret-sisters-terrible.ancient.umbrella-worried]]
+ afraid = true # dreary
+
+ [terrible.regret-sisters-terrible.ancient.umbrella-worried.uptight-sisters-leather]
+ bore-tank-afraid = true # wretched curtain
+
+ [[terrible.regret-sisters-terrible.terrible-scene-surprise]]
+ prefer-legal = 428
+ relation-license-partner = [ true ] # playground
+
+ [[terrible.regret-sisters-terrible]]
+ glorious-adorable = 206 # curtain
+ grandfather = 76
+ ignore-cycle = 1956-07-22T01:39:24+03:39
+ messy = {} # draconian
+
+ [[terrible.regret-sisters-terrible.memory]] # curious memory
+ kindhearted-anxious-rotten = true
+ march-cheerful-view = { best-rice-want = 1978-08-26T22:05:21-00:49, spiritual = 1951-01-22T09:45:33-07:27, vessel-insidious = true } # gold
+ mark-sulky = 0.0597
+ pear = 1986-10-18T13:04:43-01:01 # three itch
+ remarkable-wistful = 1901-10-01
+ scatter-furtive-versed = 01:16:52
+ tank-reject = [ 12:09:18, {} ] # wall finger
+
+ [[terrible.regret-sisters-terrible.memory]]
+ babies-memory = [ { decisive = 15:35:50.000020612, stale-spicy = 0.1702 } ] # adhesive
+ blue-eyed-aromatic = 'curious birds terrible crowded'
+ close-cobweb-satisfy = [ {} ]
+ license = 0.9682 # lewd
+ reject-spiritual-taboo = ''
+ sulky-afraid = false
+ train-ghost-week = [ [ 0.6958, true ], 1942-02-15 ]
+
+ [[terrible.regret-sisters-terrible.memory]]
+ imperfect = [ 0.0689 ] # harm
+ three-string-tacky = 0.2109
diff --git a/tomlplusplus/examples/error_printer.cpp b/tomlplusplus/examples/error_printer.cpp
new file mode 100644
index 0000000000..c73ea75881
--- /dev/null
+++ b/tomlplusplus/examples/error_printer.cpp
@@ -0,0 +1,210 @@
+// 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
+
+// This example shows the error messages the library produces by forcing a set of specific parsing
+// failures and printing their results.
+
+#include "examples.hpp"
+#include <toml++/toml.hpp>
+#include <cctype> // For iscntrl.
+#include <iomanip> // For setfill, hex, etc.
+#include <optional>
+
+using namespace std::string_view_literals;
+
+namespace
+{
+ inline constexpr auto invalid_parses = std::array{
+ "########## comments and whitespace"sv,
+ "# bar\rkek"sv,
+ "# bar\bkek"sv,
+ "# DEL character: '\x7f'"sv,
+ "# \xf1\x63"sv,
+ "# val1 = 1\fval2 = 2"sv,
+ "foo = 1\n\u2000\nbar = 2"sv,
+
+ "########## inline tables"sv,
+ "val = {,}"sv,
+ "val = {a='b',}"sv, // allowed when TOML_ENABLE_UNRELEASED_FEATURES == 1
+ "val = {a='b',,}"sv,
+ "val = {a='b',"sv,
+ "val = {a='b',\n c='d'}"sv, // allowed when TOML_ENABLE_UNRELEASED_FEATURES == 1
+ "val = {?='b'}"sv,
+ "foo = {} \n [foo.bar]"sv,
+
+ "########## tables"sv,
+ "[]"sv,
+ "[foo"sv,
+ "[foo] ?"sv,
+ "[foo] [bar]"sv,
+ "[foo]\n[foo]"sv,
+ "? = 'foo' ?"sv,
+ "[ [foo] ]"sv,
+
+ "########## arrays"sv,
+ "val = [,]"sv,
+ "val = ['a',,]"sv,
+ "val = ['a',"sv,
+
+ "########## key-value pairs"sv,
+ "val = 'foo' ?"sv,
+ "val = "sv,
+ "val "sv,
+ "val ?"sv,
+ "val = ]"sv,
+ "[foo]\nbar = 'kek'\nbar = 'kek2'"sv,
+ "[foo]\nbar = 'kek'\nbar = 7"sv,
+ "[foo.bar]\n[foo]\nbar = 'kek'"sv,
+ "[foo]\nbar = 'kek'\nbar.kek = 7"sv,
+ "[foo]\nbar.? = 'kek'"sv,
+ R"('''val''' = 1)"sv,
+ R"(a."""val""" = 1)"sv,
+ "1= 0x6cA#+\xf1"sv,
+ R"(😂 = 3)"sv, // allowed when TOML_ENABLE_UNRELEASED_FEATURES == 1
+
+ "########## values"sv,
+ "val = _"sv,
+ "val = G"sv,
+ "PATHOLOGICALLY_NESTED"sv, // generated inline
+
+ "########## strings"sv,
+ "val = \" \r \""sv,
+ R"(val = ")"sv,
+ R"(val = "\g")"sv,
+ R"(val = "\x20")"sv, // allowed when TOML_ENABLE_UNRELEASED_FEATURES == 1
+ R"(val = "\uFFF")"sv,
+ R"(val = "\uFFFG")"sv,
+ R"(val = "\UFFFFFFF")"sv,
+ R"(val = "\UFFFFFGF")"sv,
+ R"(val = "\uD801")"sv,
+ R"(val = "\U00110000")"sv,
+ R"(val = """ """""")"sv,
+ R"(val = ''' '''''')"sv,
+ "val = '\n'"sv,
+
+ "########## integers"sv,
+ R"(val = -0b0)"sv,
+ R"(val = -0o0)"sv,
+ R"(val = -0x0)"sv,
+ R"(val = +0b0)"sv,
+ R"(val = +0o0)"sv,
+ R"(val = +0x0)"sv,
+ R"(val = 1-)"sv,
+ R"(val = -1+)"sv,
+ R"(val = -+1)"sv,
+ R"(val = 1_0_)"sv,
+ R"(val = 1_0_ )"sv,
+ R"(val = 01 )"sv,
+ R"(val = 0b10000000_00000000_00000000_00000000_00000000_00000000_00000000_00000000 )"sv,
+ R"(val = 0o1000000000000000000000 )"sv,
+ R"(val = 9223372036854775808 )"sv,
+ R"(val = 0x8000000000000000 )"sv,
+
+ "########## floats"sv,
+ R"(val = 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.0)"sv,
+ };
+
+ inline constexpr auto divider =
+ "################################################################################"sv;
+
+ void print_string(std::string_view str)
+ {
+ for (char c : str)
+ {
+ if (std::optional<std::string_view> escape_sequence = (c == '\\') ? "\\\\"sv
+ : (c == '\a') ? "\\a"sv
+ : (c == '\b') ? "\\b"sv
+ : (c == '\f') ? "\\f"sv
+ : (c == '\n') ? "\\n"sv
+ : (c == '\r') ? "\\r"sv
+ : (c == '\t') ? "\\t"sv
+ : (c == '\v') ? "\\v"sv
+ : std::optional<std::string_view>{})
+ {
+ std::cout << *escape_sequence;
+ }
+ else
+ {
+ if (c >= 0 && std::iscntrl(c))
+ {
+ // Print a string, just like `toml::impl::control_char_escapes[c]`.
+ std::ostringstream stream;
+ stream << "\\u00"sv << std::setfill('0') << std::setw(2) << std::hex << std::uppercase << int{ c };
+ std::cout << stream.str();
+ }
+ else
+ {
+ std::cout << c;
+ }
+ }
+ }
+ }
+
+ void print_parse_error(std::string_view doc, const toml::parse_error& err)
+ {
+ std::cout << err;
+
+ auto line_num = err.source().begin.line;
+
+ if (auto line = toml::get_line(doc, line_num))
+ {
+ std::cout << "\nLine "sv << line_num << ": "sv;
+ print_string(*line);
+ }
+ std::cout << "\n\n"sv;
+ }
+}
+
+int main()
+{
+ const auto parse_and_print_if_error = [](std::string_view str)
+ {
+#if TOML_EXCEPTIONS
+ try
+ {
+ auto result = toml::parse(str);
+ static_cast<void>(result);
+ }
+ catch (const toml::parse_error& err)
+ {
+ print_parse_error(str, err);
+ }
+#else
+ if (auto result = toml::parse(str); !result)
+ print_parse_error(str, result.error());
+#endif
+ };
+
+ for (auto str : invalid_parses)
+ {
+ if (str.empty())
+ continue;
+
+ // section headings
+ if (str.substr(0, 10) == "##########"sv)
+ {
+ std::cout << divider << '\n';
+ std::cout << "# "sv << str.substr(11) << '\n';
+ std::cout << divider << "\n\n"sv;
+ }
+
+ // error messages
+ else
+ {
+ toml::parse_result result;
+
+ if (str == "PATHOLOGICALLY_NESTED"sv)
+ {
+ std::string s(1000u, '[');
+ constexpr auto start = "array = "sv;
+ memcpy(s.data(), start.data(), start.length());
+ parse_and_print_if_error(s);
+ }
+ else
+ parse_and_print_if_error(str);
+ }
+ }
+ return 0;
+}
diff --git a/tomlplusplus/examples/error_printer.vcxproj b/tomlplusplus/examples/error_printer.vcxproj
new file mode 100644
index 0000000000..d866aa5e3f
--- /dev/null
+++ b/tomlplusplus/examples/error_printer.vcxproj
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup Label="ProjectConfigurations">
+ <ProjectConfiguration Include="Debug|x64">
+ <Configuration>Debug</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|x64">
+ <Configuration>Release</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ </ItemGroup>
+ <PropertyGroup Label="Globals">
+ <VCProjectVersion>16.0</VCProjectVersion>
+ <ProjectGuid>{DAB4634D-8145-4860-AE45-5198E76FF324}</ProjectGuid>
+ <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <PlatformToolset>v143</PlatformToolset>
+ <CharacterSet>MultiByte</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <PlatformToolset>v143</PlatformToolset>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>MultiByte</CharacterSet>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+ <ImportGroup Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <Import Project="..\toml++.props" />
+ <ItemDefinitionGroup>
+ <Link>
+ <SubSystem>Console</SubSystem>
+ </Link>
+ </ItemDefinitionGroup>
+ <PropertyGroup>
+ <LocalDebuggerWorkingDirectory>..\examples</LocalDebuggerWorkingDirectory>
+ </PropertyGroup>
+ <ItemGroup>
+ <Natvis Include="..\toml++.natvis" />
+ </ItemGroup>
+ <ItemGroup>
+ <ClCompile Include="error_printer.cpp" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="meson.build" />
+ </ItemGroup>
+ <ItemGroup>
+ <Text Include="CMakeLists.txt" />
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="examples.hpp" />
+ </ItemGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+</Project> \ No newline at end of file
diff --git a/tomlplusplus/examples/example.toml b/tomlplusplus/examples/example.toml
new file mode 100644
index 0000000000..9612b5301f
--- /dev/null
+++ b/tomlplusplus/examples/example.toml
@@ -0,0 +1,102 @@
+# This is a TOML document. Boom.
+
+title = "TOML Example"
+
+# plain signed integers
+int1 = -9223372036854775808
+int2 = 9223372036854775807
+
+# floats
+flt1 = 0.00000000001
+flt2 = 1e-11
+flt3 = 11.0
+flt4 = +1.0
+
+# hexadecimal with prefix `0x`
+hex1 = 0xDEADBEEF
+hex2 = 0xdeadbeef
+hex3 = 0xdead_beef
+
+# octal with prefix `0o`
+oct1 = 0o01234567
+oct2 = 0o755 # useful for Unix file permissions
+
+# binary with prefix `0b`
+bin1 = 0b11010110 # 214
+
+# local dates and times
+tim1 = 07:32:00
+tim2 = 00:32:00.100000000
+dat1 = 1979-05-27
+
+# offset date-times
+odt1 = 1979-05-27T07:32:00Z
+odt2 = 1979-05-27T00:32:00-07:00
+odt3 = 1979-05-27T00:32:00.999999-07:00
+
+# strings
+str1 = """
+This is a
+multi-line
+string.
+"""
+str2 = "This is also\na multi-line\nstring."
+str3 = 'C:\highway\to\the\danger\zone'
+kosme = "κόσμε" # unicode!
+
+arr = [ 'this', 'is', 'a', 'long', 'array', 'with', 16, 'elements.', 'it', 'should', 'be', 'printed', 'as', 'a', 'multiline', 'array.']
+
+tab = { this = 'is', an = 'inline', table = 'yay'}
+
+dotted.keys.are = "supported"
+dotted.and = "implemented as tables"
+
+[owner]
+name = "Mark Gillard"
+dob = 1987-03-16 10:20:00+09:30
+
+ [[owner.pets]]
+ name = "Brian"
+ species = "cat"
+
+ [[owner.pets]]
+ name = "Skippy"
+ species = "kangaroo"
+
+[database]
+server = "192.168.1.1"
+ports = [ 8001, 8001, 8002 ]
+connection_max = 5000
+enabled = true
+
+[servers]
+
+ # You can indent as you please. Tabs or spaces. TOML don't care.
+ [servers.alpha]
+ ip = "10.0.0.1"
+ dc = "eqdc10"
+
+ [servers.beta]
+ ip = "10.0.0.2"
+ dc = "eqdc10"
+ country = "中国" # This should be parsed as UTF-8
+
+[clients]
+data = [ ["gamma", "delta"], [1, 2] ] # just an update to make sure parsers support it
+
+# Line breaks are OK when inside arrays
+hosts = [
+ "alpha",
+ "omega"
+]
+
+# Products
+
+ [[products]]
+ name = "Hammer"
+ sku = 738594937
+
+ [[products]]
+ name = "Nail"
+ sku = 284758393
+ color = "gray"
diff --git a/tomlplusplus/examples/examples.hpp b/tomlplusplus/examples/examples.hpp
new file mode 100644
index 0000000000..7dc81800de
--- /dev/null
+++ b/tomlplusplus/examples/examples.hpp
@@ -0,0 +1,62 @@
+//# 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.
+// SPDX-License-Identifier: MIT
+
+// this file is for boilerplate unrelated to the toml++ example learning outcomes.
+
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Weverything"
+#elif defined(__GNUC__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wall"
+#pragma GCC diagnostic ignored "-Wextra"
+#elif defined(_MSC_VER)
+#pragma warning(push, 0)
+#endif
+
+#include <cstdlib>
+#include <ctime>
+#include <cassert>
+#include <iostream>
+#include <sstream>
+#include <string>
+#include <string_view>
+#include <vector>
+#include <array>
+#include <chrono>
+#include <fstream>
+#ifdef _WIN32
+#ifdef _MSC_VER
+extern "C" __declspec(dllimport) int __stdcall SetConsoleOutputCP(unsigned int);
+#pragma comment(lib, "Kernel32.lib")
+#else
+#include <Windows.h>
+#endif
+#endif
+
+namespace
+{
+ static const auto initialize_environment_automagically = []() noexcept
+ {
+#ifdef _WIN32
+ SetConsoleOutputCP(65001); // CP_UTF8
+#endif
+
+ std::ios_base::sync_with_stdio(false);
+ std::cout << std::boolalpha;
+
+ srand(static_cast<unsigned int>(time(nullptr)));
+
+ return true;
+ }();
+}
+
+#ifdef __clang__
+#pragma clang diagnostic pop
+#elif defined(__GNUC__)
+#pragma GCC diagnostic pop
+#elif defined(_MSC_VER)
+#pragma warning(pop)
+#endif
diff --git a/tomlplusplus/examples/merge_base.toml b/tomlplusplus/examples/merge_base.toml
new file mode 100644
index 0000000000..a863b27e05
--- /dev/null
+++ b/tomlplusplus/examples/merge_base.toml
@@ -0,0 +1,5 @@
+[section1]
+key1="value1"
+key2="value2"
+
+[section1.child1]
diff --git a/tomlplusplus/examples/merge_overrides.toml b/tomlplusplus/examples/merge_overrides.toml
new file mode 100644
index 0000000000..792396e3e1
--- /dev/null
+++ b/tomlplusplus/examples/merge_overrides.toml
@@ -0,0 +1,8 @@
+[section1]
+key2="value3"
+
+[section1.child1]
+foo="bar"
+
+[section1.child2]
+foo2="bar2"
diff --git a/tomlplusplus/examples/meson.build b/tomlplusplus/examples/meson.build
new file mode 100644
index 0000000000..fa38aab953
--- /dev/null
+++ b/tomlplusplus/examples/meson.build
@@ -0,0 +1,31 @@
+# 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
+
+example_args = []
+example_args += global_args
+
+examples = [
+ 'simple_parser',
+ 'toml_to_json_transcoder',
+ 'toml_generator',
+ 'error_printer',
+ 'parse_benchmark',
+ 'toml_merger',
+]
+
+example_executables = []
+foreach example : examples
+ example_executables += [[
+ example,
+ executable(
+ example,
+ [ example + '.cpp' ],
+ cpp_args: example_args,
+ dependencies: tomlplusplus_dep,
+ override_options: global_overrides,
+ install: not is_subproject
+ )
+ ]]
+endforeach
diff --git a/tomlplusplus/examples/parse_benchmark.cpp b/tomlplusplus/examples/parse_benchmark.cpp
new file mode 100644
index 0000000000..8c2b53d92e
--- /dev/null
+++ b/tomlplusplus/examples/parse_benchmark.cpp
@@ -0,0 +1,81 @@
+// 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
+
+// This example is just a short-n-shiny benchmark.
+
+#include "examples.hpp"
+#include <toml++/toml.hpp>
+
+using namespace std::string_view_literals;
+
+static constexpr size_t iterations = 10000;
+
+int main(int argc, char** argv)
+{
+ const auto file_path = std::string(argc > 1 ? std::string_view{ argv[1] } : "benchmark_data.toml"sv);
+
+ // read the file into a string first to remove file I/O from the benchmark
+ std::string file_content;
+ {
+ std::ifstream file(file_path, std::ifstream::in | std::ifstream::binary | std::ifstream::ate);
+ if (!file)
+ {
+ std::cerr << "File '"sv << file_path << "'could not be opened for reading\n"sv;
+ return -1;
+ }
+
+ const auto file_size = file.tellg();
+ if (file_size == -1)
+ {
+ std::cerr << "File '"sv << file_path << "' could not be opened for reading\n"sv;
+ return -1;
+ }
+ file.seekg(0, std::ifstream::beg);
+
+ file_content.resize(static_cast<size_t>(file_size));
+ file.read(file_content.data(), static_cast<std::streamsize>(file_size));
+ if (!file.eof() && !file)
+ {
+ std::cerr << "Failed to read contents of file '"sv << file_path << "'\n"sv;
+ return -1;
+ }
+ }
+
+ // parse once to make sure it isn't garbage
+ {
+#if TOML_EXCEPTIONS
+ try
+ {
+ const auto result = toml::parse(file_content, file_path);
+ }
+ catch (const toml::parse_error& err)
+ {
+ std::cerr << err << "\n";
+ return 1;
+ }
+#else
+ const auto result = toml::parse(file_content, file_path);
+ if (!result)
+ {
+ std::cerr << result.error() << "\n";
+ return 1;
+ }
+#endif
+ }
+
+ // run the benchmark
+ std::cout << "Parsing '"sv << file_path << "' "sv << iterations << " times...\n"sv;
+
+ const auto start = std::chrono::steady_clock::now();
+ for (size_t i = 0; i < iterations; i++)
+ std::ignore = toml::parse(file_content, file_path);
+ const auto cumulative_sec =
+ std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::steady_clock::now() - start).count();
+ const auto mean_sec = cumulative_sec / static_cast<double>(iterations);
+ std::cout << " total: "sv << cumulative_sec << " s\n"sv
+ << " mean: "sv << mean_sec << " s\n"sv;
+
+ return 0;
+}
diff --git a/tomlplusplus/examples/parse_benchmark.vcxproj b/tomlplusplus/examples/parse_benchmark.vcxproj
new file mode 100644
index 0000000000..6beec675ac
--- /dev/null
+++ b/tomlplusplus/examples/parse_benchmark.vcxproj
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup Label="ProjectConfigurations">
+ <ProjectConfiguration Include="Debug|x64">
+ <Configuration>Debug</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|x64">
+ <Configuration>Release</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ </ItemGroup>
+ <PropertyGroup Label="Globals">
+ <VCProjectVersion>16.0</VCProjectVersion>
+ <ProjectGuid>{407FCAA8-FC2C-424D-B44B-C6A1AFAD757A}</ProjectGuid>
+ <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <PlatformToolset>v143</PlatformToolset>
+ <CharacterSet>MultiByte</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <PlatformToolset>v143</PlatformToolset>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>MultiByte</CharacterSet>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+ <ImportGroup Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <Import Project="..\toml++.props" />
+ <ItemDefinitionGroup>
+ <Link>
+ <SubSystem>Console</SubSystem>
+ </Link>
+ </ItemDefinitionGroup>
+ <PropertyGroup>
+ <LocalDebuggerWorkingDirectory>..\examples</LocalDebuggerWorkingDirectory>
+ </PropertyGroup>
+ <ItemGroup>
+ <Natvis Include="..\toml++.natvis" />
+ </ItemGroup>
+ <ItemGroup>
+ <ClCompile Include="parse_benchmark.cpp" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="benchmark_data.toml" />
+ <None Include="meson.build" />
+ </ItemGroup>
+ <ItemGroup>
+ <Text Include="CMakeLists.txt" />
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="examples.hpp" />
+ </ItemGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+</Project>
diff --git a/tomlplusplus/examples/simple_parser.cpp b/tomlplusplus/examples/simple_parser.cpp
new file mode 100644
index 0000000000..f45202e0f2
--- /dev/null
+++ b/tomlplusplus/examples/simple_parser.cpp
@@ -0,0 +1,36 @@
+// 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
+
+// This example demonstrates how to parse TOML from a file or stdin and re-serialize it (print it out) to stdout.
+
+#include "examples.hpp"
+#include <toml++/toml.hpp>
+
+using namespace std::string_view_literals;
+
+int main(int argc, char** argv)
+{
+ const auto path = argc > 1 ? std::string_view{ argv[1] } : "example.toml"sv;
+
+ toml::table tbl;
+ try
+ {
+ // read directly from stdin
+ if (path == "-"sv || path.empty())
+ tbl = toml::parse(std::cin, "stdin"sv);
+
+ // read from a file
+ else
+ tbl = toml::parse_file(path);
+ }
+ catch (const toml::parse_error& err)
+ {
+ std::cerr << err << "\n";
+ return 1;
+ }
+
+ std::cout << tbl << "\n";
+ return 0;
+}
diff --git a/tomlplusplus/examples/simple_parser.vcxproj b/tomlplusplus/examples/simple_parser.vcxproj
new file mode 100644
index 0000000000..8b90d442f7
--- /dev/null
+++ b/tomlplusplus/examples/simple_parser.vcxproj
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup Label="ProjectConfigurations">
+ <ProjectConfiguration Include="Debug|x64">
+ <Configuration>Debug</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|x64">
+ <Configuration>Release</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ </ItemGroup>
+ <PropertyGroup Label="Globals">
+ <VCProjectVersion>16.0</VCProjectVersion>
+ <ProjectGuid>{259FCEE5-3442-4076-9547-2BA793ECA1CB}</ProjectGuid>
+ <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <PlatformToolset>v143</PlatformToolset>
+ <CharacterSet>MultiByte</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <PlatformToolset>v143</PlatformToolset>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>MultiByte</CharacterSet>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+ <ImportGroup Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <Import Project="..\toml++.props" />
+ <ItemDefinitionGroup>
+ <Link>
+ <SubSystem>Console</SubSystem>
+ </Link>
+ </ItemDefinitionGroup>
+ <PropertyGroup>
+ <LocalDebuggerWorkingDirectory>..\examples</LocalDebuggerWorkingDirectory>
+ </PropertyGroup>
+ <ItemGroup>
+ <ClCompile Include="simple_parser.cpp" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="example.toml" />
+ <None Include="meson.build" />
+ </ItemGroup>
+ <ItemGroup>
+ <Natvis Include="..\toml++.natvis" />
+ </ItemGroup>
+ <ItemGroup>
+ <Text Include="CMakeLists.txt" />
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="examples.hpp" />
+ </ItemGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+</Project>
diff --git a/tomlplusplus/examples/toml_generator.cpp b/tomlplusplus/examples/toml_generator.cpp
new file mode 100644
index 0000000000..c8230db1e3
--- /dev/null
+++ b/tomlplusplus/examples/toml_generator.cpp
@@ -0,0 +1,322 @@
+// 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
+
+// This example demonstrates the use of some more advanced features to generate a tree of random TOML data.
+
+#include "examples.hpp"
+#include <toml++/toml.hpp>
+
+using namespace std::string_view_literals;
+
+namespace
+{
+ namespace random
+ {
+ inline constexpr std::string_view words[] = {
+ "acceptable"sv, "contain"sv, "ghost"sv, "mark"sv, "respect"sv, "taboo"sv,
+ "actually"sv, "cream"sv, "gleaming"sv, "meaty"sv, "rest"sv, "tacky"sv,
+ "addition"sv, "creature"sv, "glorious"sv, "memory"sv, "rice"sv, "tank"sv,
+ "adhesive"sv, "crime"sv, "gold"sv, "messy"sv, "rich"sv, "tent"sv,
+ "adorable"sv, "cross"sv, "grandfather"sv, "miss"sv, "righteous"sv, "terrible"sv,
+ "advise"sv, "crowded"sv, "gusty"sv, "modern"sv, "room"sv, "threatening"sv,
+ "afraid"sv, "crown"sv, "haircut"sv, "morning"sv, "rotten"sv, "three"sv,
+ "ancient"sv, "cure"sv, "hard-to-find"sv, "naughty"sv, "royal"sv, "ticket"sv,
+ "anxious"sv, "curious"sv, "harm"sv, "neck"sv, "run"sv, "title"sv,
+ "aromatic"sv, "curtain"sv, "heavy"sv, "night"sv, "satisfy"sv, "torpid"sv,
+ "attempt"sv, "cycle"sv, "helpless"sv, "nondescript"sv, "scary"sv, "train"sv,
+ "babies"sv, "deadpan"sv, "high-pitched"sv, "overjoyed"sv, "scatter"sv, "umbrella"sv,
+ "bake"sv, "decisive"sv, "hilarious"sv, "page"sv, "scene"sv, "unadvised"sv,
+ "ball"sv, "deeply"sv, "history"sv, "partner"sv, "scintillating"sv, "unbecoming"sv,
+ "bat"sv, "delightful"sv, "hook"sv, "party"sv, "self"sv, "unbiased"sv,
+ "behave"sv, "deserted"sv, "ignore"sv, "pause"sv, "selfish"sv, "unite"sv,
+ "best"sv, "draconian"sv, "imperfect"sv, "pear"sv, "silky"sv, "uptight"sv,
+ "birds"sv, "dreary"sv, "impossible"sv, "picture"sv, "sisters"sv, "used"sv,
+ "blind"sv, "dull"sv, "incandescent"sv, "place"sv, "ski"sv, "vengeful"sv,
+ "blood"sv, "enthusiastic"sv, "influence"sv, "playground"sv, "skip"sv, "versed"sv,
+ "blue-eyed"sv, "equable"sv, "innocent"sv, "popcorn"sv, "snow"sv, "vessel"sv,
+ "boiling"sv, "excuse"sv, "insidious"sv, "prefer"sv, "soap"sv, "view"sv,
+ "bore"sv, "experience"sv, "itch"sv, "productive"sv, "spare"sv, "voyage"sv,
+ "borrow"sv, "fabulous"sv, "jail"sv, "profuse"sv, "spicy"sv, "wall"sv,
+ "broken"sv, "familiar"sv, "kindhearted"sv, "protective"sv, "spiritual"sv, "want"sv,
+ "capable"sv, "finger"sv, "lackadaisical"sv, "pumped"sv, "sprout"sv, "weary"sv,
+ "charming"sv, "finicky"sv, "laughable"sv, "rabbit"sv, "squirrel"sv, "week"sv,
+ "cheerful"sv, "fix"sv, "leather"sv, "rapid"sv, "stale"sv, "whip"sv,
+ "chubby"sv, "flagrant"sv, "legal"sv, "regret"sv, "step"sv, "wilderness"sv,
+ "clean"sv, "flat"sv, "lewd"sv, "reject"sv, "stingy"sv, "wistful"sv,
+ "close"sv, "flimsy"sv, "license"sv, "rejoice"sv, "string"sv, "worried"sv,
+ "cobweb"sv, "fuel"sv, "light"sv, "relation"sv, "sulky"sv, "wretched"sv,
+ "complex"sv, "furtive"sv, "march"sv, "remarkable"sv, "surprise"sv, "zealous"sv,
+ "consist"sv, "geese"sv
+ };
+
+ [[nodiscard]] static bool boolean() noexcept
+ {
+ return std::rand() % 2 == 0;
+ }
+
+ template <typename T>
+ [[nodiscard]] static T integer(T excl_max) noexcept
+ {
+ return static_cast<T>(static_cast<T>(std::rand()) % excl_max);
+ }
+
+ template <typename T>
+ [[nodiscard]] static T integer(T incl_min, T excl_max) noexcept
+ {
+ return static_cast<T>(incl_min + integer(excl_max - incl_min));
+ }
+
+ [[nodiscard]] static bool chance(float val) noexcept
+ {
+ val = (val < 0.0f ? 0.0f : (val > 1.0f ? 1.0f : val)) * 1000.0f;
+ return static_cast<float>(integer(0, 1000)) <= val;
+ }
+
+ [[nodiscard]] static toml::date date() noexcept
+ {
+ return toml::date{ integer(1900, 2021), //
+ integer(1, 13),
+ integer(1, 29) };
+ }
+
+ [[nodiscard]] static toml::time time() noexcept
+ {
+ return toml::time{ integer(24), //
+ integer(60),
+ integer(60),
+ boolean() ? integer(1000000000u) : 0u };
+ }
+
+ [[nodiscard]] static toml::time_offset time_offset() noexcept
+ {
+ return toml::time_offset{ integer(-11, 12), integer(-45, +46) };
+ }
+
+ [[nodiscard]] static toml::date_time date_time() noexcept
+ {
+ return boolean() ? toml::date_time{ date(), time() } //
+ : toml::date_time{ date(), time(), time_offset() };
+ }
+
+ [[nodiscard]] static std::string_view word() noexcept
+ {
+ return words[integer(std::size(words))];
+ }
+
+ [[nodiscard]] static std::string string(size_t word_count, char sep = ' ')
+ {
+ std::string val;
+ while (word_count-- > 0u)
+ {
+ if (!val.empty())
+ val += sep;
+ val.append(word());
+ }
+ return val;
+ }
+
+ [[nodiscard]] static std::string key()
+ {
+ return random::string(random::integer(1u, 4u), '-');
+ }
+
+ }
+
+ template <typename T>
+ static auto add_to(toml::table& tbl, T&& val) -> toml::inserted_type_of<T&&>&
+ {
+ while (true)
+ {
+ auto key = random::key();
+ auto it = std::as_const(tbl).lower_bound(key);
+ if (it == tbl.cend() || it->first != key)
+ {
+ return *tbl.emplace_hint(it, std::move(key), static_cast<T&&>(val))
+ ->second.template as<toml::inserted_type_of<T&&>>();
+ }
+ }
+ }
+
+ template <typename T>
+ static auto add_to(toml::array& arr, T&& val) -> toml::inserted_type_of<T&&>&
+ {
+ return arr.emplace_back(static_cast<T&&>(val));
+ }
+
+ template <typename Container>
+ static void add_value_to(Container& container)
+ {
+ static_assert(toml::is_container<Container>);
+
+ switch (random::integer(7))
+ {
+ case 0: add_to(container, random::string(random::integer(8u))); break;
+ case 1: add_to(container, random::integer(1000)); break;
+ case 2: add_to(container, random::integer(10001) / 10000.0); break;
+ case 3: add_to(container, random::boolean()); break;
+ case 4: add_to(container, random::date()); break;
+ case 5: add_to(container, random::time()); break;
+ case 6: add_to(container, random::date_time()); break;
+ default: break;
+ }
+ }
+
+ static constexpr int max_inline_nesting = 2;
+ static constexpr int default_max_inline_values = 4;
+
+ template <typename Container>
+ static void populate_inline_container(Container& container,
+ int& budget,
+ int inline_nesting = 0,
+ int max_values = default_max_inline_values)
+ {
+ static_assert(toml::is_container<Container>);
+
+ auto values = random::integer(max_values);
+ while (budget && values)
+ {
+ // inline array/table
+ if (inline_nesting < max_inline_nesting && random::chance(0.25f))
+ {
+ // array
+ if (random::boolean())
+ {
+ auto& arr = add_to(container, toml::array{});
+ populate_inline_container(arr, budget, inline_nesting + 1, default_max_inline_values);
+ }
+
+ // table
+ else
+ {
+ auto& tbl = add_to(container, toml::table{});
+ tbl.is_inline(true);
+ populate_inline_container(tbl, budget, inline_nesting + 1, default_max_inline_values);
+ }
+ }
+
+ // regular value
+ else
+ {
+ add_value_to(container);
+ budget--;
+ }
+
+ values--;
+ }
+ }
+
+ static constexpr int max_top_level_nesting = 5;
+ static constexpr int max_array_of_tables_children = 4;
+ static constexpr int max_table_children = 4;
+
+ static void populate_table(toml::table& tbl, int& budget, int nesting = 0)
+ {
+ assert(!tbl.is_inline());
+
+ // do simple values + inline tables/arrays first
+ populate_inline_container(tbl, budget, 0, 10);
+
+ // add a nested array-of-tables
+ if (budget && nesting < max_top_level_nesting && random::chance(0.33f))
+ {
+ auto& arr = add_to(tbl, toml::array{});
+ // note we don't subtract from the budget for the outer array;
+ // it's "invisible" from a topological perspective when reading the output TOML
+
+ auto children = random::integer(1, max_array_of_tables_children);
+ while (budget && children)
+ {
+ auto& sub_tbl = add_to(arr, toml::table{});
+ budget--;
+ children--;
+
+ populate_table(sub_tbl, budget, nesting + 1);
+ }
+ }
+
+ // add nested tables
+ if (budget && nesting < max_top_level_nesting && random::chance(0.33f))
+ {
+ auto children = random::integer(1, max_table_children);
+ while (budget && children)
+ {
+ auto& sub_tbl = add_to(tbl, toml::table{});
+ budget--;
+ children--;
+
+ populate_table(sub_tbl, budget, nesting + 1);
+ }
+ }
+ }
+}
+
+int main(int argc, char** argv)
+{
+ int budget{};
+ bool comments = true;
+ for (int i = 1; i < argc; i++)
+ {
+ const auto arg = std::string_view{ argv[i] };
+ if (arg == "--nocomments"sv)
+ comments = false;
+ else
+ {
+ std::istringstream ss{ std::string(arg) };
+ int num;
+ if ((ss >> num))
+ budget += num;
+ else
+ {
+ std::cerr << "Unknown argument '"sv << arg << "'\n";
+ return 1;
+ }
+ }
+ }
+ if (budget <= 0)
+ budget = 100;
+
+ toml::table root;
+ while (budget > 0)
+ populate_table(root, budget);
+
+ if (comments)
+ {
+ std::stringstream src;
+ src << root;
+
+ std::string line;
+ std::ostringstream dest;
+ while (std::getline(src, line))
+ {
+ if (line.empty())
+ {
+ // occasionally dump a paragraph comment at the top-level of the document
+ if (random::chance(0.20f))
+ {
+ auto lines = random::integer(1, 8);
+ while (lines--)
+ dest << "\n# "sv << random::string(random::integer(4u, 8u));
+ dest << "\n"sv;
+ }
+ }
+ else
+ {
+ dest << line;
+
+ // occasionally add short comments at end of non-blank lines
+ if (random::chance(0.30f))
+ dest << " # "sv << random::string(random::integer(1u, 3u));
+ }
+
+ dest << "\n"sv;
+ }
+ std::cout << dest.str();
+ }
+ else
+ {
+ std::cout << root << "\n";
+ }
+ return 0;
+}
diff --git a/tomlplusplus/examples/toml_generator.vcxproj b/tomlplusplus/examples/toml_generator.vcxproj
new file mode 100644
index 0000000000..4a7bdfe5f7
--- /dev/null
+++ b/tomlplusplus/examples/toml_generator.vcxproj
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup Label="ProjectConfigurations">
+ <ProjectConfiguration Include="Debug|x64">
+ <Configuration>Debug</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|x64">
+ <Configuration>Release</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ </ItemGroup>
+ <PropertyGroup Label="Globals">
+ <VCProjectVersion>16.0</VCProjectVersion>
+ <ProjectGuid>{23CE3B73-FEE7-436C-9B4E-3DFB202EE9A2}</ProjectGuid>
+ <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
+ <ProjectName>toml_generator</ProjectName>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <PlatformToolset>v143</PlatformToolset>
+ <CharacterSet>MultiByte</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <PlatformToolset>v143</PlatformToolset>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>MultiByte</CharacterSet>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+ <ImportGroup Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <Import Project="..\toml++.props" />
+ <ItemDefinitionGroup>
+ <Link>
+ <SubSystem>Console</SubSystem>
+ </Link>
+ </ItemDefinitionGroup>
+ <PropertyGroup>
+ <LocalDebuggerWorkingDirectory>..\examples</LocalDebuggerWorkingDirectory>
+ </PropertyGroup>
+ <ItemGroup>
+ <ClCompile Include="toml_generator.cpp" />
+ </ItemGroup>
+ <ItemGroup>
+ <Natvis Include="..\toml++.natvis" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="meson.build" />
+ </ItemGroup>
+ <ItemGroup>
+ <Text Include="CMakeLists.txt" />
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="examples.hpp" />
+ </ItemGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+</Project>
diff --git a/tomlplusplus/examples/toml_merger.cpp b/tomlplusplus/examples/toml_merger.cpp
new file mode 100644
index 0000000000..5835b81693
--- /dev/null
+++ b/tomlplusplus/examples/toml_merger.cpp
@@ -0,0 +1,101 @@
+// 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
+
+// This example demonstrates a method of merging one TOML data tree into another.
+
+#include "examples.hpp"
+#include <toml++/toml.hpp>
+
+using namespace std::string_view_literals;
+
+namespace
+{
+ // recursively merge 'rhs' into 'lhs'.
+ //
+ // note that this implementation always prioritizes 'rhs' over 'lhs' in the event of a conflict;
+ // extending it to handle conflicts in some other manner is left as an exercise to the reader :)
+
+ static void merge_left(toml::table& lhs, toml::table&& rhs);
+
+ static void merge_left(toml::array& lhs, toml::array&& rhs)
+ {
+ rhs.for_each(
+ [&](std::size_t index, auto&& rhs_val)
+ {
+ // rhs index not found in lhs - direct move
+ if (lhs.size() <= index)
+ {
+ lhs.push_back(std::move(rhs_val));
+ return;
+ }
+
+ // both elements were the same container type - recurse into them
+ if constexpr (toml::is_container<decltype(rhs_val)>)
+ {
+ using rhs_type = std::remove_cv_t<std::remove_reference_t<decltype(rhs_val)>>;
+ if (auto lhs_child = lhs[index].as<rhs_type>())
+ {
+ merge_left(*lhs_child, std::move(rhs_val));
+ return;
+ }
+ }
+
+ // replace lhs element with rhs
+ lhs.replace(lhs.cbegin() + static_cast<std::ptrdiff_t>(index), std::move(rhs_val));
+ });
+ }
+
+ static void merge_left(toml::table& lhs, toml::table&& rhs)
+ {
+ rhs.for_each(
+ [&](const toml::key& rhs_key, auto&& rhs_val)
+ {
+ auto lhs_it = lhs.lower_bound(rhs_key);
+
+ // rhs key not found in lhs - direct move
+ if (lhs_it == lhs.cend() || lhs_it->first != rhs_key)
+ {
+ using rhs_type = std::remove_cv_t<std::remove_reference_t<decltype(rhs_val)>>;
+ lhs.emplace_hint<rhs_type>(lhs_it, rhs_key, std::move(rhs_val));
+ return;
+ }
+
+ // both children were the same container type - recurse into them
+ if constexpr (toml::is_container<decltype(rhs_val)>)
+ {
+ using rhs_type = std::remove_cv_t<std::remove_reference_t<decltype(rhs_val)>>;
+ if (auto lhs_child = lhs_it->second.as<rhs_type>())
+ {
+ merge_left(*lhs_child, std::move(rhs_val));
+ return;
+ }
+ }
+
+ // replace lhs value with rhs
+ lhs.insert_or_assign(rhs_key, std::move(rhs_val));
+ });
+ }
+}
+
+int main(int argc, char** argv)
+{
+ const auto base_path = argc > 1 ? std::string_view{ argv[1] } : "merge_base.toml"sv;
+ const auto overrides_path = argc > 2 ? std::string_view{ argv[2] } : "merge_overrides.toml"sv;
+
+ toml::table tbl;
+ try
+ {
+ tbl = toml::parse_file(base_path);
+ merge_left(tbl, toml::parse_file(overrides_path));
+ }
+ catch (const toml::parse_error& err)
+ {
+ std::cerr << err << "\n";
+ return 1;
+ }
+
+ std::cout << tbl << "\n";
+ return 0;
+}
diff --git a/tomlplusplus/examples/toml_merger.vcxproj b/tomlplusplus/examples/toml_merger.vcxproj
new file mode 100644
index 0000000000..13cb3c3b57
--- /dev/null
+++ b/tomlplusplus/examples/toml_merger.vcxproj
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup Label="ProjectConfigurations">
+ <ProjectConfiguration Include="Debug|x64">
+ <Configuration>Debug</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|x64">
+ <Configuration>Release</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ </ItemGroup>
+ <PropertyGroup Label="Globals">
+ <VCProjectVersion>16.0</VCProjectVersion>
+ <ProjectGuid>{E467EB97-B066-4D38-B3DB-60961E3F96A1}</ProjectGuid>
+ <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <PlatformToolset>v143</PlatformToolset>
+ <CharacterSet>MultiByte</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <PlatformToolset>v143</PlatformToolset>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>MultiByte</CharacterSet>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+ <ImportGroup Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <Import Project="..\toml++.props" />
+ <ItemDefinitionGroup>
+ <Link>
+ <SubSystem>Console</SubSystem>
+ </Link>
+ </ItemDefinitionGroup>
+ <PropertyGroup>
+ <LocalDebuggerWorkingDirectory>..\examples</LocalDebuggerWorkingDirectory>
+ </PropertyGroup>
+ <ItemGroup>
+ <ClCompile Include="toml_merger.cpp" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="merge_overrides.toml" />
+ <None Include="merge_base.toml" />
+ <None Include="meson.build" />
+ </ItemGroup>
+ <ItemGroup>
+ <Natvis Include="..\toml++.natvis" />
+ </ItemGroup>
+ <ItemGroup>
+ <Text Include="CMakeLists.txt" />
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="examples.hpp" />
+ </ItemGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+</Project>
diff --git a/tomlplusplus/examples/toml_to_json_transcoder.cpp b/tomlplusplus/examples/toml_to_json_transcoder.cpp
new file mode 100644
index 0000000000..f47143b6b4
--- /dev/null
+++ b/tomlplusplus/examples/toml_to_json_transcoder.cpp
@@ -0,0 +1,36 @@
+// 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
+
+// This example demonstrates how to use the toml::json_formatter to re-serialize TOML data as JSON.
+
+#include "examples.hpp"
+#include <toml++/toml.hpp>
+
+using namespace std::string_view_literals;
+
+int main(int argc, char** argv)
+{
+ const auto path = argc > 1 ? std::string_view{ argv[1] } : ""sv;
+
+ toml::table table;
+ try
+ {
+ // read directly from stdin
+ if (path == "-"sv || path.empty())
+ table = toml::parse(std::cin, "stdin"sv);
+
+ // read from a file
+ else
+ table = toml::parse_file(argv[1]);
+ }
+ catch (const toml::parse_error& err)
+ {
+ std::cerr << err << "\n";
+ return 1;
+ }
+
+ std::cout << toml::json_formatter{ table } << "\n";
+ return 0;
+}
diff --git a/tomlplusplus/examples/toml_to_json_transcoder.vcxproj b/tomlplusplus/examples/toml_to_json_transcoder.vcxproj
new file mode 100644
index 0000000000..3faf4ba278
--- /dev/null
+++ b/tomlplusplus/examples/toml_to_json_transcoder.vcxproj
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup Label="ProjectConfigurations">
+ <ProjectConfiguration Include="Debug|x64">
+ <Configuration>Debug</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|x64">
+ <Configuration>Release</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ </ItemGroup>
+ <PropertyGroup Label="Globals">
+ <VCProjectVersion>16.0</VCProjectVersion>
+ <ProjectGuid>{BE34AA99-BEE6-4B50-B237-217E7C88FCB5}</ProjectGuid>
+ <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
+ <ProjectName>toml_to_json_transcoder</ProjectName>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <PlatformToolset>v143</PlatformToolset>
+ <CharacterSet>MultiByte</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <PlatformToolset>v143</PlatformToolset>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>MultiByte</CharacterSet>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+ <ImportGroup Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <Import Project="..\toml++.props" />
+ <ItemDefinitionGroup>
+ <Link>
+ <SubSystem>Console</SubSystem>
+ </Link>
+ </ItemDefinitionGroup>
+ <PropertyGroup>
+ <LocalDebuggerWorkingDirectory>..\examples</LocalDebuggerWorkingDirectory>
+ </PropertyGroup>
+ <ItemGroup>
+ <ClCompile Include="toml_to_json_transcoder.cpp" />
+ </ItemGroup>
+ <ItemGroup>
+ <Natvis Include="..\toml++.natvis" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="meson.build" />
+ </ItemGroup>
+ <ItemGroup>
+ <Text Include="CMakeLists.txt" />
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="examples.hpp" />
+ </ItemGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+</Project>