Skip to content

Replace use of standard IO from error handling #3239

Closed
@theShmoo

Description

@theShmoo

In
https://github.com/nlohmann/json/blame/develop/include/nlohmann/detail/output/serializer.hpp#L598-L599
and
https://github.com/nlohmann/json/blame/develop/include/nlohmann/detail/output/serializer.hpp#L504-L505
std::stringstream is used.

Use fmt instead. Instead of:

std::stringstream ss;
ss << std::uppercase << std::setfill('0') << std::setw(2) << std::hex << (byte | 0);
JSON_THROW(type_error::create(316, "invalid UTF-8 byte at index " + std::to_string(i) + ": 0x" + ss.str(), BasicJsonType()));

use:

JSON_THROW(type_error::create(316, fmt::format("invalid UTF-8 byte at index {}: {:#04x}", i, byte), BasicJsonType()));

Metadata

Metadata

Assignees

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions