Changeset 62930 in vbox for trunk/src/VBox/Runtime/common/string
- Timestamp:
- Aug 3, 2016 4:11:43 PM (9 years ago)
- svn:sync-xref-src-repo-rev:
- 109533
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/string/utf-16.cpp
r62477 r62930 299 299 300 300 301 RTDECL(ssize_t) RTUtf16PurgeComplementSet(PRTUTF16 pwsz, PCRTUNICP puszValidSet, char chReplacement) 302 { 303 size_t cReplacements = 0; 301 /** 302 * Helper for RTUtf16PurgeComplementSet. 303 * 304 * @returns true if @a Cp is valid, false if not. 305 * @param Cp The code point to validate. 306 * @param puszValidPairs Pair of valid code point sets. 307 * @param cValidPairs Number of pairs. 308 */ 309 DECLINLINE(bool) rtUtf16PurgeIsInSet(RTUNICP Cp, PCRTUNICP puszValidPairs, uint32_t cValidPairs) 310 { 311 while (cValidPairs-- > 0) 312 { 313 if ( Cp >= puszValidPairs[0] 314 && Cp <= puszValidPairs[1]) 315 return true; 316 puszValidPairs += 2; 317 } 318 return false; 319 } 320 321 322 RTDECL(ssize_t) RTUtf16PurgeComplementSet(PRTUTF16 pwsz, PCRTUNICP puszValidPairs, char chReplacement) 323 { 304 324 AssertReturn(chReplacement && (unsigned)chReplacement < 128, -1); 305 /* Validate the encoding. */ 325 326 /* 327 * Calc valid pairs and check that we've got an even number. 328 */ 329 uint32_t cValidPairs = 0; 330 while (puszValidPairs[cValidPairs * 2]) 331 { 332 AssertReturn(puszValidPairs[cValidPairs * 2 + 1], -1); 333 AssertMsg(puszValidPairs[cValidPairs * 2] <= puszValidPairs[cValidPairs * 2 + 1], 334 ("%#x vs %#x\n", puszValidPairs[cValidPairs * 2], puszValidPairs[cValidPairs * 2 + 1])); 335 cValidPairs++; 336 } 337 338 /* 339 * Do the replacing. 340 */ 341 ssize_t cReplacements = 0; 306 342 for (;;) 307 343 { 344 PRTUTF16 pwszCur = pwsz; 308 345 RTUNICP Cp; 309 PCRTUNICP pCp; 310 PRTUTF16 pwszOld = pwsz; 311 if (RT_FAILURE(RTUtf16GetCpEx((PCRTUTF16 *)&pwsz, &Cp))) 346 int rc = RTUtf16GetCpEx((PCRTUTF16 *)&pwsz, &Cp); 347 if (RT_SUCCESS(rc)) 348 { 349 if (Cp) 350 { 351 if (!rtUtf16PurgeIsInSet(Cp, puszValidPairs, cValidPairs)) 352 { 353 for (; pwszCur != pwsz; ++pwszCur) 354 *pwszCur = chReplacement; 355 ++cReplacements; 356 } 357 } 358 else 359 break; 360 } 361 else 312 362 return -1; 313 if (!Cp)314 break;315 for (pCp = puszValidSet; *pCp; pCp += 2)316 {317 AssertReturn(*(pCp + 1), -1);318 if (*pCp <= Cp && *(pCp + 1) >= Cp) /* No, I won't do * and ++. */319 break;320 }321 if (!*pCp)322 {323 for (; pwszOld != pwsz; ++pwszOld)324 *pwszOld = chReplacement;325 ++cReplacements;326 }327 363 } 328 364 return cReplacements;
Note:
See TracChangeset
for help on using the changeset viewer.