-
-
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.
Mainly to simplify a the error handling code (it had gotten a bit verbose), but also to reduce compiled binary sizes. also: - moved windows terminal code page stuff in examples to a separate file
- Loading branch information
Showing
11 changed files
with
1,293 additions
and
2,378 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 |
---|---|---|
@@ -1,17 +1,23 @@ | ||
// This file is a part of toml++ and is subject to the the terms of the MIT license. | ||
// Copyright (c) 2019-2020 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 how to use the toml::json_formatter to | ||
re-serialize TOML data as JSON. | ||
*/ | ||
#include <iostream> | ||
#include <fstream> | ||
#include "utf8_console.h" | ||
#define TOML_UNRELEASED_FEATURES 1 | ||
#include <toml++/toml.h> | ||
#ifdef _WIN32 | ||
#define WIN32_LEAN_AND_MEAN | ||
#include <Windows.h> | ||
#endif | ||
using namespace std::string_view_literals; | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
#ifdef _WIN32 | ||
SetConsoleOutputCP(65001); //UTF-8 console output | ||
#endif | ||
init_utf8_console(); | ||
|
||
auto path = std::string{ argc > 1 ? argv[1] : "example.toml" }; | ||
auto file = std::ifstream{ path }; | ||
|
@@ -27,7 +33,7 @@ int main(int argc, char** argv) | |
} | ||
catch (const toml::parse_error& err) | ||
{ | ||
std::cerr << "Error parsing file:\n"sv << err << std::endl; | ||
std::cerr << err << std::endl; | ||
return 1; | ||
} | ||
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 |
---|---|---|
@@ -1,19 +1,25 @@ | ||
// This file is a part of toml++ and is subject to the the terms of the MIT license. | ||
// Copyright (c) 2019-2020 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 how to parse TOML from a file and | ||
re-serialize it (print it out) to stdout. | ||
*/ | ||
#include <iostream> | ||
#include <fstream> | ||
#include "utf8_console.h" | ||
#define TOML_UNRELEASED_FEATURES 1 | ||
#include <toml++/toml.h> | ||
#ifdef _WIN32 | ||
#define WIN32_LEAN_AND_MEAN | ||
#include <Windows.h> | ||
#endif | ||
using namespace std::string_view_literals; | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
#ifdef _WIN32 | ||
SetConsoleOutputCP(65001); //UTF-8 console output | ||
#endif | ||
init_utf8_console(); | ||
|
||
//read from a file | ||
// read from a file if a path argument is given | ||
if (argc > 1) | ||
{ | ||
auto path = std::string{ argv[1] }; | ||
|
@@ -31,23 +37,23 @@ int main(int argc, char** argv) | |
} | ||
catch (const toml::parse_error& err) | ||
{ | ||
std::cerr << "Error parsing file:\n"sv << err << std::endl; | ||
std::cerr << err << std::endl; | ||
|
||
return 1; | ||
} | ||
} | ||
|
||
//read directly from stdin | ||
// otherwise read directly from stdin | ||
else | ||
{ | ||
try | ||
{ | ||
const auto table = toml::parse(std::cin); | ||
const auto table = toml::parse(std::cin, "stdin"sv); | ||
std::cout << toml::json_formatter{ table } << std::endl; | ||
} | ||
catch (const toml::parse_error& err) | ||
{ | ||
std::cerr << "Error parsing stdin:\n"sv << err << std::endl; | ||
std::cerr << err << std::endl; | ||
|
||
return 1; | ||
} | ||
|
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 @@ | ||
//# This file is a part of toml++ and is subject to the the terms of the MIT license. | ||
//# Copyright (c) 2019-2020 Mark Gillard <[email protected]> | ||
//# See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text. | ||
// SPDX-License-Identifier: MIT | ||
|
||
#ifdef _WIN32 | ||
|
||
#define WIN32_LEAN_AND_MEAN | ||
#define VC_EXTRALEAN | ||
#define NOATOM // - Atom Manager routines | ||
#define NOBITMAP | ||
#define NOCLIPBOARD // - Clipboard routines | ||
#define NOCOLOR // - Screen colors | ||
#define NOCOMM // - COMM driver routines | ||
#define NOCTLMGR // - Control and Dialog routines | ||
#define NODEFERWINDOWPOS // - DeferWindowPos routines | ||
#define NODRAWTEXT // - DrawText() and DT_* | ||
#define NOGDI // - All GDI defines and routines | ||
#define NOGDICAPMASKS // - CC_*, LC_*, PC_*, CP_*, TC_*, RC_ | ||
#define NOHELP // - Help engine interface. | ||
#define NOICONS // - IDI_* | ||
#define NOKANJI // - Kanji support stuff. | ||
#define NOKEYSTATES // - MK_* | ||
#define NOKERNEL // - All KERNEL defines and routines | ||
#define NOMB // - MB_* and MessageBox() | ||
#define NOMCX // - Modem Configuration Extensions | ||
#define NOMENUS // - MF_* | ||
#define NOMEMMGR // - GMEM_*, LMEM_*, GHND, LHND, associated routines | ||
#define NOMETAFILE // - typedef METAFILEPICT | ||
#define NOMINMAX // - Macros min(a,b) and max(a,b) | ||
#define NOMSG // - typedef MSG and associated routines | ||
#define NONLS // - All NLS defines and routines | ||
#define NOOPENFILE // - OpenFile(), OemToAnsi, AnsiToOem, and OF_* | ||
#define NOPROFILER // - Profiler interface. | ||
#define NORASTEROPS // - Binary and Tertiary raster ops | ||
#define NOSCROLL // - SB_* and scrolling routines | ||
#define NOSERVICE // - All Service Controller routines, SERVICE_ equates, etc. | ||
#define NOSHOWWINDOW // - SW_* | ||
#define NOSOUND // - Sound driver routines | ||
#define NOSYSCOMMANDS // - SC_* | ||
#define NOSYSMETRICS // - SM_* | ||
#define NOTEXTMETRIC // - typedef TEXTMETRIC and associated routines | ||
#define NOUSER // - All USER defines and routines | ||
#define NOVIRTUALKEYCODES // - VK_* | ||
#define NOWH // - SetWindowsHook and WH_* | ||
#define NOWINOFFSETS // - GWL_*, GCL_*, associated routines | ||
#define NOWINMESSAGES // - WM_*, EM_*, LB_*, CB_* | ||
#define NOWINSTYLES // - WS_*, CS_*, ES_*, LBS_*, SBS_*, CBS_* | ||
#include <Windows.h> | ||
|
||
inline void init_utf8_console() noexcept | ||
{ | ||
SetConsoleOutputCP(65001); //CP_UTF8 | ||
} | ||
|
||
#else | ||
|
||
inline void init_utf8_console() noexcept | ||
{ | ||
// no-op | ||
} | ||
|
||
#endif |
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
Oops, something went wrong.