From f4ac286b0f9570b697b5e85c46d57b6e9c37b911 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Thu, 12 Dec 2019 21:31:21 +0900 Subject: [PATCH] doc: add description about format_error --- README.md | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3db66b1..b9d5d31 100644 --- a/README.md +++ b/README.md @@ -1361,8 +1361,23 @@ By defining `TOML11_COLORIZE_ERROR_MESSAGE`, the error messages from `toml::parse` and `toml::find|get` will be colorized. By default, this feature is turned off. -Note that the message would be messy when it is written to a file, not a terminal -because it uses [ANSI escape code](https://en.wikipedia.org/wiki/ANSI_escape_code). +The message would be messy when it is written to a file, not a terminal because +it uses [ANSI escape code](https://en.wikipedia.org/wiki/ANSI_escape_code). + +Without `TOML11_COLORIZE_ERROR_MESSAGE`, you can still colorize user-defined +error message by passing `true` to the `toml::format_error` function. +If you define `TOML11_COLORIZE_ERROR_MESSAGE`, the value is `true` by default. +If not, the defalut value would be `false`. + +```cpp +std::cerr << toml::format_error("[error] value should be positive", + data.at("num"), "positive number required", + hints, /*colorize = */ true) << std::endl; +``` + +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. ## Serializing TOML data