msvcrt: Move WCHAR-to-int conversion to a function.

Signed-off-by: Lauri Kenttä <lauri.kentta@gmail.com>
Signed-off-by: Piotr Caban <piotr@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Lauri Kenttä 2017-01-25 17:02:24 +02:00 committed by Alexandre Julliard
parent b0ccba4b33
commit bdd771dfa7
1 changed files with 25 additions and 28 deletions

View File

@ -2015,6 +2015,21 @@ INT CDECL MSVCRT_wcsncat_s(MSVCRT_wchar_t *dst, MSVCRT_size_t elem,
return MSVCRT_ERANGE;
}
/*********************************************************************
* wctoint (INTERNAL)
*/
static int wctoint(WCHAR c, int base)
{
int v = -1;
if ('0' <= c && c <= '9')
v = c - '0';
else if ('A' <= c && c <= 'Z')
v = c - 'A' + 10;
else if ('a' <= c && c <= 'z')
v = c - 'a' + 10;
return v < base ? v : -1;
}
/*********************************************************************
* _wcstoi64_l (MSVCRT.@)
*
@ -2040,31 +2055,22 @@ __int64 CDECL MSVCRT__wcstoi64_l(const MSVCRT_wchar_t *nptr,
} else if(*nptr == '+')
nptr++;
if((base==0 || base==16) && *nptr=='0' && tolowerW(*(nptr+1))=='x') {
if((base==0 || base==16) && wctoint(*nptr, 1)==0 && tolowerW(*(nptr+1))=='x') {
base = 16;
nptr += 2;
}
if(base == 0) {
if(*nptr=='0')
if(wctoint(*nptr, 1)==0)
base = 8;
else
base = 10;
}
while(*nptr) {
MSVCRT_wchar_t cur = tolowerW(*nptr);
int v;
if(cur>='0' && cur<='9') {
if(cur >= '0'+base)
int v = wctoint(*nptr, base);
if(v<0)
break;
v = cur-'0';
} else {
if(cur<'a' || cur>='a'+base-10)
break;
v = cur-'a'+10;
}
if(negative)
v = -v;
@ -2205,31 +2211,22 @@ unsigned __int64 CDECL MSVCRT__wcstoui64_l(const MSVCRT_wchar_t *nptr,
} else if(*nptr == '+')
nptr++;
if((base==0 || base==16) && *nptr=='0' && tolowerW(*(nptr+1))=='x') {
if((base==0 || base==16) && wctoint(*nptr, 1)==0 && tolowerW(*(nptr+1))=='x') {
base = 16;
nptr += 2;
}
if(base == 0) {
if(*nptr=='0')
if(wctoint(*nptr, 1)==0)
base = 8;
else
base = 10;
}
while(*nptr) {
MSVCRT_wchar_t cur = tolowerW(*nptr);
int v;
if(cur>='0' && cur<='9') {
if(cur >= '0'+base)
int v = wctoint(*nptr, base);
if(v<0)
break;
v = *nptr-'0';
} else {
if(cur<'a' || cur>='a'+base-10)
break;
v = cur-'a'+10;
}
nptr++;