Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
json
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
json
Commits
9e89c2fd
Unverified
Commit
9e89c2fd
authored
Jan 04, 2022
by
Niels Lohmann
Committed by
GitHub
Jan 04, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
♻
remove stringstream (#3244)
parent
78ddf2bc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
14 deletions
+32
-14
include/nlohmann/detail/output/serializer.hpp
include/nlohmann/detail/output/serializer.hpp
+16
-7
single_include/nlohmann/json.hpp
single_include/nlohmann/json.hpp
+16
-7
No files found.
include/nlohmann/detail/output/serializer.hpp
View file @
9e89c2fd
...
...
@@ -10,7 +10,6 @@
#include <limits> // numeric_limits
#include <string> // string, char_traits
#include <iomanip> // setfill, setw
#include <sstream> // stringstream
#include <type_traits> // is_same
#include <utility> // move
...
...
@@ -501,9 +500,7 @@ class serializer
{
case
error_handler_t
:
:
strict
:
{
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
()));
JSON_THROW
(
type_error
::
create
(
316
,
"invalid UTF-8 byte at index "
+
std
::
to_string
(
i
)
+
": 0x"
+
hex_bytes
(
byte
|
0
),
BasicJsonType
()));
}
case
error_handler_t
:
:
ignore
:
...
...
@@ -595,9 +592,7 @@ class serializer
{
case
error_handler_t
:
:
strict
:
{
std
::
stringstream
ss
;
ss
<<
std
::
uppercase
<<
std
::
setfill
(
'0'
)
<<
std
::
setw
(
2
)
<<
std
::
hex
<<
(
static_cast
<
std
::
uint8_t
>
(
s
.
back
())
|
0
);
JSON_THROW
(
type_error
::
create
(
316
,
"incomplete UTF-8 string; last byte: 0x"
+
ss
.
str
(),
BasicJsonType
()));
JSON_THROW
(
type_error
::
create
(
316
,
"incomplete UTF-8 string; last byte: 0x"
+
hex_bytes
(
static_cast
<
std
::
uint8_t
>
(
s
.
back
()
|
0
)),
BasicJsonType
()));
}
case
error_handler_t
:
:
ignore
:
...
...
@@ -664,6 +659,20 @@ class serializer
}
}
/*!
* @brief convert a byte to a uppercase hex representation
* @param[in] byte byte to represent
* @return representation ("00".."FF")
*/
inline
std
::
string
hex_bytes
(
std
::
uint8_t
byte
)
{
std
::
string
result
=
"FF"
;
constexpr
const
char
*
nibble_to_hex
=
"0123456789ABCDEF"
;
result
[
0
]
=
nibble_to_hex
[
byte
/
16
];
result
[
1
]
=
nibble_to_hex
[
byte
%
16
];
return
result
;
}
// templates to avoid warnings about useless casts
template
<
typename
NumberType
,
enable_if_t
<
std
::
is_signed
<
NumberType
>
::
value
,
int
>
=
0
>
bool
is_negative_number
(
NumberType
x
)
...
...
single_include/nlohmann/json.hpp
View file @
9e89c2fd
...
...
@@ -14935,7 +14935,6 @@ class binary_writer
#include <limits> // numeric_limits
#include <string> // string, char_traits
#include <iomanip> // setfill, setw
#include <sstream> // stringstream
#include <type_traits> // is_same
#include <utility> // move
...
...
@@ -16544,9 +16543,7 @@ class serializer
{
case error_handler_t::strict:
{
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
()));
JSON_THROW(type_error::create(316, "invalid UTF-8 byte at index " + std::to_string(i) + ": 0x" + hex_bytes(byte | 0), BasicJsonType()));
}
case error_handler_t::ignore:
...
...
@@ -16638,9 +16635,7 @@ class serializer
{
case error_handler_t::strict:
{
std
::
stringstream
ss
;
ss
<<
std
::
uppercase
<<
std
::
setfill
(
'0'
)
<<
std
::
setw
(
2
)
<<
std
::
hex
<<
(
static_cast
<
std
::
uint8_t
>
(
s
.
back
())
|
0
);
JSON_THROW
(
type_error
::
create
(
316
,
"incomplete UTF-8 string; last byte: 0x"
+
ss
.
str
(),
BasicJsonType
()));
JSON_THROW(type_error::create(316, "incomplete UTF-8 string; last byte: 0x" + hex_bytes(static_cast<std::uint8_t>(s.back() | 0)), BasicJsonType()));
}
case error_handler_t::ignore:
...
...
@@ -16707,6 +16702,20 @@ class serializer
}
}
/*!
* @brief convert a byte to a uppercase hex representation
* @param[in] byte byte to represent
* @return representation ("00".."FF")
*/
inline std::string hex_bytes(std::uint8_t byte)
{
std::string result = "FF";
constexpr const char* nibble_to_hex = "0123456789ABCDEF";
result[0] = nibble_to_hex[byte / 16];
result[1] = nibble_to_hex[byte % 16];
return result;
}
// templates to avoid warnings about useless casts
template <typename NumberType, enable_if_t<std::is_signed<NumberType>::value, int> = 0>
bool is_negative_number(NumberType x)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment