- Timestamp:
- Aug 3, 2016 2:05:01 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/vmm/pdmifs.h
r62476 r62916 1197 1197 * @thread Any thread. 1198 1198 */ 1199 DECLR3CALLBACKMEMBER(int, pfnSetParameters,(PPDMICHARCONNECTOR pInterface, unsigned Bps, char chParity, unsigned cDataBits, unsigned cStopBits)); 1199 DECLR3CALLBACKMEMBER(int, pfnSetParameters,(PPDMICHARCONNECTOR pInterface, unsigned Bps, char chParity, 1200 unsigned cDataBits, unsigned cStopBits)); 1200 1201 1201 1202 /** -
trunk/include/iprt/string.h
r62473 r62916 726 726 727 727 /** 728 * Saniti sea (valid) UTF-8 string by replacing all characters outside a white728 * Sanitizes a (valid) UTF-8 string by replacing all characters outside a white 729 729 * list in-place by an ASCII replacement character. Multi-byte characters will 730 730 * be replaced byte by byte. 731 731 * 732 * @returns The number of code points replaced, or a negative value if the 733 * string is not correctly encoded. In this last case the string 734 * may be partially processed. 732 * @returns The number of code points replaced. In the case of an incorrectly 733 * encoded string -1 will be returned, and the string is not completely 734 * processed. In the case of puszValidPairs having an odd number of 735 * code points, -1 will be also return but without any modification to 736 * the string. 735 737 * @param psz The string to sanitise. 736 * @param puszValid SetA zero-terminated array of pairs of Unicode points.738 * @param puszValidPairs A zero-terminated array of pairs of Unicode points. 737 739 * Each pair is the start and end point of a range, 738 740 * and the union of these ranges forms the white list. 739 741 * @param chReplacement The ASCII replacement character. 740 742 */ 741 RTDECL(ssize_t) RTStrPurgeComplementSet(char *psz, PCRTUNICP puszValid Set, char chReplacement);743 RTDECL(ssize_t) RTStrPurgeComplementSet(char *psz, PCRTUNICP puszValidPairs, char chReplacement); 742 744 743 745 /** -
trunk/src/VBox/Runtime/common/string/utf-8.cpp
r62477 r62916 364 364 365 365 366 RTDECL(ssize_t) RTStrPurgeComplementSet(char *psz, PCRTUNICP puszValidSet, char chReplacement) 367 { 368 size_t cReplacements = 0; 366 /** 367 * Helper for RTStrPurgeComplementSet. 368 * 369 * @returns true if @a Cp is valid, false if not. 370 * @param Cp The code point to validate. 371 * @param puszValidPairs Pair of valid code point sets. 372 * @param cValidPairs Number of pairs. 373 */ 374 DECLINLINE(bool) rtStrPurgeIsInSet(RTUNICP Cp, PCRTUNICP puszValidPairs, uint32_t cValidPairs) 375 { 376 while (cValidPairs-- > 0) 377 { 378 if ( Cp >= puszValidPairs[0] 379 && Cp <= puszValidPairs[1]) 380 return true; 381 puszValidPairs += 2; 382 } 383 return false; 384 } 385 386 387 RTDECL(ssize_t) RTStrPurgeComplementSet(char *psz, PCRTUNICP puszValidPairs, char chReplacement) 388 { 369 389 AssertReturn(chReplacement && (unsigned)chReplacement < 128, -1); 390 391 /* 392 * Calc valid pairs and check that we've got an even number. 393 */ 394 uint32_t cValidPairs = 0; 395 while (puszValidPairs[cValidPairs * 2]) 396 { 397 AssertReturn(puszValidPairs[cValidPairs * 2 + 1], -1); 398 AssertMsg(puszValidPairs[cValidPairs * 2] <= puszValidPairs[cValidPairs * 2 + 1], 399 ("%#x vs %#x\n", puszValidPairs[cValidPairs * 2], puszValidPairs[cValidPairs * 2 + 1])); 400 cValidPairs++; 401 } 402 403 /* 404 * Do the replacing. 405 */ 406 ssize_t cReplacements = 0; 370 407 for (;;) 371 408 { 372 RTUNICP Cp; 373 PCRTUNICP pCp; 374 char *pszOld = psz; 375 if (RT_FAILURE(RTStrGetCpEx((const char **)&psz, &Cp))) 409 char *pszCur = psz; 410 RTUNICP Cp; 411 int rc = RTStrGetCpEx((const char **)&psz, &Cp); 412 if (RT_SUCCESS(rc)) 413 { 414 if (Cp) 415 { 416 if (!rtStrPurgeIsInSet(Cp, puszValidPairs, cValidPairs)) 417 { 418 for (; pszCur != psz; ++pszCur) 419 *pszCur = chReplacement; 420 ++cReplacements; 421 } 422 } 423 else 424 break; 425 } 426 else 376 427 return -1; 377 if (!Cp)378 break;379 for (pCp = puszValidSet; *pCp; pCp += 2)380 {381 AssertReturn(*(pCp + 1), -1);382 if (*pCp <= Cp && *(pCp + 1) >= Cp) /* No, I won't do * and ++. */383 break;384 }385 if (!*pCp)386 {387 for (; pszOld != psz; ++pszOld)388 *pszOld = chReplacement;389 ++cReplacements;390 }391 428 } 392 429 return cReplacements; -
trunk/src/VBox/Runtime/testcase/tstUtf8.cpp
r62722 r62916 874 874 ssize_t cReplacements; 875 875 AssertRC(RTStrCopy(szCopy, RT_ELEMENTS(szCopy), aTests[i].pcszIn)); 876 cReplacements = RTStrPurgeComplementSet(szCopy, aTests[i].pcCpSet, 877 aTests[i].chReplacement); 876 RTTestDisableAssertions(hTest); 877 cReplacements = RTStrPurgeComplementSet(szCopy, aTests[i].pcCpSet, aTests[i].chReplacement); 878 RTTestRestoreAssertions(hTest); 878 879 if (cReplacements != aTests[i].cExpected) 879 880 RTTestFailed(hTest, "#%u: expected %lld, actual %lld\n", i,
Note:
See TracChangeset
for help on using the changeset viewer.