Files
tomlplusplus/examples/simple_parser.cpp
Mark Gillard f3bd22bff4 fixed some incorrect handling of vertical whitespace when printing TOML to streams
also:
- added `date_time` converting constructors from `date` and `time`
- added `is_key<>` and is_key_or_convertible<>` metafunctions
- exposed `TOML_NAMESPACE_START` and `TOML_NAMESPACE_END` macros to help with ADL specialization scenarios
- added encoder and decoder for `toml-test` (closes #125)
2022-01-03 21:01:32 +02:00

39 lines
963 B
C++

// 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"
#define TOML_ENABLE_UNRELEASED_FEATURES 1
#include <toml++/toml.h>
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;
}