| 302 | } |
| 303 | |
| 304 | Error TextParser::makeParseError(std::string_view str, std::string_view sourceErrorMessage, size_t position) { |
| 305 | SC_ASSERT(position <= str.size()); |
| 306 | auto targetEndPosition = position + kMaxErrorMessageLength; |
| 307 | auto resolvedEndPosition = std::min(str.size(), targetEndPosition); |
| 308 | |
| 309 | auto debugString = str.substr(position, resolvedEndPosition - position); |
| 310 | |
| 311 | std::string suffix; |
| 312 | if (debugString.empty()) { |
| 313 | suffix = "<EOF>"; |
| 314 | } else { |
| 315 | suffix = debugString; |
| 316 | if (debugString.size() != str.size() - position) { |
| 317 | suffix += "…"; |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | return Error(STRING_FORMAT("At position {} ({}): {}", position, suffix, sourceErrorMessage)); |
| 322 | } |
| 323 | |
| 324 | } // namespace Valdi |