msvcrt: Make wcstoi64 support various Unicode digits.

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:25 +02:00 committed by Alexandre Julliard
parent bdd771dfa7
commit 5b6e1cf2de
2 changed files with 26 additions and 11 deletions

View File

@ -2862,17 +2862,17 @@ static void test__wcstoi64(void)
ok(res == 0, "res != 0\n");
ok(endpos == tamil, "Incorrect endpos (%p-%p)\n", tamil, endpos);
res = p_wcstoi64(thai, NULL, 10);
todo_wine ok(res == 9, "res != 9\n");
ok(res == 9, "res != 9\n");
res = p_wcstoi64(fullwidth, NULL, 10);
todo_wine ok(res == 9, "res != 9\n");
ok(res == 9, "res != 9\n");
res = p_wcstoi64(superscript1, NULL, 10);
ok(res == 0, "res != 0\n");
res = p_wcstoi64(hex, NULL, 16);
todo_wine ok(res == 0x9f9, "res != 0x9f9\n");
ok(res == 0x9f9, "res != 0x9f9\n");
res = p_wcstoi64(minus_0x91, NULL, 0);
todo_wine ok(res == -0x91, "res != -0x91\n");
ok(res == -0x91, "res != -0x91\n");
res = p_wcstoi64(plus_071, NULL, 0);
todo_wine ok(res == 071, "res != 071\n");
ok(res == 071, "res != 071\n");
ures = p_wcstoui64(digit, NULL, 10);
ok(ures == 9, "ures != 9\n");
@ -2883,24 +2883,24 @@ static void test__wcstoi64(void)
ok(ures == 0, "ures != 0\n");
ok(endpos == tamil, "Incorrect endpos (%p-%p)\n", tamil, endpos);
ures = p_wcstoui64(thai, NULL, 10);
todo_wine ok(ures == 9, "ures != 9\n");
ok(ures == 9, "ures != 9\n");
ures = p_wcstoui64(fullwidth, NULL, 10);
todo_wine ok(ures == 9, "ures != 9\n");
ok(ures == 9, "ures != 9\n");
ures = p_wcstoui64(superscript1, NULL, 10);
ok(ures == 0, "ures != 0\n");
ures = p_wcstoui64(hex, NULL, 16);
todo_wine ok(ures == 0x9f9, "ures != 0x9f9\n");
ok(ures == 0x9f9, "ures != 0x9f9\n");
ures = p_wcstoui64(plus_071, NULL, 0);
todo_wine ok(ures == 071, "ures != 071\n");
ok(ures == 071, "ures != 071\n");
/* Test various unicode digits */
for (i = 0; i < sizeof(zeros) / sizeof(zeros[0]); ++i) {
WCHAR tmp[] = {zeros[i] + 4, zeros[i], zeros[i] + 5, 0};
res = p_wcstoi64(tmp, NULL, 0);
todo_wine ok(res == 405, "with zero = U+%04X: got %d, expected 405\n", zeros[i], (int)res);
ok(res == 405, "with zero = U+%04X: got %d, expected 405\n", zeros[i], (int)res);
tmp[1] = zeros[i] + 10;
res = p_wcstoi64(tmp, NULL, 16);
todo_wine ok(res == 4, "with zero = U+%04X: got %d, expected 4\n", zeros[i], (int)res);
ok(res == 4, "with zero = U+%04X: got %d, expected 4\n", zeros[i], (int)res);
}
return;

View File

@ -2027,6 +2027,21 @@ static int wctoint(WCHAR c, int base)
v = c - 'A' + 10;
else if ('a' <= c && c <= 'z')
v = c - 'a' + 10;
else {
/* NOTE: wine_fold_string(MAP_FOLDDIGITS) supports too many things. */
/* Unicode points that contain digits 0-9; keep this sorted! */
static const WCHAR zeros[] = {
0x660, 0x6f0, 0x966, 0x9e6, 0xa66, 0xae6, 0xb66, 0xc66, 0xce6,
0xd66, 0xe50, 0xed0, 0xf20, 0x1040, 0x17e0, 0x1810, 0xff10
};
int i;
for (i = 0; i < sizeof(zeros)/sizeof(zeros[0]) && c >= zeros[i]; ++i) {
if (zeros[i] <= c && c <= zeros[i] + 9) {
v = c - zeros[i];
break;
}
}
}
return v < base ? v : -1;
}