diff options
author | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2018-09-06 11:10:24 -0400 |
---|---|---|
committer | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2018-09-06 11:10:24 -0400 |
commit | dfca02c17d430b7b983157154055a58939b22372 (patch) | |
tree | 5b30c3eaa220760c79d1af8fb53755fe0a80fad9 | |
parent | fb46b7f5a9fbb6b9573ab25dc4f9ad48dfbbc032 (diff) | |
download | mongo-dfca02c17d430b7b983157154055a58939b22372.tar.gz |
SERVER-36576 Restore ostream formatters after change
-rw-r--r-- | src/mongo/bson/bsonelement.cpp | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/mongo/bson/bsonelement.cpp b/src/mongo/bson/bsonelement.cpp index ba44d546370..42151c23b50 100644 --- a/src/mongo/bson/bsonelement.cpp +++ b/src/mongo/bson/bsonelement.cpp @@ -44,6 +44,7 @@ #include "mongo/util/hex.h" #include "mongo/util/log.h" #include "mongo/util/mongoutils/str.h" +#include "mongo/util/scopeguard.h" #include "mongo/util/string_map.h" #include "mongo/util/stringutils.h" #include "mongo/util/uuid.h" @@ -87,6 +88,8 @@ void BSONElement::jsonStringStream(JsonStringFormat format, case NumberDouble: if (number() >= -std::numeric_limits<double>::max() && number() <= std::numeric_limits<double>::max()) { + auto origPrecision = s.precision(); + auto guard = MakeGuard([&s, origPrecision]() { s.precision(origPrecision); }); s.precision(16); s << number(); } @@ -206,10 +209,22 @@ void BSONElement::jsonStringStream(JsonStringFormat format, s << "{ \"$binary\" : \""; base64::encode(s, reader.view(), len); - s << "\", \"$type\" : \"" << hex; + + auto origFill = s.fill(); + auto origFmtF = s.flags(); + auto origWidth = s.width(); + auto guard = MakeGuard([&s, origFill, origFmtF, origWidth] { + s.fill(origFill); + s.setf(origFmtF); + s.width(origWidth); + }); + + s.setf(std::ios_base::hex, std::ios_base::basefield); + + s << "\", \"$type\" : \""; s.width(2); s.fill('0'); - s << type << dec; + s << type; s << "\" }"; break; } |