1
/* - mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2009 Sun Microsystems, Inc.
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
#include <drizzled/util/convert.h>
33
uint64_t drizzled_string_to_hex(char *to, const char *from, uint64_t from_size)
35
static const char hex_map[]= "0123456789ABCDEF";
38
for (from_end= from + from_size; from != from_end; from++)
40
*to++= hex_map[((unsigned char) *from) >> 4];
41
*to++= hex_map[((unsigned char) *from) & 0xF];
49
static inline char hex_char_value(char c)
51
if (c >= '0' && c <= '9')
53
else if (c >= 'A' && c <= 'F')
55
else if (c >= 'a' && c <= 'f')
60
void drizzled_hex_to_string(char *to, const char *from, uint64_t from_size)
62
const char *from_end = from + from_size;
64
while (from != from_end)
66
*to= hex_char_value(*from++) << 4;
68
*to++|= hex_char_value(*from++);
72
void bytesToHexdumpFormat(string &to, const unsigned char *from, size_t from_length)
74
static const char hex_map[]= "0123456789abcdef";
76
ostringstream line_number;
78
for (x= 0; x < from_length; x+= 16)
80
line_number << setfill('0') << setw(6);
82
to.append(line_number.str());
85
for (y= 0; y < 16; y++)
87
if ((x + y) < from_length)
89
to.push_back(hex_map[(from[x+y]) >> 4]);
90
to.push_back(hex_map[(from[x+y]) & 0xF]);
97
for (y= 0; y < 16; y++)
99
if ((x + y) < from_length)
100
to.push_back(isprint(from[x + y]) ? from[x + y] : '.');
107
} /* namespace drizzled */