408
Escape string with backslashes (\)
411
escape_string_for_drizzle()
412
charset_info Charset of the strings
413
to Buffer for escaped string
414
to_length Length of destination buffer, or 0
415
from The string to escape
416
length The length of the string to escape
419
This escapes the contents of a string by adding backslashes before special
420
characters, and turning others into specific escape sequences, such as
421
turning newlines into \n and null bytes into \0.
424
To maintain compatibility with the old C API, to_length may be 0 to mean
428
(size_t) -1 The escaped string did not fit in the to buffer
429
# The length of the escaped string
432
size_t escape_string_for_drizzle(const CHARSET_INFO *charset_info,
433
char *to, size_t to_length,
434
const char *from, size_t length)
436
const char *to_start= to;
437
const char *end, *to_end=to_start + (to_length ? to_length-1 : 2*length);
438
bool overflow= false;
440
bool use_mb_flag= use_mb(charset_info);
442
for (end= from + length; from < end; from++)
447
if (use_mb_flag && (tmp_length= my_ismbchar(charset_info, from, end)))
449
if (to + tmp_length > to_end)
460
If the next character appears to begin a multi-byte character, we
461
escape that first byte of that apparent multi-byte character. (The
462
character just looks like a multi-byte character -- if it were actually
463
a multi-byte character, it would have been passed through in the test
466
Without this check, we can create a problem by converting an invalid
467
multi-byte character into a valid one. For example, 0xbf27 is not
468
a valid GBK character, but 0xbf5c is. (0x27 = ', 0x5c = \)
470
if (use_mb_flag && (tmp_length= my_mbcharlen(charset_info, *from)) > 1)
475
case 0: /* Must be escaped for 'mysql' */
478
case '\n': /* Must be escaped for logs */
490
case '"': /* Better safe than sorry */
493
case '\032': /* This gives problems on Win32 */
518
return overflow ? (size_t) -1 : (size_t) (to - to_start);
522
407
#ifdef BACKSLASH_MBTAIL
523
408
static CHARSET_INFO *fs_cset_cache= NULL;