Changeset 7414 in vbox
- Timestamp:
- Mar 10, 2008 3:40:15 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/string/strformat.cpp
r7183 r7414 41 41 #include <iprt/assert.h> 42 42 #ifdef IN_RING3 43 #include <iprt/alloc.h> 44 #include <iprt/err.h> 43 # include <iprt/alloc.h> 44 # include <iprt/err.h> 45 # include <iprt/uni.h> 45 46 #endif 46 47 #include <iprt/string.h> … … 65 66 *******************************************************************************/ 66 67 static unsigned _strnlen(const char *psz, unsigned cchMax); 67 static unsigned _strnlenU CS2(PCRTUCS2 pucs, unsigned cchMax);68 static unsigned _strnlenUtf16(PCRTUTF16 pwsz, unsigned cchMax); 68 69 static int rtStrFormatNumber(char *psz, KSIZE64 ullValue, unsigned int uiBase, signed int cchWidth, signed int cchPrecision, unsigned int fFlags); 69 70 … … 89 90 * Finds the length of a string up to cchMax. 90 91 * @returns Length. 91 * @param p ucsPointer to string.92 * @param pwsz Pointer to string. 92 93 * @param cchMax Max length. 93 94 */ 94 static unsigned _strnlenU CS2(PCRTUCS2 pucs, unsigned cchMax)95 static unsigned _strnlenUtf16(PCRTUTF16 pwsz, unsigned cchMax) 95 96 { 96 PCRTUCS2 pucsC = pucs; 97 98 while (cchMax-- > 0 && *pucs != '\0') 99 pucs++; 100 101 return pucs - pucsC; 97 #ifdef IN_RING3 98 unsigned cwc = 0; 99 while (cchMax-- > 0) 100 { 101 RTUNICP cp = RTUtf16GetCp(pwsz); 102 Assert(cp != RTUNICP_INVALID); 103 if (!cp || cp == RTUNICP_INVALID) 104 break; 105 } 106 return cwc; 107 #else /* !IN_RING3 */ 108 PCRTUTF16 pwszC = pwsz; 109 110 while (cchMax-- > 0 && *pwsz != '\0') 111 pwsz++; 112 113 return pwsz - pwszC; 114 #endif /* !IN_RING3 */ 102 115 } 103 116 … … 436 449 437 450 #ifndef IN_RING3 438 case 'S': /* Unicode string as current code page . */451 case 'S': /* Unicode string as current code page -> Unicode as UTF-8 in GC/R0. */ 439 452 chArgSize = 'l'; 440 453 /* fall thru */ … … 444 457 if (chArgSize == 'l') 445 458 { 446 /* u cs2 -> utf8 */459 /* utf-16 -> utf-8 */ 447 460 int cchStr; 448 461 PCRTUTF16 pwszStr = va_arg(args, PRTUTF16); … … 453 466 pwszStr = s_wszNull; 454 467 } 455 cchStr = _strnlenU CS2(pwszStr, (unsigned)cchPrecision);468 cchStr = _strnlenUtf16(pwszStr, (unsigned)cchPrecision); 456 469 if (!(fFlags & RTSTR_F_LEFT)) 457 470 while (--cchWidth >= cchStr) … … 481 494 if (!VALID_PTR(puszStr)) 482 495 { 483 static RTUNICP uszNull[] = {'<', 'N', 'U', 'L', 'L', '>', '\0' };484 puszStr = uszNull;496 static RTUNICP s_uszNull[] = {'<', 'N', 'U', 'L', 'L', '>', '\0' }; 497 puszStr = s_uszNull; 485 498 } 486 499 cchStr = _strnlenUni(puszStr, (unsigned)cchPrecision); … … 528 541 if (chArgSize == 'l') 529 542 { 530 int cchStr; 531 PCRTUCS2 pucs2Str = va_arg(args, PRTUCS2); 532 if (!VALID_PTR(pucs2Str)) 533 { 534 static RTUCS2 ucs2Null[] = {'<', 'N', 'U', 'L', 'L', '>', '\0' }; 535 pucs2Str = ucs2Null; 536 } 537 538 cchStr = _strnlenUCS2(pucs2Str, (unsigned)cchPrecision); 543 /* UTF-16 */ 544 int cchStr; 545 PCRTUTF16 pwsz2Str = va_arg(args, PRTUTF16); 546 if (!VALID_PTR(pwsz2Str)) 547 { 548 static RTUTF16 s_wsz2Null[] = {'<', 'N', 'U', 'L', 'L', '>', '\0' }; 549 pwsz2Str = s_wsz2Null; 550 } 551 552 cchStr = _strnlenUtf16(pwsz2Str, (unsigned)cchPrecision); 539 553 if (!(fFlags & RTSTR_F_LEFT)) 540 554 while (--cchWidth >= cchStr) … … 544 558 { 545 559 /* allocate temporary buffer. */ 546 PRTU CS2 pucs2Tmp = (PRTUCS2)RTMemAlloc((cchStr + 1) * sizeof(RTUCS2));547 memcpy(p ucs2Tmp, pucs2Str, cchStr * sizeof(RTUCS2));548 p ucs2Tmp[cchStr] = '\0';560 PRTUTF16 pwsz2Tmp = (PRTUTF16)RTMemTmpAlloc((cchStr + 1) * sizeof(RTUTF16)); 561 memcpy(pwsz2Tmp, pwsz2Str, cchStr * sizeof(RTUTF16)); 562 pwsz2Tmp[cchStr] = '\0'; 549 563 550 564 char *pszUtf8; 551 int rc = RT StrUcs2ToUtf8(&pszUtf8, pucs2Tmp);565 int rc = RTUtf16ToUtf8(pwsz2Tmp, &pszUtf8); 552 566 if (RT_SUCCESS(rc)) 553 567 { … … 564 578 while (cchStr-- > 0) 565 579 cch += pfnOutput(pvArgOutput, "\x7f", 1); 566 RTMem Free(pucs2Tmp);580 RTMemTmpFree(pwsz2Tmp); 567 581 } 568 582 … … 572 586 else if (chArgSize == 'L') 573 587 { 588 /* UCS-32 */ 574 589 AssertMsgFailed(("Not implemented yet\n")); 575 590 } 576 591 else 577 592 { 593 /* UTF-8 */ 578 594 int cchStr; 579 const char *pszStr = va_arg(args, char *);595 const char *pszStr = va_arg(args, char *); 580 596 581 597 if (!VALID_PTR(pszStr)) … … 589 605 { 590 606 /* allocate temporary buffer. */ 591 char *pszTmp = (char *)RTMem Alloc(cchStr + 1);607 char *pszTmp = (char *)RTMemTmpAlloc(cchStr + 1); 592 608 memcpy(pszTmp, pszStr, cchStr); 593 609 pszTmp[cchStr] = '\0'; … … 603 619 while (cchStr-- > 0) 604 620 cch += pfnOutput(pvArgOutput, "\x7f", 1); 605 RTMem Free(pszTmp);621 RTMemTmpFree(pszTmp); 606 622 } 607 623
Note:
See TracChangeset
for help on using the changeset viewer.