~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/util/convert.cc

  • Committer: Padraig O'Sullivan
  • Date: 2009-07-30 02:39:13 UTC
  • mto: (1115.3.11 captain)
  • mto: This revision was merged to the branch mainline in revision 1121.
  • Revision ID: osullivan.padraig@gmail.com-20090730023913-o2zuocp32l6btnc2
Removing references to MY_BITMAP throughout the code base and updating calls
to MyBitmap in various places to use the new interface.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
20
 
21
 
#include "config.h"
22
 
 
23
21
#include <drizzled/util/convert.h>
24
 
#include <string>
25
 
#include <iomanip>
26
 
#include <sstream>
27
 
 
28
 
using namespace std;
29
 
 
30
 
namespace drizzled
31
 
{
32
22
 
33
23
uint64_t drizzled_string_to_hex(char *to, const char *from, uint64_t from_size)
34
24
{
45
35
 
46
36
  return from_size * 2;
47
37
}
48
 
 
49
 
static inline char hex_char_value(char c)
50
 
{
51
 
  if (c >= '0' && c <= '9')
52
 
    return c - '0';
53
 
  else if (c >= 'A' && c <= 'F')
54
 
    return c - 'A' + 10;
55
 
  else if (c >= 'a' && c <= 'f')
56
 
    return c - 'a' + 10;
57
 
  return 0;
58
 
}
59
 
 
60
 
void drizzled_hex_to_string(char *to, const char *from, uint64_t from_size)
61
 
{
62
 
  const char *from_end = from + from_size;
63
 
 
64
 
  while (from != from_end)
65
 
  {
66
 
    *to= hex_char_value(*from++) << 4;
67
 
    if (from != from_end)
68
 
      *to++|= hex_char_value(*from++);
69
 
  }
70
 
}
71
 
 
72
 
void bytesToHexdumpFormat(string &to, const unsigned char *from, size_t from_length)
73
 
{
74
 
  static const char hex_map[]= "0123456789abcdef";
75
 
  unsigned int x, y;
76
 
  ostringstream line_number;
77
 
 
78
 
  for (x= 0; x < from_length; x+= 16)
79
 
  {
80
 
    line_number << setfill('0') << setw(6);
81
 
    line_number << x;
82
 
    to.append(line_number.str());
83
 
    to.append(": ", 2);
84
 
 
85
 
    for (y= 0; y < 16; y++)
86
 
    {
87
 
      if ((x + y) < from_length)
88
 
      {
89
 
        to.push_back(hex_map[(from[x+y]) >> 4]);
90
 
        to.push_back(hex_map[(from[x+y]) & 0xF]);
91
 
        to.push_back(' ');
92
 
      }
93
 
      else
94
 
        to.append("   ");
95
 
    }
96
 
    to.push_back(' ');
97
 
    for (y= 0; y < 16; y++)
98
 
    {
99
 
      if ((x + y) < from_length)
100
 
        to.push_back(isprint(from[x + y]) ? from[x + y] : '.');
101
 
    }
102
 
    to.push_back('\n');
103
 
    line_number.str("");
104
 
  }
105
 
}
106
 
 
107
 
} /* namespace drizzled */