22 #include "mongo/base/string_data.h"
23 #include "mongo/bson/util/builder.h"
27 inline int fromHex(
char c) {
28 if (
'0' <= c && c <=
'9')
30 if (
'a' <= c && c <=
'f')
32 if (
'A' <= c && c <=
'F')
37 inline char fromHex(
const char* c) {
38 return (
char)((fromHex(c[0]) << 4) | fromHex(c[1]));
40 inline char fromHex(
const StringData& c) {
41 return (
char)((fromHex(c[0]) << 4) | fromHex(c[1]));
44 inline std::string toHex(
const void* inRaw,
int len) {
45 static const char hexchars[] =
"0123456789ABCDEF";
48 const char* in =
reinterpret_cast<const char*
>(inRaw);
49 for (
int i = 0; i < len; ++i) {
51 char hi = hexchars[(c & 0xF0) >> 4];
52 char lo = hexchars[(c & 0x0F)];
61 std::string integerToHex(T val);
63 inline std::string toHexLower(
const void* inRaw,
int len) {
64 static const char hexchars[] =
"0123456789abcdef";
67 const char* in =
reinterpret_cast<const char*
>(inRaw);
68 for (
int i = 0; i < len; ++i) {
70 char hi = hexchars[(c & 0xF0) >> 4];
71 char lo = hexchars[(c & 0x0F)];
Utility functions for parsing numbers from strings.
Definition: compare_numbers.h:20