📄 string.c
字号:
{10, ULL(0x0fffffff,0xffffffff), "1152921504606846975\0-----------------------------------------------", 0x33}, {10, ULL(0x7fffffff,0xffffffff), "9223372036854775807\0-----------------------------------------------", 0x33}, {10, ULL(0x80000000,0x00000000), "-9223372036854775808\0----------------------------------------------", 0x11}, {10, ULL(0x80000000,0x00000000), "9223372036854775808\0-----------------------------------------------", 0x22}, {10, ULL(0x80000000,0x00000001), "-9223372036854775807\0----------------------------------------------", 0x55}, {10, ULL(0x80000000,0x00000001), "-9223372036854775809\0----------------------------------------------", 0x00}, {10, ULL(0x80000000,0x00000001), "9223372036854775809\0-----------------------------------------------", 0x22}, {10, ULL(0x80000000,0x00000002), "-9223372036854775806\0----------------------------------------------", 0x55}, {10, ULL(0x80000000,0x00000002), "-9223372036854775810\0----------------------------------------------", 0x00}, {10, ULL(0x80000000,0x00000002), "9223372036854775810\0-----------------------------------------------", 0x22}, {10, ULL(0xffffffff,0xfffffffe), "-2\0----------------------------------------------------------------", 0x55}, {10, ULL(0xffffffff,0xfffffffe), "-18446744073709551614\0---------------------------------------------", 0x00}, {10, ULL(0xffffffff,0xfffffffe), "18446744073709551614\0----------------------------------------------", 0x22}, {10, ULL(0xffffffff,0xffffffff), "-1\0----------------------------------------------------------------", 0x55}, {10, ULL(0xffffffff,0xffffffff), "-18446744073709551615\0---------------------------------------------", 0x00}, {10, ULL(0xffffffff,0xffffffff), "18446744073709551615\0----------------------------------------------", 0x22}, {16, 0, "0\0-----------------------------------------------------------------", 0x33}, {16, 1, "1\0-----------------------------------------------------------------", 0x33}, {16, 2147483646, "7ffffffe\0----------------------------------------------------------", 0x33}, {16, 2147483647, "7fffffff\0----------------------------------------------------------", 0x33}, {16, 0x80000000, "80000000\0----------------------------------------------------------", 0x33}, {16, 0x80000001, "80000001\0----------------------------------------------------------", 0x33}, {16, 0xFFFFFFFE, "fffffffe\0----------------------------------------------------------", 0x33}, {16, 0xFFFFFFFF, "ffffffff\0----------------------------------------------------------", 0x33}, {16, ULL(0x1,0x00000000), "100000000\0---------------------------------------------------------", 0x33}, {16, ULL(0xbad,0xdeadbeef), "baddeadbeef\0-------------------------------------------------------", 0x33}, {16, ULL(0x80000000,0x00000000), "8000000000000000\0--------------------------------------------------", 0x33}, {16, ULL(0xfedcba98,0x76543210), "fedcba9876543210\0--------------------------------------------------", 0x33}, {16, ULL(0xffffffff,0x80000001), "ffffffff80000001\0--------------------------------------------------", 0x33}, {16, ULL(0xffffffff,0xfffffffe), "fffffffffffffffe\0--------------------------------------------------", 0x33}, {16, ULL(0xffffffff,0xffffffff), "ffffffffffffffff\0--------------------------------------------------", 0x33}, { 2, 32768, "1000000000000000\0--------------------------------------------------", 0x33}, { 2, 65536, "10000000000000000\0-------------------------------------------------", 0x33}, { 2, 131072, "100000000000000000\0------------------------------------------------", 0x33}, {16, 0xffffffff, "ffffffff\0----------------------------------------------------------", 0x33}, {16, 0xa, "a\0-----------------------------------------------------------------", 0x33}, {16, 0, "0\0-----------------------------------------------------------------", 0x33}, {20, 3368421, "111111\0------------------------------------------------------------", 0x33}, {36, 62193781, "111111\0------------------------------------------------------------", 0x33}, {37, 71270178, "111111\0------------------------------------------------------------", 0x33}, {99, ULL(0x2,0x3c9e468c), "111111\0------------------------------------------------------------", 0x33},};#define NB_ULONGLONG2STR (sizeof(ulonglong2str)/sizeof(*ulonglong2str))static void one_i64toa_test(int test_num, const ulonglong2str_t *ulonglong2str){ LPSTR result; char dest_str[LARGE_STRI_BUFFER_LENGTH + 1]; memset(dest_str, '-', LARGE_STRI_BUFFER_LENGTH); dest_str[LARGE_STRI_BUFFER_LENGTH] = '\0'; result = p_i64toa(ulonglong2str->value, dest_str, ulonglong2str->base); ok(result == dest_str, "(test %d): _i64toa(%Lu, [out], %d) has result %p, expected: %p", test_num, ulonglong2str->value, ulonglong2str->base, result, dest_str); if (ulonglong2str->mask & 0x04) { if (memcmp(dest_str, ulonglong2str->Buffer, LARGE_STRI_BUFFER_LENGTH) != 0) { if (memcmp(dest_str, ulonglong2str[1].Buffer, LARGE_STRI_BUFFER_LENGTH) != 0) { ok(memcmp(dest_str, ulonglong2str->Buffer, LARGE_STRI_BUFFER_LENGTH) == 0, "(test %d): _i64toa(%Lu, [out], %d) assigns string \"%s\", expected: \"%s\"", test_num, ulonglong2str->value, ulonglong2str->base, dest_str, ulonglong2str->Buffer); } /* if */ } /* if */ } else { ok(memcmp(dest_str, ulonglong2str->Buffer, LARGE_STRI_BUFFER_LENGTH) == 0, "(test %d): _i64toa(%Lu, [out], %d) assigns string \"%s\", expected: \"%s\"", test_num, ulonglong2str->value, ulonglong2str->base, dest_str, ulonglong2str->Buffer); } /* if */}static void one_ui64toa_test(int test_num, const ulonglong2str_t *ulonglong2str){ LPSTR result; char dest_str[LARGE_STRI_BUFFER_LENGTH + 1]; memset(dest_str, '-', LARGE_STRI_BUFFER_LENGTH); dest_str[LARGE_STRI_BUFFER_LENGTH] = '\0'; result = p_ui64toa(ulonglong2str->value, dest_str, ulonglong2str->base); ok(result == dest_str, "(test %d): _ui64toa(%Lu, [out], %d) has result %p, expected: %p", test_num, ulonglong2str->value, ulonglong2str->base, result, dest_str); ok(memcmp(dest_str, ulonglong2str->Buffer, LARGE_STRI_BUFFER_LENGTH) == 0, "(test %d): _ui64toa(%Lu, [out], %d) assigns string \"%s\", expected: \"%s\"", test_num, ulonglong2str->value, ulonglong2str->base, dest_str, ulonglong2str->Buffer);}static void test_ulonglongtoa(void){ int test_num; for (test_num = 0; test_num < NB_ULONGLONG2STR; test_num++) { if (ulonglong2str[test_num].mask & 0x01) { one_i64toa_test(test_num, &ulonglong2str[test_num]); } /* if */ if (p_ui64toa != NULL) { if (ulonglong2str[test_num].mask & 0x02) { one_ui64toa_test(test_num, &ulonglong2str[test_num]); } /* if */ } /* if */ } /* for */}static void one_i64tow_test(int test_num, const ulonglong2str_t *ulonglong2str){ int pos; WCHAR expected_wstr[LARGE_STRI_BUFFER_LENGTH + 1]; WCHAR dest_wstr[LARGE_STRI_BUFFER_LENGTH + 1]; UNICODE_STRING unicode_string; STRING ansi_str; LPWSTR result; for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) { expected_wstr[pos] = ulonglong2str->Buffer[pos]; } /* for */ expected_wstr[LARGE_STRI_BUFFER_LENGTH] = '\0'; for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) { dest_wstr[pos] = '-'; } /* for */ dest_wstr[LARGE_STRI_BUFFER_LENGTH] = '\0'; unicode_string.Length = LARGE_STRI_BUFFER_LENGTH * sizeof(WCHAR); unicode_string.MaximumLength = unicode_string.Length + sizeof(WCHAR); unicode_string.Buffer = dest_wstr; result = p_i64tow(ulonglong2str->value, dest_wstr, ulonglong2str->base); pRtlUnicodeStringToAnsiString(&ansi_str, &unicode_string, 1); ok(result == dest_wstr, "(test %d): _i64tow(%llu, [out], %d) has result %p, expected: %p", test_num, ulonglong2str->value, ulonglong2str->base, result, dest_wstr); if (ulonglong2str->mask & 0x04) { if (memcmp(dest_wstr, expected_wstr, LARGE_STRI_BUFFER_LENGTH * sizeof(WCHAR)) != 0) { for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) { expected_wstr[pos] = ulonglong2str[1].Buffer[pos]; } /* for */ expected_wstr[LARGE_STRI_BUFFER_LENGTH] = '\0'; if (memcmp(dest_wstr, expected_wstr, LARGE_STRI_BUFFER_LENGTH * sizeof(WCHAR)) != 0) { ok(memcmp(dest_wstr, expected_wstr, LARGE_STRI_BUFFER_LENGTH * sizeof(WCHAR)) == 0, "(test %d): _i64tow(%llu, [out], %d) assigns string \"%s\", expected: \"%s\"", test_num, ulonglong2str->value, ulonglong2str->base, ansi_str.Buffer, ulonglong2str->Buffer); } /* if */ } /* if */ } else { ok(memcmp(dest_wstr, expected_wstr, LARGE_STRI_BUFFER_LENGTH * sizeof(WCHAR)) == 0, "(test %d): _i64tow(%llu, [out], %d) assigns string \"%s\", expected: \"%s\"", test_num, ulonglong2str->value, ulonglong2str->base, ansi_str.Buffer, ulonglong2str->Buffer); } /* if */ pRtlFreeAnsiString(&ansi_str);}static void one_ui64tow_test(int test_num, const ulonglong2str_t *ulonglong2str){ int pos; WCHAR expected_wstr[LARGE_STRI_BUFFER_LENGTH + 1]; WCHAR dest_wstr[LARGE_STRI_BUFFER_LENGTH + 1]; UNICODE_STRING unicode_string; STRING ansi_str; LPWSTR result; for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) { expected_wstr[pos] = ulonglong2str->Buffer[pos]; } /* for */ expected_wstr[LARGE_STRI_BUFFER_LENGTH] = '\0'; for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) { dest_wstr[pos] = '-'; } /* for */ dest_wstr[LARGE_STRI_BUFFER_LENGTH] = '\0'; unicode_string.Length = LARGE_STRI_BUFFER_LENGTH * sizeof(WCHAR); unicode_string.MaximumLength = unicode_string.Length + sizeof(WCHAR); unicode_string.Buffer = dest_wstr; result = p_ui64tow(ulonglong2str->value, dest_wstr, ulonglong2str->base); pRtlUnicodeStringToAnsiString(&ansi_str, &unicode_string, 1); ok(result == dest_wstr, "(test %d): _ui64tow(%llu, [out], %d) has result %p, expected: %p", test_num, ulonglong2str->value, ulonglong2str->base, result, dest_wstr); ok(memcmp(dest_wstr, expected_wstr, LARGE_STRI_BUFFER_LENGTH * sizeof(WCHAR)) == 0, "(test %d): _ui64tow(%llu, [out], %d) assigns string \"%s\", expected: \"%s\"", test_num, ulonglong2str->value, ulonglong2str->base, ansi_str.Buffer, ulonglong2str->Buffer); pRtlFreeAnsiString(&ansi_str);}static void test_ulonglongtow(void){ int test_num; int pos; WCHAR expected_wstr[LARGE_STRI_BUFFER_LENGTH + 1]; LPWSTR result; for (test_num = 0; test_num < NB_ULONGLONG2STR; test_num++) { if (ulonglong2str[test_num].mask & 0x10) { one_i64tow_test(test_num, &ulonglong2str[test_num]); } /* if */ if (p_ui64tow) { if (ulonglong2str[test_num].mask & 0x20) { one_ui64tow_test(test_num, &ulonglong2str[test_num]); } /* if */ } /* if */ } /* for */ for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) { expected_wstr[pos] = ulong2str[0].Buffer[pos]; } /* for */ expected_wstr[LARGE_STRI_BUFFER_LENGTH] = '\0'; result = p_i64tow(ulong2str[0].value, NULL, 10); ok(result == NULL, "(test d): _i64tow(%llu, NULL, 10) has result %p, expected: NULL", ulonglong2str[0].value, result); if (p_ui64tow) { for (pos = 0; pos < LARGE_STRI_BUFFER_LENGTH; pos++) { expected_wstr[pos] = ulong2str[0].Buffer[pos]; } /* for */ expected_wstr[LARGE_STRI_BUFFER_LENGTH] = '\0'; result = p_ui64tow(ulong2str[0].value, NULL, 10); ok(result == NULL, "(test e): _ui64tow(%llu, NULL, 10) has result %p, expected: NULL", ulonglong2str[0].value, result); } /* if */}typedef struct { const char *str; LONG value;} str2long_t;static const str2long_t str2long[] = { { "1011101100", 1011101100 }, { "1234567", 1234567 }, { "-214", -214 }, { "+214", 214 }, /* The + sign is allowed also */ { "--214", 0 }, /* Do not accept more than one sign */ { "-+214", 0 }, { "++214", 0 }, { "+-214", 0 }, { "\00141", 0 }, /* not whitespace char 1 */ { "\00242", 0 }, /* not whitespace char 2 */ { "\00343", 0 }, /* not whitespace char 3 */ { "\00444", 0 }, /* not whitespace char 4 */ { "\00545", 0 }, /* not whitespace char 5 */ { "\00646", 0 }, /* not whitespace char 6 */ { "\00747", 0 }, /* not whitespace char 7 */ { "\01050", 0 }, /* not whitespace char 8 */ { "\01151", 51 }, /* is whitespace char 9 (tab) */ { "\01252", 52 }, /* is whitespace char 10 (lf) */ { "\01353", 53 }, /* is whitespace char 11 (vt) */ { "\01454", 54 }, /* is whitespace char 12 (ff) */ { "\01555", 55 }, /* is whitespace char 13 (cr) */ { "\01656", 0 }, /* not whitespace char 14 */ { "\01757", 0 }, /* not whitespace char 15 */ { "\02060", 0 }, /* not whitespace char 16 */ { "\02161", 0 }, /* not whitespace char 17 */ { "\02262", 0 }, /* not whitespace char 18 */ { "\02363", 0 }, /* not whitespace char 19 */ { "\02464", 0 }, /* not whitespace char 20 */ { "\02565", 0 }, /* not whitespace char 21 */ { "\02666", 0 }, /* not whitespace char 22 */ { "\02767", 0 }, /* not whitespace char 23 */ { "\03070", 0 }, /* not whitespace char 24 */ { "\03171", 0 }, /* not whitespace char 25 */ { "\03272", 0 }, /* not whitespace char 26 */ { "\03373", 0 }, /* not whitespace char 27 */ { "\03474", 0 }, /* not whitespace char 28 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -