Skip to content

Commit 03b770f

Browse files
authored
Save the flags of the stream
Changing the stream to `std::hex` mode should only affect the current character; otherwise printing some msgpack with a list like this: `[123, "string\\u0003", 123]` (123 decimal) ends up printing `[123, "string\\u0003", 7b]`, as `std::hex` is sticky.
1 parent 1df97bc commit 03b770f

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

include/msgpack/v1/object.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,9 @@ inline std::ostream& operator<< (std::ostream& s, const msgpack::object& o)
802802
default: {
803803
unsigned int code = static_cast<unsigned int>(c);
804804
if (code < 0x20 || code == 0x7f) {
805+
std::ios::fmtflags flags(s.flags());
805806
s << "\\u" << std::hex << std::setw(4) << std::setfill('0') << (code & 0xff);
807+
s.flags(flags);
806808
}
807809
else {
808810
s << c;

0 commit comments

Comments
 (0)