Merge pull request #1117 from TinyTinni/develop
remove stringstream dependency
This commit is contained in:
commit
e830bc502f
3 changed files with 14 additions and 22 deletions
|
@ -6,12 +6,10 @@
|
||||||
#include <cmath> // ldexp
|
#include <cmath> // ldexp
|
||||||
#include <cstddef> // size_t
|
#include <cstddef> // size_t
|
||||||
#include <cstdint> // uint8_t, uint16_t, uint32_t, uint64_t
|
#include <cstdint> // uint8_t, uint16_t, uint32_t, uint64_t
|
||||||
|
#include <cstdio> // snprintf
|
||||||
#include <cstring> // memcpy
|
#include <cstring> // memcpy
|
||||||
#include <iomanip> // setw, setfill
|
|
||||||
#include <ios> // hex
|
|
||||||
#include <iterator> // back_inserter
|
#include <iterator> // back_inserter
|
||||||
#include <limits> // numeric_limits
|
#include <limits> // numeric_limits
|
||||||
#include <sstream> // stringstream
|
|
||||||
#include <string> // char_traits, string
|
#include <string> // char_traits, string
|
||||||
#include <utility> // make_pair, move
|
#include <utility> // make_pair, move
|
||||||
|
|
||||||
|
@ -1665,9 +1663,9 @@ class binary_reader
|
||||||
*/
|
*/
|
||||||
std::string get_token_string() const
|
std::string get_token_string() const
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
char cr[3];
|
||||||
ss << std::setw(2) << std::uppercase << std::setfill('0') << std::hex << current;
|
snprintf(cr, 3, "%.2X", current);
|
||||||
return ss.str();
|
return std::string{cr};
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -3,10 +3,8 @@
|
||||||
#include <clocale> // localeconv
|
#include <clocale> // localeconv
|
||||||
#include <cstddef> // size_t
|
#include <cstddef> // size_t
|
||||||
#include <cstdlib> // strtof, strtod, strtold, strtoll, strtoull
|
#include <cstdlib> // strtof, strtod, strtold, strtoll, strtoull
|
||||||
|
#include <cstdio> // snprintf
|
||||||
#include <initializer_list> // initializer_list
|
#include <initializer_list> // initializer_list
|
||||||
#include <ios> // hex, uppercase
|
|
||||||
#include <iomanip> // setw, setfill
|
|
||||||
#include <sstream> // stringstream
|
|
||||||
#include <string> // char_traits, string
|
#include <string> // char_traits, string
|
||||||
#include <vector> // vector
|
#include <vector> // vector
|
||||||
|
|
||||||
|
@ -1174,10 +1172,9 @@ scan_number_done:
|
||||||
if ('\x00' <= c and c <= '\x1F')
|
if ('\x00' <= c and c <= '\x1F')
|
||||||
{
|
{
|
||||||
// escape control characters
|
// escape control characters
|
||||||
std::stringstream ss;
|
char cs[9];
|
||||||
ss << "<U+" << std::setw(4) << std::uppercase << std::setfill('0')
|
snprintf(cs, 9, "<U+%.4X>", c);
|
||||||
<< std::hex << static_cast<int>(c) << ">";
|
result += cs;
|
||||||
result += ss.str();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -9,11 +9,8 @@
|
||||||
#include <cstddef> // size_t, ptrdiff_t
|
#include <cstddef> // size_t, ptrdiff_t
|
||||||
#include <cstdint> // uint8_t
|
#include <cstdint> // uint8_t
|
||||||
#include <cstdio> // snprintf
|
#include <cstdio> // snprintf
|
||||||
#include <iomanip> // setfill
|
|
||||||
#include <iterator> // next
|
|
||||||
#include <limits> // numeric_limits
|
#include <limits> // numeric_limits
|
||||||
#include <string> // string
|
#include <string> // string
|
||||||
#include <sstream> // stringstream
|
|
||||||
#include <type_traits> // is_same
|
#include <type_traits> // is_same
|
||||||
|
|
||||||
#include <nlohmann/detail/exceptions.hpp>
|
#include <nlohmann/detail/exceptions.hpp>
|
||||||
|
@ -389,9 +386,9 @@ class serializer
|
||||||
|
|
||||||
case UTF8_REJECT: // decode found invalid UTF-8 byte
|
case UTF8_REJECT: // decode found invalid UTF-8 byte
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::string sn(3, '\0');
|
||||||
ss << std::setw(2) << std::uppercase << std::setfill('0') << std::hex << static_cast<int>(byte);
|
snprintf(&sn[0], sn.size(), "%.2X", byte);
|
||||||
JSON_THROW(type_error::create(316, "invalid UTF-8 byte at index " + std::to_string(i) + ": 0x" + ss.str()));
|
JSON_THROW(type_error::create(316, "invalid UTF-8 byte at index " + std::to_string(i) + ": 0x" + sn));
|
||||||
}
|
}
|
||||||
|
|
||||||
default: // decode found yet incomplete multi-byte code point
|
default: // decode found yet incomplete multi-byte code point
|
||||||
|
@ -417,9 +414,9 @@ class serializer
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// we finish reading, but do not accept: string was incomplete
|
// we finish reading, but do not accept: string was incomplete
|
||||||
std::stringstream ss;
|
std::string sn(3,'\0');
|
||||||
ss << std::setw(2) << std::uppercase << std::setfill('0') << std::hex << static_cast<int>(static_cast<uint8_t>(s.back()));
|
snprintf(&sn[0], sn.size(), "%.2X", static_cast<uint8_t>(s.back()));
|
||||||
JSON_THROW(type_error::create(316, "incomplete UTF-8 string; last byte: 0x" + ss.str()));
|
JSON_THROW(type_error::create(316, "incomplete UTF-8 string; last byte: 0x" + sn));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue