Commit 79914d30 authored by unknown's avatar unknown

thread charset related improvements

parent 05eb29d5
...@@ -93,18 +93,36 @@ bool String::realloc(uint32 alloc_length) ...@@ -93,18 +93,36 @@ bool String::realloc(uint32 alloc_length)
bool String::set(longlong num, CHARSET_INFO *cs) bool String::set(longlong num, CHARSET_INFO *cs)
{ {
if (alloc(21)) uint l=20*cs->mbmaxlen+1;
if (alloc(l))
return TRUE; return TRUE;
str_length=(uint32) (longlong10_to_str(num,Ptr,-10)-Ptr); if (cs->snprintf == my_snprintf_8bit)
{
str_length=(uint32) (longlong10_to_str(num,Ptr,-10)-Ptr);
}
else
{
str_length=cs->snprintf(cs,Ptr,l,"%d",num);
}
str_charset=cs; str_charset=cs;
return FALSE; return FALSE;
} }
bool String::set(ulonglong num, CHARSET_INFO *cs) bool String::set(ulonglong num, CHARSET_INFO *cs)
{ {
if (alloc(21)) uint l=20*cs->mbmaxlen+1;
if (alloc(l))
return TRUE; return TRUE;
str_length=(uint32) (longlong10_to_str(num,Ptr,10)-Ptr); if (cs->snprintf == my_snprintf_8bit)
{
str_length=(uint32) (longlong10_to_str(num,Ptr,10)-Ptr);
}
else
{
str_length=cs->snprintf(cs,Ptr,l,"%d",num);
}
str_charset=cs; str_charset=cs;
return FALSE; return FALSE;
} }
...@@ -117,14 +135,14 @@ bool String::set(double num,uint decimals, CHARSET_INFO *cs) ...@@ -117,14 +135,14 @@ bool String::set(double num,uint decimals, CHARSET_INFO *cs)
if (decimals >= NOT_FIXED_DEC) if (decimals >= NOT_FIXED_DEC)
{ {
sprintf(buff,"%.14g",num); // Enough for a DATETIME sprintf(buff,"%.14g",num); // Enough for a DATETIME
return copy(buff, (uint32) strlen(buff), my_charset_latin1); return copy(buff, (uint32) strlen(buff), my_charset_latin1, cs);
} }
#ifdef HAVE_FCONVERT #ifdef HAVE_FCONVERT
int decpt,sign; int decpt,sign;
char *pos,*to; char *pos,*to;
VOID(fconvert(num,(int) decimals,&decpt,&sign,buff+1)); VOID(fconvert(num,(int) decimals,&decpt,&sign,buff+1));
if (!my_isdigit(system_charset_info, buff[1])) if (!my_isdigit(my_charset_latin1, buff[1]))
{ // Nan or Inf { // Nan or Inf
pos=buff+1; pos=buff+1;
if (sign) if (sign)
...@@ -132,7 +150,7 @@ bool String::set(double num,uint decimals, CHARSET_INFO *cs) ...@@ -132,7 +150,7 @@ bool String::set(double num,uint decimals, CHARSET_INFO *cs)
buff[0]='-'; buff[0]='-';
pos=buff; pos=buff;
} }
return copy(pos,(uint32) strlen(pos)); return copy(pos,(uint32) strlen(pos), my_charset_latin1, cs);
} }
if (alloc((uint32) ((uint32) decpt+3+decimals))) if (alloc((uint32) ((uint32) decpt+3+decimals)))
return TRUE; return TRUE;
...@@ -182,7 +200,7 @@ bool String::set(double num,uint decimals, CHARSET_INFO *cs) ...@@ -182,7 +200,7 @@ bool String::set(double num,uint decimals, CHARSET_INFO *cs)
#else #else
sprintf(buff,"%.*f",(int) decimals,num); sprintf(buff,"%.*f",(int) decimals,num);
#endif #endif
return copy(buff,(uint32) strlen(buff), my_charset_latin1); return copy(buff,(uint32) strlen(buff), my_charset_latin1, cs);
#endif #endif
} }
...@@ -219,6 +237,55 @@ bool String::copy(const char *str,uint32 arg_length, CHARSET_INFO *cs) ...@@ -219,6 +237,55 @@ bool String::copy(const char *str,uint32 arg_length, CHARSET_INFO *cs)
return FALSE; return FALSE;
} }
/* Copy with charset convertion */
bool String::copy(const char *str,uint32 arg_length, CHARSET_INFO *from, CHARSET_INFO *to)
{
uint32 new_length=to->mbmaxlen*arg_length;
int cnvres;
my_wc_t wc;
const uchar *s=(const uchar *)str;
const uchar *se=s+arg_length;
uchar *d, *de;
if (alloc(new_length))
return TRUE;
d=(uchar *)Ptr;
de=d+new_length;
for (str_length=new_length ; s < se && d < de ; )
{
if ((cnvres=from->mb_wc(from,&wc,s,se)) > 0 )
{
s+=cnvres;
}
else if (cnvres==MY_CS_ILSEQ)
{
s++;
wc='?';
}
else
break;
outp:
if((cnvres=to->wc_mb(to,wc,d,de)) >0 )
{
d+=cnvres;
}
else if (cnvres==MY_CS_ILUNI && wc!='?')
{
wc='?';
goto outp;
}
else
break;
}
Ptr[new_length]=0;
length((uint32) (d-(uchar *)Ptr));
str_charset=to;
return FALSE;
}
/* This is used by mysql.cc */ /* This is used by mysql.cc */
bool String::fill(uint32 max_length,char fill_char) bool String::fill(uint32 max_length,char fill_char)
......
...@@ -179,6 +179,7 @@ class String ...@@ -179,6 +179,7 @@ class String
bool copy(); // Alloc string if not alloced bool copy(); // Alloc string if not alloced
bool copy(const String &s); // Allocate new string bool copy(const String &s); // Allocate new string
bool copy(const char *s,uint32 arg_length, CHARSET_INFO *cs); // Allocate new string bool copy(const char *s,uint32 arg_length, CHARSET_INFO *cs); // Allocate new string
bool copy(const char*s,uint32 arg_length, CHARSET_INFO *csfrom, CHARSET_INFO *csto);
bool append(const String &s); bool append(const String &s);
bool append(const char *s,uint32 arg_length=0); bool append(const char *s,uint32 arg_length=0);
bool append(IO_CACHE* file, uint32 arg_length); bool append(IO_CACHE* file, uint32 arg_length);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment