Changeset 21744 in vbox for trunk/src/VBox/Runtime/common/string
- Timestamp:
- Jul 21, 2009 12:29:43 PM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 50321
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/string/utf-8.cpp
r21337 r21744 189 189 * @param paCps Where to store the code points array. 190 190 * @param cCps The number of RTUNICP items the paCps buffer can hold, excluding the terminator ('\\0'). 191 * @param pcCps Where to store the actual number of decoded code points. This excludes the terminator.192 191 */ 193 static int rtUtf8Decode(const char *psz, size_t cch, PRTUNICP paCps, size_t cCps , size_t *pcCps)194 { 195 int rc = VINF_SUCCESS;192 static int rtUtf8Decode(const char *psz, size_t cch, PRTUNICP paCps, size_t cCps) 193 { 194 int rc = VINF_SUCCESS; 196 195 const unsigned char *puch = (const unsigned char *)psz; 197 const PRTUNICP pCpEnd = paCps + cCps; 198 PRTUNICP pCp = paCps; 199 Assert(pCpEnd >= pCp); 196 PRTUNICP pCp = paCps; 200 197 while (cch > 0) 201 198 { … … 206 203 207 204 /* check for output overflow */ 208 if ( pCp >= pCpEnd)205 if (RT_UNLIKELY(cCps < 1)) 209 206 { 210 207 rc = VERR_BUFFER_OVERFLOW; 211 208 break; 212 209 } 210 cCps--; 213 211 214 212 /* decode and recode the code point */ … … 273 271 /* done */ 274 272 *pCp = 0; 275 *pcCps = pCp - paCps;276 273 return rc; 277 274 } … … 363 360 * Decode the string. 364 361 */ 365 rc = rtUtf8Decode(pszString, RTSTR_MAX, paCps, cCps , &cCps);362 rc = rtUtf8Decode(pszString, RTSTR_MAX, paCps, cCps); 366 363 if (RT_SUCCESS(rc)) 367 364 { … … 422 419 * Encode the UTF-16 string. 423 420 */ 424 rc = rtUtf8Decode(pszString, cchString, paCpsResult, cCps - 1 , &cCpsResult);421 rc = rtUtf8Decode(pszString, cchString, paCpsResult, cCps - 1); 425 422 if (RT_SUCCESS(rc)) 426 423 { … … 585 582 * @param pwsz Where to store the UTF-16 string. 586 583 * @param cwc The number of RTUTF16 items the pwsz buffer can hold, excluding the terminator ('\\0'). 587 * @param pcwc Where to store the actual number of RTUTF16 items encoded into the UTF-16. This excludes the terminator.588 584 */ 589 static int rtUtf8RecodeAsUtf16(const char *psz, size_t cch, PRTUTF16 pwsz, size_t cwc , size_t *pcwc)590 { 591 int rc = VINF_SUCCESS;585 static int rtUtf8RecodeAsUtf16(const char *psz, size_t cch, PRTUTF16 pwsz, size_t cwc) 586 { 587 int rc = VINF_SUCCESS; 592 588 const unsigned char *puch = (const unsigned char *)psz; 593 const PRTUTF16 pwszEnd = pwsz + cwc; 594 PRTUTF16 pwc = pwsz; 595 Assert(pwszEnd >= pwc); 589 PRTUTF16 pwc = pwsz; 596 590 while (cch > 0) 597 591 { … … 602 596 603 597 /* check for output overflow */ 604 if ( pwc >= pwszEnd)598 if (RT_UNLIKELY(cwc < 1)) 605 599 { 606 600 rc = VERR_BUFFER_OVERFLOW; 607 601 break; 608 602 } 603 cwc--; 609 604 610 605 /* decode and recode the code point */ … … 640 635 | ((RTUNICP)(puch[1] & 0x3f) << 12) 641 636 | ((RTUNICP)(uch & 0x07) << 18); 642 if ( pwc + 1 >= pwszEnd)637 if (RT_UNLIKELY(cwc < 1)) 643 638 { 644 639 rc = VERR_BUFFER_OVERFLOW; 645 640 break; 646 641 } 642 cwc--; 643 647 644 uc -= 0x10000; 648 645 *pwc++ = 0xd800 | (uc >> 10); … … 655 652 /* done */ 656 653 *pwc = '\0'; 657 *pcwc = pwc - pwsz;658 654 return rc; 659 655 } … … 685 681 * Encode the UTF-16 string. 686 682 */ 687 rc = rtUtf8RecodeAsUtf16(pszString, RTSTR_MAX, pwsz, cwc , &cwc);683 rc = rtUtf8RecodeAsUtf16(pszString, RTSTR_MAX, pwsz, cwc); 688 684 if (RT_SUCCESS(rc)) 689 685 { … … 744 740 * Encode the UTF-16 string. 745 741 */ 746 rc = rtUtf8RecodeAsUtf16(pszString, cchString, pwszResult, cwc - 1 , &cwcResult);742 rc = rtUtf8RecodeAsUtf16(pszString, cchString, pwszResult, cwc - 1); 747 743 if (RT_SUCCESS(rc)) 748 744 {
Note:
See TracChangeset
for help on using the changeset viewer.