-
-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
closes #155
- Loading branch information
Showing
9 changed files
with
158 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -280,6 +280,7 @@ UTF-8 decoding is performed using a state machine based on Bjoern Hoehrmann's '[ | |
# Contact | ||
For bug reports and feature requests please consider using the [issues] system here on GitHub. For anything else | ||
though you're welcome to reach out via other means. In order of likely response time: | ||
- Gitter: [marzer/tomlplusplus](https://gitter.im/marzer/tomlplusplus) ("Discord for repos") | ||
- Twitter: [marzer8789](https://twitter.com/marzer8789) | ||
- Email: [[email protected]](mailto:[email protected]) | ||
- Facebook: [marzer](https://www.facebook.com/marzer) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -591,6 +591,7 @@ it is embedded in the preamble at the top of the header. | |
\section mainpage-contact Contacting the author | ||
For bug reports and feature requests please use the \github{marzer/tomlplusplus/issues, Github Issues} | ||
system. For anything else you're welcome to reach out via other means. In order of likely response speed: | ||
- Gitter: [marzer/tomlplusplus](https://gitter.im/marzer/tomlplusplus) ("Discord for repos") | ||
- Twitter: [marzer8789](https://twitter.com/marzer8789) | ||
- Email: [[email protected]](mailto:[email protected]) | ||
- Facebook: [marzer](https://www.facebook.com/marzer) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[section1] | ||
key1="value1" | ||
key2="value2" | ||
|
||
[section1.child1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[section1] | ||
key2="value3" | ||
|
||
[section1.child1] | ||
foo="bar" | ||
|
||
[section1.child2] | ||
foo2="bar2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// This file is a part of toml++ and is subject to the the terms of the MIT license. | ||
// Copyright (c) Mark Gillard <[email protected]> | ||
// 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.h" | ||
#include <toml++/toml.h> | ||
|
||
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(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); | ||
|
||
// not found in lhs - direct move | ||
if (lhs_it == lhs.cend() || lhs_it->first != rhs_key) | ||
{ | ||
lhs.emplace_hint(lhs_it, rhs_key, std::move(rhs_val)); | ||
return; | ||
} | ||
|
||
// both nodes were tables - recurse into them | ||
if constexpr (toml::is_table<decltype(rhs_val)>) | ||
{ | ||
if (auto lhs_child_table = lhs_it->second.as_table()) | ||
{ | ||
merge(*lhs_child_table, std::move(rhs_val)); | ||
return; | ||
} | ||
} | ||
|
||
// one or both weren't tables - replace lhs 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(tbl, toml::parse_file(overrides_path)); | ||
} | ||
catch (const toml::parse_error& err) | ||
{ | ||
std::cerr << err << "\n"; | ||
return 1; | ||
} | ||
|
||
std::cout << tbl << "\n"; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.h" /> | ||
</ItemGroup> | ||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters