Changeset 30859 in vbox for trunk/src/VBox/Runtime
- Timestamp:
- Jul 15, 2010 4:20:17 PM (14 years ago)
- Location:
- trunk/src/VBox/Runtime
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/string/utf-8.cpp
r28903 r30859 326 326 } 327 327 RT_EXPORT_SYMBOL(RTStrIsValidEncoding); 328 329 330 RTDECL(size_t) RTStrPurgeEncoding(char *psz) 331 { 332 size_t cErrors = 0; 333 for (;;) 334 { 335 RTUNICP Cp; 336 int rc = RTStrGetCpEx((const char **)&psz, &Cp); 337 if (RT_SUCCESS(rc)) 338 { 339 if (!Cp) 340 break; 341 } 342 else 343 { 344 psz[-1] = '?'; 345 cErrors++; 346 } 347 } 348 return cErrors; 349 } 350 RT_EXPORT_SYMBOL(RTStrPurgeEncoding); 328 351 329 352 -
trunk/src/VBox/Runtime/testcase/tstUtf8.cpp
r30320 r30859 788 788 } 789 789 790 791 792 /** 793 * Check case insensitivity. 794 */ 795 void TstRTStrPurgeEncoding(RTTEST hTest) 796 { 797 RTTestSub(hTest, "RTStrPurgeEncoding"); 798 799 /* 800 * Test some good strings. 801 */ 802 char sz1[] = "1234567890wertyuiopsdfghjklzxcvbnm"; 803 char sz1Copy[sizeof(sz1)]; 804 memcpy(sz1Copy, sz1, sizeof(sz1)); 805 806 RTTESTI_CHECK_RETV(RTStrPurgeEncoding(sz1) == 0); 807 RTTESTI_CHECK_RETV(!memcmp(sz1, sz1Copy, sizeof(sz1))); 808 809 char *pszAll = RTStrDup(g_szAll); 810 if (pszAll) 811 { 812 RTTESTI_CHECK(RTStrPurgeEncoding(pszAll) == 0); 813 RTTESTI_CHECK(!memcmp(pszAll, g_szAll, sizeof(g_szAll))); 814 RTStrFree(pszAll); 815 } 816 817 /* 818 * Test some bad stuff. 819 */ 820 struct 821 { 822 size_t cErrors; 823 unsigned char szIn[5]; 824 const char *pszExpect; 825 } aTests[] = 826 { 827 { 0, { '1', '2', '3', '4', '\0' }, "1234" }, 828 { 1, { 0x80, '2', '3', '4', '\0' }, "?234" }, 829 { 1, { '1', 0x80, '3', '4', '\0' }, "1?34" }, 830 { 1, { '1', '2', 0x80, '4', '\0' }, "12?4" }, 831 { 1, { '1', '2', '3', 0x80, '\0' }, "123?" }, 832 { 2, { 0x80, 0x81, '3', '4', '\0' }, "??34" }, 833 { 2, { '1', 0x80, 0x81, '4', '\0' }, "1??4" }, 834 { 2, { '1', '2', 0x80, 0x81, '\0' }, "12??" }, 835 }; 836 for (size_t i = 0; i < RT_ELEMENTS(aTests); i++) 837 { 838 size_t cErrors = RTStrPurgeEncoding((char *)aTests[i].szIn); 839 if (cErrors != aTests[i].cErrors) 840 RTTestFailed(hTest, "#%u: cErrors=%u expected %u\n", i, cErrors, aTests[i].cErrors); 841 else if (strcmp((char *)aTests[i].szIn, aTests[i].pszExpect)) 842 RTTestFailed(hTest, "#%u: %.5Rhxs expected %.5Rhxs (%s)\n", i, aTests[i].szIn, aTests[i].pszExpect, aTests[i].pszExpect); 843 } 844 845 RTTestSubDone(hTest); 846 } 790 847 791 848 … … 1238 1295 test3(hTest); 1239 1296 TstRTStrXCmp(hTest); 1297 TstRTStrPurgeEncoding(hTest); 1240 1298 testStrEnd(hTest); 1241 1299 testStrStr(hTest);
Note:
See TracChangeset
for help on using the changeset viewer.