📄 locale.c
字号:
"6",
"7",
"8",
"9",
"a",
"A",
"b",
"B",
"c",
"C"
};
const char *strings[] =
{
"C",
"\"",
"9",
"'",
"}",
"-",
"7",
"+",
"`",
"1",
"a",
"5",
"\\",
"8",
"B",
"3",
"_",
"6",
"{",
"2",
"c",
"4",
"!",
"0",
"A",
":",
"b",
"."
};
static int compare_string1(const void *e1, const void *e2)
{
const char *s1 = *(const char **)e1;
const char *s2 = *(const char **)e2;
return lstrcmpA(s1, s2);
}
static int compare_string2(const void *e1, const void *e2)
{
const char *s1 = *(const char **)e1;
const char *s2 = *(const char **)e2;
return CompareStringA(0, 0, s1, -1, s2, -1) - 2;
}
static int compare_string3(const void *e1, const void *e2)
{
const char *s1 = *(const char **)e1;
const char *s2 = *(const char **)e2;
char key1[256], key2[256];
LCMapStringA(0, LCMAP_SORTKEY, s1, -1, key1, sizeof(key1));
LCMapStringA(0, LCMAP_SORTKEY, s2, -1, key2, sizeof(key2));
return strcmp(key1, key2);
}
static void test_sorting(void)
{
char buf[256];
char **str_buf = (char **)buf;
int i;
assert(sizeof(buf) >= sizeof(strings));
/* 1. sort using lstrcmpA */
memcpy(buf, strings, sizeof(strings));
qsort(buf, sizeof(strings)/sizeof(strings[0]), sizeof(strings[0]), compare_string1);
for (i = 0; i < sizeof(strings)/sizeof(strings[0]); i++)
{
ok(!strcmp(strings_sorted[i], str_buf[i]),
"qsort using lstrcmpA failed for element %d\n", i);
}
/* 2. sort using CompareStringA */
memcpy(buf, strings, sizeof(strings));
qsort(buf, sizeof(strings)/sizeof(strings[0]), sizeof(strings[0]), compare_string2);
for (i = 0; i < sizeof(strings)/sizeof(strings[0]); i++)
{
ok(!strcmp(strings_sorted[i], str_buf[i]),
"qsort using CompareStringA failed for element %d\n", i);
}
/* 3. sort using sort keys */
memcpy(buf, strings, sizeof(strings));
qsort(buf, sizeof(strings)/sizeof(strings[0]), sizeof(strings[0]), compare_string3);
for (i = 0; i < sizeof(strings)/sizeof(strings[0]); i++)
{
ok(!strcmp(strings_sorted[i], str_buf[i]),
"qsort using sort keys failed for element %d\n", i);
}
}
static void test_FoldStringA(void)
{
int ret, i;
char src[256], dst[256];
static const char digits_src[] = { 0xB9,0xB2,0xB3,'\0' };
static const char digits_dst[] = { '1','2','3','\0' };
static const char composite_src[] =
{
0x8a,0x8e,0x9a,0x9e,0x9f,0xc0,0xc1,0xc2,
0xc3,0xc4,0xc5,0xc7,0xc8,0xc9,0xca,0xcb,
0xcc,0xcd,0xce,0xcf,0xd1,0xd2,0xd3,0xd4,
0xd5,0xd6,0xd8,0xd9,0xda,0xdb,0xdc,0xdd,
0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,0xe7,0xe8,
0xe9,0xea,0xeb,0xec,0xed,0xee,0xef,0xf1,
0xf2,0xf3,0xf4,0xf5,0xf6,0xf8,0xf9,0xfa,
0xfb,0xfc,0xfd,0xff,'\0'
};
static const char composite_dst[] =
{
0x53,0x3f,0x5a,0x3f,0x73,0x3f,0x7a,0x3f,
0x59,0xa8,0x41,0x60,0x41,0xb4,0x41,0x5e,
0x41,0x7e,0x41,0xa8,0x41,0xb0,0x43,0xb8,
0x45,0x60,0x45,0xb4,0x45,0x5e,0x45,0xa8,
0x49,0x60,0x49,0xb4,0x49,0x5e,0x49,0xa8,
0x4e,0x7e,0x4f,0x60,0x4f,0xb4,0x4f,0x5e,
0x4f,0x7e,0x4f,0xa8,0x4f,0x3f,0x55,0x60,
0x55,0xb4,0x55,0x5e,0x55,0xa8,0x59,0xb4,
0x61,0x60,0x61,0xb4,0x61,0x5e,0x61,0x7e,
0x61,0xa8,0x61,0xb0,0x63,0xb8,0x65,0x60,
0x65,0xb4,0x65,0x5e,0x65,0xa8,0x69,0x60,
0x69,0xb4,0x69,0x5e,0x69,0xa8,0x6e,0x7e,
0x6f,0x60,0x6f,0xb4,0x6f,0x5e,0x6f,0x7e,
0x6f,0xa8,0x6f,0x3f,0x75,0x60,0x75,0xb4,
0x75,0x5e,0x75,0xa8,0x79,0xb4,0x79,0xa8,'\0'
};
static const char ligatures_src[] =
{
0x8C,0x9C,0xC6,0xDE,0xDF,0xE6,0xFE,'\0'
};
static const char ligatures_dst[] =
{
'O','E','o','e','A','E','T','H','s','s','a','e','t','h','\0'
};
if (!pFoldStringA)
return; /* FoldString is present in NT v3.1+, but not 95/98/Me */
/* these tests are locale specific */
if (GetACP() != 1252)
{
trace("Skipping FoldStringA tests for a not Latin 1 locale\n");
return;
}
/* MAP_FOLDDIGITS */
SetLastError(0);
ret = pFoldStringA(MAP_FOLDDIGITS, digits_src, -1, dst, 256);
if (GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
return;
EXPECT_LEN(4); EXPECT_VALID;
ok(strcmp(dst, digits_dst) == 0,
"MAP_FOLDDIGITS: Expected '%s', got '%s'\n", digits_dst, dst);
for (i = 1; i < 256; i++)
{
if (!strchr(digits_src, i))
{
src[0] = i;
src[1] = '\0';
SetLastError(0);
ret = pFoldStringA(MAP_FOLDDIGITS, src, -1, dst, 256);
EXPECT_LEN(2); EXPECT_VALID;
ok(dst[0] == src[0],
"MAP_FOLDDIGITS: Expected '%s', got '%s'\n", src, dst);
}
}
/* MAP_EXPAND_LIGATURES */
SetLastError(0);
ret = pFoldStringA(MAP_EXPAND_LIGATURES, ligatures_src, -1, dst, 256);
/* NT 4.0 doesn't support MAP_EXPAND_LIGATURES */
if (!(ret == 0 && GetLastError() == ERROR_INVALID_FLAGS)) {
EXPECT_LEN(sizeof(ligatures_dst)); EXPECT_VALID;
ok(strcmp(dst, ligatures_dst) == 0,
"MAP_EXPAND_LIGATURES: Expected '%s', got '%s'\n", ligatures_dst, dst);
for (i = 1; i < 256; i++)
{
if (!strchr(ligatures_src, i))
{
src[0] = i;
src[1] = '\0';
SetLastError(0);
ret = pFoldStringA(MAP_EXPAND_LIGATURES, src, -1, dst, 256);
EXPECT_LEN(2); EXPECT_VALID;
ok(dst[0] == src[0],
"MAP_EXPAND_LIGATURES: Expected '%s', got '%s'\n", src, dst);
}
}
}
/* MAP_COMPOSITE */
SetLastError(0);
ret = pFoldStringA(MAP_COMPOSITE, composite_src, -1, dst, 256);
EXPECT_VALID;
todo_wine
{
/* Wine gets close, but doesn't produce quite the same result as native */
EXPECT_LEN(121);
ok(strcmp(dst, composite_dst) == 0,
"MAP_COMPOSITE: Expected '%s', got '%s'\n", composite_dst, dst);
}
for (i = 1; i < 256; i++)
{
if (!strchr(composite_src, i))
{
src[0] = i;
src[1] = '\0';
SetLastError(0);
ret = pFoldStringA(MAP_COMPOSITE, src, -1, dst, 256);
EXPECT_LEN(2); EXPECT_VALID;
ok(dst[0] == src[0],
"0x%02x, 0x%02x,0x%02x,0x%02x,\n", (unsigned char)src[0],
(unsigned char)dst[0],(unsigned char)dst[1],(unsigned char)dst[2]);
}
}
/* MAP_FOLDCZONE */
for (i = 1; i < 256; i++)
{
src[0] = i;
src[1] = '\0';
SetLastError(0);
ret = pFoldStringA(MAP_FOLDCZONE, src, -1, dst, 256);
EXPECT_LEN(2); EXPECT_VALID;
ok(src[0] == dst[0],
"MAP_FOLDCZONE: Expected 0x%02x, got 0x%02x\n",
(unsigned char)src[0], (unsigned char)dst[0]);
}
/* MAP_PRECOMPOSED */
for (i = 1; i < 256; i++)
{
src[0] = i;
src[1] = '\0';
SetLastError(0);
ret = pFoldStringA(MAP_PRECOMPOSED, src, -1, dst, 256);
EXPECT_LEN(2); EXPECT_VALID;
ok(src[0] == dst[0],
"MAP_PRECOMPOSED: Expected 0x%02x, got 0x%02x\n",
(unsigned char)src[0], (unsigned char)dst[0]);
}
}
static void test_FoldStringW(void)
{
int ret;
size_t i, j;
WCHAR src[256], dst[256], ch, prev_ch = 1;
static const DWORD badFlags[] =
{
0,
MAP_PRECOMPOSED|MAP_COMPOSITE,
MAP_PRECOMPOSED|MAP_EXPAND_LIGATURES,
MAP_COMPOSITE|MAP_EXPAND_LIGATURES
};
/* Ranges of digits 0-9 : Must be sorted! */
static const WCHAR digitRanges[] =
{
0x0030, /* '0'-'9' */
0x0660, /* Eastern Arabic */
0x06F0, /* Arabic - Hindu */
0x0966, /* Devengari */
0x09E6, /* Bengalii */
0x0A66, /* Gurmukhi */
0x0AE6, /* Gujarati */
0x0B66, /* Oriya */
0x0BE6, /* Tamil - No 0 */
0x0C66, /* Telugu */
0x0CE6, /* Kannada */
0x0D66, /* Maylayalam */
0x0E50, /* Thai */
0x0ED0, /* Laos */
0x2070, /* Superscript - 1, 2, 3 are out of sequence */
0x2080, /* Subscript */
0x245F, /* Circled - 0 is out of sequence */
0x2473, /* Bracketed */
0x2487, /* Full stop */
0x2775, /* Inverted circled - No 0 */
0x277F, /* Patterned circled - No 0 */
0x2789, /* Inverted Patterned circled - No 0 */
0xff10, /* Pliene chasse (?) */
0xffff /* Terminator */
};
/* Digits which are represented, but out of sequence */
static const WCHAR outOfSequenceDigits[] =
{
0xB9, /* Superscript 1 */
0xB2, /* Superscript 2 */
0xB3, /* Superscript 3 */
0x24EA, /* Circled 0 */
'\0' /* Terminator */
};
/* Digits in digitRanges for which no representation is available */
static const WCHAR noDigitAvailable[] =
{
0x0BE6, /* No Tamil 0 */
0x2473, /* No Bracketed 0 */
0x2487, /* No 0 Full stop */
0x2775, /* No inverted circled 0 */
0x277F, /* No patterned circled */
0x2789, /* No inverted Patterned circled */
'\0' /* Terminator */
};
/* Compatibility conversion results */
static const
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -