| 33 | using TomlBasicValue = toml::basic_value<toml::discard_comments, tsl::ordered_map, std::vector>; |
| 34 | |
| 35 | static std::string format_key_message(const std::string &message, const toml::key &ky, const TomlBasicValue &value) { |
| 36 | auto loc = value.location(); |
| 37 | auto line_number_str = std::to_string(loc.line()); |
| 38 | auto line_width = line_number_str.length(); |
| 39 | const auto &line_str = loc.line_str(); |
| 40 | |
| 41 | std::ostringstream oss; |
| 42 | oss << message << "\n"; |
| 43 | oss << " --> " << loc.file_name() << ':' << loc.line() << '\n'; |
| 44 | |
| 45 | oss << std::string(line_width + 2, ' ') << "|\n"; |
| 46 | oss << ' ' << line_number_str << " | " << line_str << '\n'; |
| 47 | |
| 48 | oss << std::string(line_width + 2, ' ') << '|'; |
| 49 | auto key_start = line_str.substr(0, loc.column() - 1).rfind(ky); |
| 50 | if (key_start == std::string::npos) { |
| 51 | key_start = line_str.find(ky); |
| 52 | } |
| 53 | if (key_start != std::string::npos) { |
| 54 | oss << std::string(key_start + 1, ' ') << std::string(ky.length(), '~'); |
| 55 | } |
| 56 | |
| 57 | return oss.str(); |
| 58 | } |
| 59 | |
| 60 | static void throw_key_error(const std::string &error, const toml::key &ky, const TomlBasicValue &value) { |
| 61 | throw std::runtime_error(format_key_message("[error] " + error, ky, value)); |
no outgoing calls
no test coverage detected