Support opting out of the default [error] prefix

This commit is contained in:
Ken Matsui 2022-05-22 13:50:45 +09:00
parent 5924325652
commit c26aa013cd
No known key found for this signature in database
GPG Key ID: 103360B3298EE433
2 changed files with 17 additions and 2 deletions

View File

@ -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.

View File

@ -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';
}