1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

MDEV-11298 Split Item_func_hex::val_str_ascii() into virtual methods in Type_handler

This commit is contained in:
Alexander Barkov
2016-12-01 11:57:01 +04:00
parent 9185f8d4a7
commit 69f80e5ecf
6 changed files with 164 additions and 49 deletions

View File

@ -130,6 +130,61 @@ bool String::set_int(longlong num, bool unsigned_flag, CHARSET_INFO *cs)
return FALSE;
}
// Convert a number into its HEX representation
bool String::set_hex(ulonglong num)
{
char *n_end;
if (alloc(65) || !(n_end= longlong2str(num, Ptr, 16)))
return true;
length((uint32) (n_end - Ptr));
set_charset(&my_charset_latin1);
return false;
}
/**
Append a hex representation of the byte "value" into "to".
Note:
"to" is incremented for the caller by two bytes. It's passed by reference!
So it resembles a macros, hence capital letters in the name.
*/
static inline void APPEND_HEX(char *&to, uchar value)
{
*to++= _dig_vec_upper[((uchar) value) >> 4];
*to++= _dig_vec_upper[((uchar) value) & 0x0F];
}
void String::qs_append_hex(const char *str, uint32 len)
{
const char *str_end= str + len;
for (char *to= Ptr + str_length ; str < str_end; str++)
APPEND_HEX(to, (uchar) *str);
str_length+= len * 2;
}
// Convert a string to its HEX representation
bool String::set_hex(const char *str, uint32 len)
{
/*
Safety: cut the source string if "len" is too large.
Note, alloc() can allocate some more space than requested, due to:
- ALIGN_SIZE
- one extra byte for a null terminator
So cut the source string to 0x7FFFFFF0 rather than 0x7FFFFFFE.
*/
set_if_smaller(len, 0x7FFFFFF0);
if (alloc(len * 2))
return true;
length(0);
qs_append_hex(str, len);
set_charset(&my_charset_latin1);
return false;
}
bool String::set_real(double num,uint decimals, CHARSET_INFO *cs)
{
char buff[FLOATING_POINT_BUFFER];
@ -960,8 +1015,7 @@ my_copy_with_hex_escaping(CHARSET_INFO *cs,
break; /* purecov: inspected */
*dst++= '\\';
*dst++= 'x';
*dst++= _dig_vec_upper[((unsigned char) *src) >> 4];
*dst++= _dig_vec_upper[((unsigned char) *src) & 15];
APPEND_HEX(dst, (uchar) *src);
src++;
dstlen-= 4;
}
@ -1146,8 +1200,7 @@ uint convert_to_printable(char *to, size_t to_len,
break;
*t++= '\\';
*t++= 'x';
*t++= _dig_vec_upper[((unsigned char) *f) >> 4];
*t++= _dig_vec_upper[((unsigned char) *f) & 0x0F];
APPEND_HEX(t, *f);
}
if (t_end - t >= 3) // '...'
dots= t;