summaryrefslogtreecommitdiff
path: root/mysys/string.c
diff options
context:
space:
mode:
authorunknown <sanja@montyprogram.com>2012-09-28 14:01:17 +0300
committerunknown <sanja@montyprogram.com>2012-09-28 14:01:17 +0300
commit7327cd9717f0b98499f0f5b19c84e5e3e48241df (patch)
treef652710ef9b4e4f9709728f1bca3b01ee52fdfc9 /mysys/string.c
parent4db207d56da2f832d8bc6cc1d935a17efcbc1035 (diff)
downloadmariadb-git-7327cd9717f0b98499f0f5b19c84e5e3e48241df.tar.gz
MDEV-377 Name support for dynamic columns
MDEV-127 Optimization of memory allocation MDEV-483 Make column_check function which cheсks dynamic columns integrit JSON conversion function
Diffstat (limited to 'mysys/string.c')
-rw-r--r--mysys/string.c102
1 files changed, 102 insertions, 0 deletions
diff --git a/mysys/string.c b/mysys/string.c
index d9791341c60..0cf8f939260 100644
--- a/mysys/string.c
+++ b/mysys/string.c
@@ -175,6 +175,34 @@ my_bool dynstr_append_os_quoted(DYNAMIC_STRING *str, const char *append, ...)
return ret;
}
+my_bool dynstr_append_quoted(DYNAMIC_STRING *str,
+ const char *append, size_t len)
+{
+ uint additional= (str->alloc_increment ? str->alloc_increment : 10);
+ uint lim= additional;
+ uint i;
+ if (dynstr_realloc(str, len + additional + 2))
+ return TRUE;
+ str->str[str->length++]= '"';
+ for (i= 0; i < len; i++)
+ {
+ register char c= append[i];
+ if (c == '"' || c == '\\')
+ {
+ if (!lim)
+ {
+ if (dynstr_realloc(str, additional))
+ return TRUE;
+ lim= additional;
+ }
+ lim--;
+ str->str[str->length++]= '\\';
+ }
+ str->str[str->length++]= c;
+ }
+ str->str[str->length++]= '"';
+ return FALSE;
+}
void dynstr_free(DYNAMIC_STRING *str)
{
@@ -193,3 +221,77 @@ void dynstr_reassociate(DYNAMIC_STRING *str, char **ptr, size_t *length,
*alloc_length= str->max_length;
str->str=0;
}
+
+
+/*
+ copy a string from one character set to another
+
+ SYNOPSIS
+ copy_and_convert()
+ to Store result here
+ to_cs Character set of result string
+ from Copy from here
+ from_length Length of from string
+ from_cs From character set
+
+ NOTES
+ 'to' must be big enough as form_length * to_cs->mbmaxlen
+
+ RETURN
+ length of bytes copied to 'to'
+*/
+
+uint32
+copy_and_convert_extended(char *to, uint32 to_length, CHARSET_INFO *to_cs,
+ const char *from, uint32 from_length,
+ CHARSET_INFO *from_cs,
+ uint *errors)
+{
+ int cnvres;
+ my_wc_t wc;
+ const uchar *from_end= (const uchar*) from+from_length;
+ char *to_start= to;
+ uchar *to_end= (uchar*) to+to_length;
+ my_charset_conv_mb_wc mb_wc= from_cs->cset->mb_wc;
+ my_charset_conv_wc_mb wc_mb= to_cs->cset->wc_mb;
+ uint error_count= 0;
+
+ while (1)
+ {
+ if ((cnvres= (*mb_wc)(from_cs, &wc, (uchar*) from,
+ from_end)) > 0)
+ from+= cnvres;
+ else if (cnvres == MY_CS_ILSEQ)
+ {
+ error_count++;
+ from++;
+ wc= '?';
+ }
+ else if (cnvres > MY_CS_TOOSMALL)
+ {
+ /*
+ A correct multibyte sequence detected
+ But it doesn't have Unicode mapping.
+ */
+ error_count++;
+ from+= (-cnvres);
+ wc= '?';
+ }
+ else
+ break; // Not enough characters
+
+outp:
+ if ((cnvres= (*wc_mb)(to_cs, wc, (uchar*) to, to_end)) > 0)
+ to+= cnvres;
+ else if (cnvres == MY_CS_ILUNI && wc != '?')
+ {
+ error_count++;
+ wc= '?';
+ goto outp;
+ }
+ else
+ break;
+ }
+ *errors= error_count;
+ return (uint32) (to - to_start);
+}