summaryrefslogtreecommitdiff
path: root/src/mongo/util/hex.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/util/hex.h')
-rw-r--r--src/mongo/util/hex.h86
1 files changed, 43 insertions, 43 deletions
diff --git a/src/mongo/util/hex.h b/src/mongo/util/hex.h
index d9724986008..802d6b13737 100644
--- a/src/mongo/util/hex.h
+++ b/src/mongo/util/hex.h
@@ -35,59 +35,59 @@
#include "mongo/bson/util/builder.h"
namespace mongo {
- //can't use hex namespace because it conflicts with hex iostream function
- inline int fromHex( char c ) {
- if ( '0' <= c && c <= '9' )
- return c - '0';
- if ( 'a' <= c && c <= 'f' )
- return c - 'a' + 10;
- if ( 'A' <= c && c <= 'F' )
- return c - 'A' + 10;
- verify( false );
- return 0xff;
- }
- inline char fromHex( const char *c ) {
- return (char)(( fromHex( c[ 0 ] ) << 4 ) | fromHex( c[ 1 ] ));
- }
- inline char fromHex( StringData c ) {
- return (char)(( fromHex( c[ 0 ] ) << 4 ) | fromHex( c[ 1 ] ));
- }
-
- inline std::string toHex(const void* inRaw, int len) {
- static const char hexchars[] = "0123456789ABCDEF";
+// can't use hex namespace because it conflicts with hex iostream function
+inline int fromHex(char c) {
+ if ('0' <= c && c <= '9')
+ return c - '0';
+ if ('a' <= c && c <= 'f')
+ return c - 'a' + 10;
+ if ('A' <= c && c <= 'F')
+ return c - 'A' + 10;
+ verify(false);
+ return 0xff;
+}
+inline char fromHex(const char* c) {
+ return (char)((fromHex(c[0]) << 4) | fromHex(c[1]));
+}
+inline char fromHex(StringData c) {
+ return (char)((fromHex(c[0]) << 4) | fromHex(c[1]));
+}
- 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)];
+inline std::string toHex(const void* inRaw, int len) {
+ static const char hexchars[] = "0123456789ABCDEF";
- out << hi << lo;
- }
+ 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)];
- return out.str();
+ out << hi << lo;
}
- template <typename T> std::string integerToHex(T val);
+ return out.str();
+}
- inline std::string toHexLower(const void* inRaw, int len) {
- static const char hexchars[] = "0123456789abcdef";
+template <typename T>
+std::string integerToHex(T val);
- 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)];
+inline std::string toHexLower(const void* inRaw, int len) {
+ static const char hexchars[] = "0123456789abcdef";
- out << hi << lo;
- }
+ 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)];
- return out.str();
+ out << hi << lo;
}
- /* @return a dump of the buffer as hex byte ascii output */
- std::string hexdump(const char *data, unsigned len);
+ return out.str();
+}
+/* @return a dump of the buffer as hex byte ascii output */
+std::string hexdump(const char* data, unsigned len);
}