2020-04-11 16:43:38 +00:00
|
|
|
// This file is a part of toml++ and is subject to the the terms of the MIT license.
|
2021-01-02 15:48:47 +00:00
|
|
|
// Copyright (c) Mark Gillard <mark.gillard@outlook.com.au>
|
2020-04-11 16:43:38 +00:00
|
|
|
// See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text.
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
2021-11-25 18:20:22 +00:00
|
|
|
// This example demonstrates how to parse TOML from a file or stdin and re-serialize it (print it out) to stdout.
|
2020-04-11 16:43:38 +00:00
|
|
|
|
2022-01-04 14:23:45 +00:00
|
|
|
#include "examples.h"
|
2020-02-22 14:10:32 +00:00
|
|
|
#include <toml++/toml.h>
|
2020-06-28 22:57:59 +00:00
|
|
|
|
2020-01-04 14:21:38 +00:00
|
|
|
using namespace std::string_view_literals;
|
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
2021-05-21 11:28:45 +00:00
|
|
|
const auto path = argc > 1 ? std::string_view{ argv[1] } : "example.toml"sv;
|
2021-11-25 18:20:22 +00:00
|
|
|
|
2022-01-03 18:51:03 +00:00
|
|
|
toml::table tbl;
|
2020-01-04 14:21:38 +00:00
|
|
|
try
|
|
|
|
{
|
2021-11-25 18:20:22 +00:00
|
|
|
// read directly from stdin
|
|
|
|
if (path == "-"sv || path.empty())
|
2022-01-03 18:51:03 +00:00
|
|
|
tbl = toml::parse(std::cin, "stdin"sv);
|
2021-11-25 18:20:22 +00:00
|
|
|
|
|
|
|
// read from a file
|
|
|
|
else
|
2022-01-03 18:51:03 +00:00
|
|
|
tbl = toml::parse_file(path);
|
2020-01-04 14:21:38 +00:00
|
|
|
}
|
|
|
|
catch (const toml::parse_error& err)
|
|
|
|
{
|
2020-08-11 13:34:03 +00:00
|
|
|
std::cerr << err << "\n";
|
2020-01-04 14:21:38 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2021-11-25 18:20:22 +00:00
|
|
|
|
2022-01-03 18:51:03 +00:00
|
|
|
std::cout << tbl << "\n";
|
2020-01-04 14:21:38 +00:00
|
|
|
return 0;
|
|
|
|
}
|