Changeset 62916 in vbox for trunk/src/VBox/Runtime/common/string/utf-8.cpp
- Timestamp:
- Aug 3, 2016 2:05:01 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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;
Note:
See TracChangeset
for help on using the changeset viewer.