Commit 95930f12 authored by bar@bar.mysql.r18.ru's avatar bar@bar.mysql.r18.ru

new string-to-number functions

parent 61141a30
...@@ -257,11 +257,11 @@ int my_wildcmp_mb(CHARSET_INFO *, ...@@ -257,11 +257,11 @@ int my_wildcmp_mb(CHARSET_INFO *,
#define my_strcasecmp(s, a, b) ((s)->strcasecmp((s), (a), (b))) #define my_strcasecmp(s, a, b) ((s)->strcasecmp((s), (a), (b)))
#define my_strncasecmp(s, a, b, l) ((s)->strncasecmp((s), (a), (b), (l))) #define my_strncasecmp(s, a, b, l) ((s)->strncasecmp((s), (a), (b), (l)))
#define my_strtol(s, a, b, c, d) ((s)->strtol((s),(a),(b),(c),(d))) #define my_strntol(s, a, b, c, d) ((s)->strntol((s),(a),(b),(c),(d)))
#define my_strtoul(s, a, b, c, d) ((s)->strtoul((s),(a),(b),(c),(d))) #define my_strntoul(s, a, b, c, d) ((s)->strntoul((s),(a),(b),(c),(d)))
#define my_strtoll(s, a, b, c, d) ((s)->strtoll((s),(a),(b),(c),(d))) #define my_strntoll(s, a, b, c, d) ((s)->strntoll((s),(a),(b),(c),(d)))
#define my_strtoull(s, a, b, c,d) ((s)->strtoull((s),(a),(b),(c),(d))) #define my_strntoull(s, a, b, c,d) ((s)->strntoull((s),(a),(b),(c),(d)))
#define my_strtod(s, a, b, c ) ((s)->strtod((s),(a),(b),(c))) #define my_strntod(s, a, b, c ) ((s)->strntod((s),(a),(b),(c)))
/* XXX: still need to take care of this one */ /* XXX: still need to take care of this one */
......
...@@ -921,8 +921,7 @@ void Field_decimal::sql_type(String &res) const ...@@ -921,8 +921,7 @@ void Field_decimal::sql_type(String &res) const
int Field_tiny::store(const char *from,uint len,CHARSET_INFO *cs) int Field_tiny::store(const char *from,uint len,CHARSET_INFO *cs)
{ {
String tmp_str(from,len,default_charset_info); long tmp= my_strntol(cs,from,len,(char **)NULL,10);
long tmp= strtol(tmp_str.c_ptr(),NULL,10);
int error= 0; int error= 0;
if (unsigned_flag) if (unsigned_flag)
...@@ -1116,8 +1115,7 @@ void Field_tiny::sql_type(String &res) const ...@@ -1116,8 +1115,7 @@ void Field_tiny::sql_type(String &res) const
int Field_short::store(const char *from,uint len,CHARSET_INFO *cs) int Field_short::store(const char *from,uint len,CHARSET_INFO *cs)
{ {
String tmp_str(from,len,default_charset_info); long tmp= my_strntol(cs,from,len,NULL,10);
long tmp= strtol(tmp_str.c_ptr(),NULL,10);
int error= 0; int error= 0;
if (unsigned_flag) if (unsigned_flag)
{ {
...@@ -1380,8 +1378,7 @@ void Field_short::sql_type(String &res) const ...@@ -1380,8 +1378,7 @@ void Field_short::sql_type(String &res) const
int Field_medium::store(const char *from,uint len,CHARSET_INFO *cs) int Field_medium::store(const char *from,uint len,CHARSET_INFO *cs)
{ {
String tmp_str(from,len,default_charset_info); long tmp= my_strntol(cs,from,len,NULL,10);
long tmp= strtol(tmp_str.c_ptr(),NULL,10);
int error= 0; int error= 0;
if (unsigned_flag) if (unsigned_flag)
...@@ -3097,8 +3094,7 @@ void Field_time::sql_type(String &res) const ...@@ -3097,8 +3094,7 @@ void Field_time::sql_type(String &res) const
int Field_year::store(const char *from, uint len,CHARSET_INFO *cs) int Field_year::store(const char *from, uint len,CHARSET_INFO *cs)
{ {
String tmp_str(from,len,default_charset_info); long nr= my_strntol(cs,from,len,NULL,10);
long nr= strtol(tmp_str.c_ptr(),NULL,10);
if (nr < 0 || nr >= 100 && nr <= 1900 || nr > 2155) if (nr < 0 || nr >= 100 && nr <= 1900 || nr > 2155)
{ {
......
...@@ -22,6 +22,26 @@ ...@@ -22,6 +22,26 @@
#include "m_string.h" #include "m_string.h"
#include "m_ctype.h" #include "m_ctype.h"
static uchar ctype_bin[] = {
0,
32, 32, 32, 32, 32, 32, 32, 32, 32, 40, 40, 40, 40, 40, 32, 32,
32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
72, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
132,132,132,132,132,132,132,132,132,132, 16, 16, 16, 16, 16, 16,
16,129,129,129,129,129,129, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 16, 16, 16, 16, 16,
16,130,130,130,130,130,130, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 16, 16, 16, 16, 32,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
72, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 16, 1, 1, 1, 1, 1, 1, 1, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 16, 2, 2, 2, 2, 2, 2, 2, 2
};
static int my_strnncoll_binary(CHARSET_INFO * cs __attribute__((unused)), static int my_strnncoll_binary(CHARSET_INFO * cs __attribute__((unused)),
const uchar *s, uint slen, const uchar *s, uint slen,
...@@ -242,7 +262,7 @@ static CHARSET_INFO my_charset_bin_st = ...@@ -242,7 +262,7 @@ static CHARSET_INFO my_charset_bin_st =
MY_CS_COMPILED|MY_CS_BINSORT,/* state */ MY_CS_COMPILED|MY_CS_BINSORT,/* state */
"binary", /* name */ "binary", /* name */
"", /* comment */ "", /* comment */
NULL, /* ctype */ ctype_bin, /* ctype */
NULL, /* to_lower */ NULL, /* to_lower */
NULL, /* to_upper */ NULL, /* to_upper */
NULL, /* sort_order */ NULL, /* sort_order */
......
...@@ -15,12 +15,13 @@ ...@@ -15,12 +15,13 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include <my_global.h> #include <my_global.h>
#include "my_sys.h"
#include "m_ctype.h"
#include "m_string.h" #include "m_string.h"
#include "m_ctype.h"
#include "my_sys.h" /* defines errno */
#include "stdarg.h" #include "stdarg.h"
#include "assert.h" #include "assert.h"
int my_strnxfrm_simple(CHARSET_INFO * cs, int my_strnxfrm_simple(CHARSET_INFO * cs,
uchar *dest, uint len, uchar *dest, uint len,
const uchar *src, uint srclen) const uchar *src, uint srclen)
...@@ -244,34 +245,468 @@ void my_hash_sort_simple(CHARSET_INFO *cs, ...@@ -244,34 +245,468 @@ void my_hash_sort_simple(CHARSET_INFO *cs,
} }
} }
long my_strntol_8bit(CHARSET_INFO *cs __attribute__((unused)),
const char *s, uint l, char **e, int base) #define MY_ERRNO(y)
long my_strntol_8bit(CHARSET_INFO *cs,
const char *nptr, uint l, char **endptr, int base)
{ {
return 0; int negative;
register ulong cutoff;
register unsigned int cutlim;
register ulong i;
register const char *s;
register unsigned char c;
const char *save, *e;
int overflow;
if (base < 0 || base == 1 || base > 36)
base = 10;
s = nptr;
e = nptr+l;
for ( ; s<e && my_isspace(cs, *s) ; s++);
if (s == e)
{
goto noconv;
}
/* Check for a sign. */
if (*s == '-')
{
negative = 1;
++s;
}
else if (*s == '+')
{
negative = 0;
++s;
}
else
negative = 0;
if (base == 16 && s[0] == '0' && (s[1]=='X' || s[1]=='x'))
s += 2;
if (base == 0)
{
if (*s == '0')
{
if (s[1]=='X' || s[1]=='x')
{
s += 2;
base = 16;
}
else
base = 8;
}
else
base = 10;
}
save = s;
cutoff = ((ulong)~0L) / (unsigned long int) base;
cutlim = (uint) (((ulong)~0L) % (unsigned long int) base);
overflow = 0;
i = 0;
for (c = *s; s != e; c = *++s)
{
if (c>='0' && c<='9')
c -= '0';
else if (c>='A' && c<='F')
c = c - 'A' + 10;
else if (c>='a' && c<='f')
c = c - 'a' + 10;
else
break;
if (c >= base)
break;
if (i > cutoff || (i == cutoff && c > cutlim))
overflow = 1;
else
{
i *= (ulong) base;
i += c;
}
}
if (s == save)
goto noconv;
if (endptr != NULL)
*endptr = (char *) s;
if (negative)
{
if (i > (ulong) LONG_MIN)
overflow = 1;
}
else if (i > (ulong) LONG_MAX)
overflow = 1;
if (overflow)
{
MY_ERRNO(ERANGE);
return negative ? LONG_MIN : LONG_MAX;
}
return (negative ? -((long) i) : (long) i);
noconv:
MY_ERRNO(EDOM);
if (endptr != NULL)
*endptr = (char *) nptr;
return 0L;
} }
ulong my_strntoul_8bit(CHARSET_INFO *cs __attribute__((unused)),
const char *s, uint l, char **e, int base) ulong my_strntoul_8bit(CHARSET_INFO *cs,
const char *nptr, uint l, char **endptr, int base)
{ {
return 0; int negative;
register ulong cutoff;
register unsigned int cutlim;
register ulong i;
register const char *s;
register unsigned char c;
const char *save, *e;
int overflow;
if (base < 0 || base == 1 || base > 36)
base = 10;
s = nptr;
e = nptr+l;
for( ; s<e && my_isspace(cs, *s); s++);
if (s==e)
{
goto noconv;
}
if (*s == '-')
{
negative = 1;
++s;
}
else if (*s == '+')
{
negative = 0;
++s;
}
else
negative = 0;
if (base == 16 && s[0] == '0' && (s[1]=='X' || s[1]=='x'))
s += 2;
if (base == 0)
{
if (*s == '0')
{
if (s[1]=='X' || s[1]=='x')
{
s += 2;
base = 16;
}
else
base = 8;
}
else
base = 10;
}
save = s;
cutoff = ((ulong)~0L) / (unsigned long int) base;
cutlim = (uint) (((ulong)~0L) % (unsigned long int) base);
overflow = 0;
i = 0;
for (c = *s; s != e; c = *++s)
{
if (c>='0' && c<='9')
c -= '0';
else if (c>='A' && c<='F')
c = c - 'A' + 10;
else if (c>='a' && c<='a')
c = c - 'a' + 10;
else
break;
if (c >= base)
break;
if (i > cutoff || (i == cutoff && c > cutlim))
overflow = 1;
else
{
i *= (ulong) base;
i += c;
}
}
if (s == save)
goto noconv;
if (endptr != NULL)
*endptr = (char *) s;
if (overflow)
{
MY_ERRNO(ERANGE);
return ((ulong)~0L);
}
return (negative ? -((long) i) : (long) i);
noconv:
MY_ERRNO(EDOM);
if (endptr != NULL)
*endptr = (char *) nptr;
return 0L;
} }
longlong my_strntoll_8bit(CHARSET_INFO *cs __attribute__((unused)), longlong my_strntoll_8bit(CHARSET_INFO *cs __attribute__((unused)),
const char *s, uint l, char **e, int base) const char *nptr, uint l, char **endptr, int base)
{ {
return 0; int negative;
register ulonglong cutoff;
register unsigned int cutlim;
register ulonglong i;
register const char *s, *e;
register unsigned char c;
const char *save;
int overflow;
if (base < 0 || base == 1 || base > 36)
base = 10;
s = nptr;
e = nptr+l;
for(; s<e && my_isspace(cs,*s); s++);
if (s == e)
{
goto noconv;
}
if (*s == '-')
{
negative = 1;
++s;
}
else if (*s == '+')
{
negative = 0;
++s;
}
else
negative = 0;
if (base == 16 && s[0] == '0' && (s[1]=='X'|| s[1]=='x'))
s += 2;
if (base == 0)
{
if (*s == '0')
{
if (s[1]=='X' || s[1]=='x')
{
s += 2;
base = 16;
}
else
base = 8;
}
else
base = 10;
}
save = s;
cutoff = (~(ulonglong) 0) / (unsigned long int) base;
cutlim = (uint) ((~(ulonglong) 0) % (unsigned long int) base);
overflow = 0;
i = 0;
for (c = *s; s != e; c = *++s)
{
if (c>='0' && c<='9')
c -= '0';
else if (c>='A' && c<='F')
c = c - 'A' + 10;
else if (c>='a' && c<='f')
c = c - 'a' + 10;
else
break;
if (c >= base)
break;
if (i > cutoff || (i == cutoff && c > cutlim))
overflow = 1;
else
{
i *= (ulonglong) base;
i += c;
}
}
if (s == save)
goto noconv;
if (endptr != NULL)
*endptr = (char *) s;
if (negative)
{
if (i > (ulonglong) LONGLONG_MIN)
overflow = 1;
}
else if (i > (ulonglong) LONGLONG_MAX)
overflow = 1;
if (overflow)
{
MY_ERRNO(ERANGE);
return negative ? LONGLONG_MIN : LONGLONG_MAX;
}
return (negative ? -((longlong) i) : (longlong) i);
noconv:
MY_ERRNO(EDOM);
if (endptr != NULL)
*endptr = (char *) nptr;
return 0L;
} }
ulonglong my_strntoull_8bit(CHARSET_INFO *cs __attribute__((unused)),
const char *s, uint l, char **e, int base) ulonglong my_strntoull_8bit(CHARSET_INFO *cs,
const char *nptr, uint l, char **endptr, int base)
{ {
return 0; int negative;
register ulonglong cutoff;
register unsigned int cutlim;
register ulonglong i;
register const char *s, *e;
register unsigned char c;
const char *save;
int overflow;
if (base < 0 || base == 1 || base > 36)
base = 10;
s = nptr;
e = nptr+l;
for(; s<e && my_isspace(cs,*s); s++);
if (s == e)
{
goto noconv;
}
if (*s == '-')
{
negative = 1;
++s;
}
else if (*s == '+')
{
negative = 0;
++s;
}
else
negative = 0;
if (base == 16 && s[0] == '0' && (s[1]=='X' || s[1]=='x'))
s += 2;
if (base == 0)
{
if (*s == '0')
{
if (s[1]=='X' || s[1]=='x')
{
s += 2;
base = 16;
}
else
base = 8;
}
else
base = 10;
}
save = s;
cutoff = (~(ulonglong) 0) / (unsigned long int) base;
cutlim = (uint) ((~(ulonglong) 0) % (unsigned long int) base);
overflow = 0;
i = 0;
for (c = *s; s != e; c = *++s)
{
if (c>='0' && c<='9')
c -= '0';
else if (c>='A' && c<='F')
c = c - 'A' + 10;
else if (c>='a' && c<='f')
c = c - 'a' + 10;
else
break;
if (c >= base)
break;
if (i > cutoff || (i == cutoff && c > cutlim))
overflow = 1;
else
{
i *= (ulonglong) base;
i += c;
}
}
if (s == save)
goto noconv;
if (endptr != NULL)
*endptr = (char *) s;
if (overflow)
{
MY_ERRNO(ERANGE);
return (~(ulonglong) 0);
}
return (negative ? -((longlong) i) : (longlong) i);
noconv:
MY_ERRNO(EDOM);
if (endptr != NULL)
*endptr = (char *) nptr;
return 0L;
} }
double my_strntod_8bit(CHARSET_INFO *cs __attribute__((unused)), double my_strntod_8bit(CHARSET_INFO *cs __attribute__((unused)),
const char *s, uint l, char **e) const char *s, uint l, char **e)
{ {
char buf[256];
double res;
if((l+1)>sizeof(buf))
{
if (e)
memcpy(*e,s,sizeof(s));
return 0; return 0;
}
strncpy(buf,s,l);
buf[l]='\0';
res=strtod(buf,e);
if (e)
memcpy(*e,*e-buf+s,sizeof(s));
return res;
} }
......
...@@ -19,7 +19,10 @@ ...@@ -19,7 +19,10 @@
/* Written by Alexander Barkov <bar@udm.net> */ /* Written by Alexander Barkov <bar@udm.net> */
#include <my_global.h> #include <my_global.h>
#include <m_ctype.h> #include "m_string.h"
#include "m_ctype.h"
#include "my_sys.h" /* defines errno */
#ifdef HAVE_CHARSET_utf8 #ifdef HAVE_CHARSET_utf8
#define HAVE_UNIDATA #define HAVE_UNIDATA
...@@ -2438,35 +2441,459 @@ static int my_snprintf_ucs2(CHARSET_INFO *cs __attribute__((unused)) ...@@ -2438,35 +2441,459 @@ static int my_snprintf_ucs2(CHARSET_INFO *cs __attribute__((unused))
return my_vsnprintf_ucs2(to, n, fmt, args); return my_vsnprintf_ucs2(to, n, fmt, args);
} }
#define MY_ERRNO(x)
static long my_strntol_ucs2(CHARSET_INFO *cs __attribute__((unused)), long my_strntol_ucs2(CHARSET_INFO *cs,
const char *s, uint l, char **e, int base) const char *nptr, uint l, char **endptr, int base)
{ {
return 0; int negative;
register ulong cutoff;
register unsigned int cutlim;
register ulong i;
register const char *s;
register unsigned char c;
const char *save, *e;
int overflow;
if (base < 0 || base == 1 || base > 36)
base = 10;
s = nptr;
e = nptr+l;
for ( ; s<e && my_isspace(cs, *s) ; s++);
if (s == e)
{
goto noconv;
}
/* Check for a sign. */
if (*s == '-')
{
negative = 1;
++s;
}
else if (*s == '+')
{
negative = 0;
++s;
}
else
negative = 0;
if (base == 16 && s[0] == '0' && my_toupper(cs,s[1]) == 'X')
s += 2;
if (base == 0)
{
if (*s == '0')
{
if (my_toupper(cs,s[1]) == 'X')
{
s += 2;
base = 16;
}
else
base = 8;
}
else
base = 10;
}
save = s;
cutoff = ((ulong)~0L) / (unsigned long int) base;
cutlim = (uint) (((ulong)~0L) % (unsigned long int) base);
overflow = 0;
i = 0;
for (c = *s; s != e; c = *++s)
{
if (my_isdigit(cs,c))
c -= '0';
else if (my_isalpha(cs,c))
c = my_toupper(cs,c) - 'A' + 10;
else
break;
if (c >= base)
break;
if (i > cutoff || (i == cutoff && c > cutlim))
overflow = 1;
else
{
i *= (ulong) base;
i += c;
}
}
if (s == save)
goto noconv;
if (endptr != NULL)
*endptr = (char *) s;
if (negative)
{
if (i > (ulong) LONG_MIN)
overflow = 1;
}
else if (i > (ulong) LONG_MAX)
overflow = 1;
if (overflow)
{
MY_ERRNO(ERANGE);
return negative ? LONG_MIN : LONG_MAX;
}
return (negative ? -((long) i) : (long) i);
noconv:
MY_ERRNO(EDOM);
if (endptr != NULL)
*endptr = (char *) nptr;
return 0L;
} }
static ulong my_strntoul_ucs2(CHARSET_INFO *cs __attribute__((unused)),
const char *s, uint l, char **e, int base) ulong my_strntoul_ucs2(CHARSET_INFO *cs,
const char *nptr, uint l, char **endptr, int base)
{ {
return 0; int negative;
register ulong cutoff;
register unsigned int cutlim;
register ulong i;
register const char *s;
register unsigned char c;
const char *save, *e;
int overflow;
if (base < 0 || base == 1 || base > 36)
base = 10;
s = nptr;
e = nptr+l;
for( ; s<e && my_isspace(cs, *s); s++);
if (s==e)
{
goto noconv;
}
if (*s == '-')
{
negative = 1;
++s;
}
else if (*s == '+')
{
negative = 0;
++s;
}
else
negative = 0;
if (base == 16 && s[0] == '0' && my_toupper(cs,s[1]) == 'X')
s += 2;
if (base == 0)
{
if (*s == '0')
{
if (my_toupper(cs,s[1]) == 'X')
{
s += 2;
base = 16;
}
else
base = 8;
}
else
base = 10;
}
save = s;
cutoff = ((ulong)~0L) / (unsigned long int) base;
cutlim = (uint) (((ulong)~0L) % (unsigned long int) base);
overflow = 0;
i = 0;
for (c = *s; s != e; c = *++s)
{
if (my_isdigit(cs,c))
c -= '0';
else if (my_isalpha(cs,c))
c = my_toupper(cs,c) - 'A' + 10;
else
break;
if (c >= base)
break;
if (i > cutoff || (i == cutoff && c > cutlim))
overflow = 1;
else
{
i *= (ulong) base;
i += c;
}
}
if (s == save)
goto noconv;
if (endptr != NULL)
*endptr = (char *) s;
if (overflow)
{
MY_ERRNO(ERANGE);
return ((ulong)~0L);
}
return (negative ? -((long) i) : (long) i);
noconv:
MY_ERRNO(EDOM);
if (endptr != NULL)
*endptr = (char *) nptr;
return 0L;
} }
static longlong my_strntoll_ucs2(CHARSET_INFO *cs __attribute__((unused)),
const char *s, uint l, char **e, int base) longlong my_strntoll_ucs2(CHARSET_INFO *cs __attribute__((unused)),
const char *nptr, uint l, char **endptr, int base)
{ {
return 0; int negative;
register ulonglong cutoff;
register unsigned int cutlim;
register ulonglong i;
register const char *s, *e;
register unsigned char c;
const char *save;
int overflow;
if (base < 0 || base == 1 || base > 36)
base = 10;
s = nptr;
e = nptr+l;
for(; s<e && my_isspace(cs,*s); s++);
if (s == e)
{
goto noconv;
}
if (*s == '-')
{
negative = 1;
++s;
}
else if (*s == '+')
{
negative = 0;
++s;
}
else
negative = 0;
if (base == 16 && s[0] == '0' && my_toupper(cs,s[1]) == 'X')
s += 2;
if (base == 0)
{
if (*s == '0')
{
if (my_toupper(cs,s[1]) == 'X')
{
s += 2;
base = 16;
}
else
base = 8;
}
else
base = 10;
}
save = s;
cutoff = (~(ulonglong) 0) / (unsigned long int) base;
cutlim = (uint) ((~(ulonglong) 0) % (unsigned long int) base);
overflow = 0;
i = 0;
for (c = *s; s != e; c = *++s)
{
if (my_isdigit(cs,c))
c -= '0';
else if (my_isalpha(cs,c))
c = my_toupper(cs,c) - 'A' + 10;
else
break;
if (c >= base)
break;
if (i > cutoff || (i == cutoff && c > cutlim))
overflow = 1;
else
{
i *= (ulonglong) base;
i += c;
}
}
if (s == save)
goto noconv;
if (endptr != NULL)
*endptr = (char *) s;
if (negative)
{
if (i > (ulonglong) LONGLONG_MIN)
overflow = 1;
}
else if (i > (ulonglong) LONGLONG_MAX)
overflow = 1;
if (overflow)
{
MY_ERRNO(ERANGE);
return negative ? LONGLONG_MIN : LONGLONG_MAX;
}
return (negative ? -((longlong) i) : (longlong) i);
noconv:
MY_ERRNO(EDOM);
if (endptr != NULL)
*endptr = (char *) nptr;
return 0L;
} }
static ulonglong my_strntoull_ucs2(CHARSET_INFO *cs __attribute__((unused)),
const char *s, uint l, char **e, int base) ulonglong my_strntoull_ucs2(CHARSET_INFO *cs,
const char *nptr, uint l, char **endptr, int base)
{ {
return 0; int negative;
register ulonglong cutoff;
register unsigned int cutlim;
register ulonglong i;
register const char *s, *e;
register unsigned char c;
const char *save;
int overflow;
if (base < 0 || base == 1 || base > 36)
base = 10;
s = nptr;
e = nptr+l;
for(; s<e && my_isspace(cs,*s); s++);
if (s == e)
{
goto noconv;
}
if (*s == '-')
{
negative = 1;
++s;
}
else if (*s == '+')
{
negative = 0;
++s;
}
else
negative = 0;
if (base == 16 && s[0] == '0' && my_toupper(cs,s[1]) == 'X')
s += 2;
if (base == 0)
{
if (*s == '0')
{
if (my_toupper(cs,s[1]) == 'X')
{
s += 2;
base = 16;
}
else
base = 8;
}
else
base = 10;
}
save = s;
cutoff = (~(ulonglong) 0) / (unsigned long int) base;
cutlim = (uint) ((~(ulonglong) 0) % (unsigned long int) base);
overflow = 0;
i = 0;
for (c = *s; s != e; c = *++s)
{
if (my_isdigit(cs,c))
c -= '0';
else if (my_isalpha(cs,c))
c = my_toupper(cs,c) - 'A' + 10;
else
break;
if (c >= base)
break;
if (i > cutoff || (i == cutoff && c > cutlim))
overflow = 1;
else
{
i *= (ulonglong) base;
i += c;
}
}
if (s == save)
goto noconv;
if (endptr != NULL)
*endptr = (char *) s;
if (overflow)
{
MY_ERRNO(ERANGE);
return (~(ulonglong) 0);
}
return (negative ? -((longlong) i) : (longlong) i);
noconv:
MY_ERRNO(EDOM);
if (endptr != NULL)
*endptr = (char *) nptr;
return 0L;
} }
double my_strntod_ucs2(CHARSET_INFO *cs __attribute__((unused)), double my_strntod_ucs2(CHARSET_INFO *cs __attribute__((unused)),
const char *s, uint l, char **e) const char *s, uint l, char **e)
{ {
char buf[256];
double res;
if((l+1)>sizeof(buf))
{
if (e)
memcpy(*e,s,sizeof(s));
return 0; return 0;
}
strncpy(buf,s,l);
buf[l]='\0';
res=strtod(buf,e);
if (e)
memcpy(*e,*e-buf+s,sizeof(s));
return res;
} }
......
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