From c26aa013cdc75286f90e6d9f661c14890b3f358f Mon Sep 17 00:00:00 2001 From: Ken Matsui <26405363+ken-matsui@users.noreply.github.com> Date: Sun, 22 May 2022 13:50:45 +0900 Subject: [PATCH] Support opting out of the default `[error]` prefix --- README.md | 9 +++++++++ toml/source_location.hpp | 10 ++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e58b93f..1ded07a 100644 --- a/README.md +++ b/README.md @@ -1630,6 +1630,15 @@ Note: It colorize `[error]` in red. That means that it detects `[error]` prefix at the front of the error message. If there is no `[error]` prefix, `format_error` adds it to the error message. +## Opting out of the default `[error]` prefix + +toml11 prints error messages with the `[error]` prefix by default. +Defining `TOML11_NO_ERROR_PREFIX` will let toml11 omit the prefix regardless of colorized or not in case you would use a custom prefix, such as `Error:`. + +```cpp +#define TOML11_NO_ERROR_PREFIX +``` + ## Serializing TOML data toml11 enables you to serialize data into toml format. diff --git a/toml/source_location.hpp b/toml/source_location.hpp index fa175b5..c97d6f6 100644 --- a/toml/source_location.hpp +++ b/toml/source_location.hpp @@ -137,12 +137,18 @@ inline std::string format_underline(const std::string& message, // if it is "[error]", it removes that part from the message shown. if(message.size() > 7 && message.substr(0, 7) == "[error]") { - retval << color::bold << color::red << "[error]" << color::reset + retval +#ifndef TOML11_NO_ERROR_PREFIX + << color::bold << color::red << "[error]" << color::reset +#endif << color::bold << message.substr(7) << color::reset << '\n'; } else { - retval << color::bold << color::red << "[error] " << color::reset + retval +#ifndef TOML11_NO_ERROR_PREFIX + << color::bold << color::red << "[error] " << color::reset +#endif << color::bold << message << color::reset << '\n'; }