summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bson/oid.h2
-rw-r--r--db/jsobj.cpp2
-rw-r--r--util/hex.h16
3 files changed, 18 insertions, 2 deletions
diff --git a/bson/oid.h b/bson/oid.h
index ed671378bbf..c1bf34d9d58 100644
--- a/bson/oid.h
+++ b/bson/oid.h
@@ -58,7 +58,7 @@ namespace mongo {
/** The object ID output as 24 hex digits. */
string str() const {
- return toHex(data, 12);
+ return toHexLower(data, 12);
}
string toString() const { return str(); }
diff --git a/db/jsobj.cpp b/db/jsobj.cpp
index 41270dac483..e5745867375 100644
--- a/db/jsobj.cpp
+++ b/db/jsobj.cpp
@@ -80,7 +80,7 @@ namespace mongo {
if ( *i >= 0 && *i <= 0x1f ) {
//TODO: these should be utf16 code-units not bytes
char c = *i;
- ret << "\\u00" << toHex(&c, 1);
+ ret << "\\u00" << toHexLower(&c, 1);
} else {
ret << *i;
}
diff --git a/util/hex.h b/util/hex.h
index 2fa7c41dd77..45a08f46d0a 100644
--- a/util/hex.h
+++ b/util/hex.h
@@ -48,4 +48,20 @@ namespace mongo {
return out.str();
}
+
+ inline string toHexLower(const void* inRaw, int len){
+ static const char hexchars[] = "0123456789abcdef";
+
+ StringBuilder out;
+ const char* in = reinterpret_cast<const char*>(inRaw);
+ for (int i=0; i<len; ++i){
+ char c = in[i];
+ char hi = hexchars[(c & 0xF0) >> 4];
+ char lo = hexchars[(c & 0x0F)];
+
+ out << hi << lo;
+ }
+
+ return out.str();
+ }
}