00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <config.h>
00021 #include <drizzled/item/bin_string.h>
00022
00023 namespace drizzled
00024 {
00025
00026
00027
00028
00029
00030
00031
00032 Item_bin_string::Item_bin_string(const char *str, uint32_t str_length)
00033 {
00034 const char *end= str + str_length - 1;
00035 unsigned char bits= 0;
00036 uint32_t power= 1;
00037
00038 max_length= (str_length + 7) >> 3;
00039 char *ptr= (char*) memory::sql_alloc(max_length + 1);
00040 if (!ptr)
00041 return;
00042 str_value.set(ptr, max_length, &my_charset_bin);
00043 ptr+= max_length - 1;
00044 ptr[1]= 0;
00045 for (; end >= str; end--)
00046 {
00047 if (power == 256)
00048 {
00049 power= 1;
00050 *ptr--= bits;
00051 bits= 0;
00052 }
00053 if (*end == '1')
00054 bits|= power;
00055 power<<= 1;
00056 }
00057 *ptr= (char) bits;
00058 collation.set(&my_charset_bin, DERIVATION_COERCIBLE);
00059 fixed= 1;
00060 }
00061
00062
00063 }