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.
This commit is contained in:
Germán M. Bravo 2016-10-28 15:27:03 -05:00 committed by GitHub
parent 1df97bc37b
commit 03b770fdf2

View File

@ -802,7 +802,9 @@ inline std::ostream& operator<< (std::ostream& s, const msgpack::object& o)
default: {
unsigned int code = static_cast<unsigned int>(c);
if (code < 0x20 || code == 0x7f) {
std::ios::fmtflags flags(s.flags());
s << "\\u" << std::hex << std::setw(4) << std::setfill('0') << (code & 0xff);
s.flags(flags);
}
else {
s << c;