Changeset 90779 in vbox for trunk/src/VBox/Runtime/common
- Timestamp:
- Aug 23, 2021 9:05:11 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/string/strformat.cpp
r82968 r90779 45 45 #include "internal/string.h" 46 46 47 48 /** 49 * Deals with bad pointers. 50 */ 51 static size_t rtStrFormatBadPointer(size_t cch, PFNRTSTROUTPUT pfnOutput, void *pvArgOutput, int cchWidth, 52 unsigned fFlags, void const *pvStr, char szTmp[64], const char *pszTag, int cchTag) 53 { 54 static char const s_szNull[] = "<NULL>"; 55 int cchStr = !pvStr ? sizeof(s_szNull) - 1 : 1 + sizeof(void *) * 2 + cchTag + 1; 56 57 if (!(fFlags & RTSTR_F_LEFT)) 58 while (--cchWidth >= cchStr) 59 cch += pfnOutput(pvArgOutput, " ", 1); 60 61 cchWidth -= cchStr; 62 if (!pvStr) 63 cch += pfnOutput(pvArgOutput, s_szNull, sizeof(s_szNull) - 1); 64 else 65 { 66 cch += pfnOutput(pvArgOutput, "<", 1); 67 cchStr = RTStrFormatNumber(&szTmp[0], (uintptr_t)pvStr, 16, sizeof(char *) * 2, 0, RTSTR_F_ZEROPAD); 68 cch += pfnOutput(pvArgOutput, szTmp, cchStr); 69 cch += pfnOutput(pvArgOutput, pszTag, cchTag); 70 cch += pfnOutput(pvArgOutput, ">", 1); 71 } 72 73 while (--cchWidth >= 0) 74 cch += pfnOutput(pvArgOutput, " ", 1); 75 return cch; 76 } 47 77 48 78 … … 514 544 { 515 545 /* utf-16 -> utf-8 */ 516 int cchStr; 517 PCRTUTF16 pwszStr = va_arg(args, PRTUTF16); 518 519 if (!VALID_PTR(pwszStr)) 520 { 521 static RTUTF16 s_wszNull[] = {'<', 'N', 'U', 'L', 'L', '>', '\0' }; 522 pwszStr = s_wszNull; 523 } 524 cchStr = _strnlenUtf16(pwszStr, (unsigned)cchPrecision); 525 if (!(fFlags & RTSTR_F_LEFT)) 546 PCRTUTF16 pwszStr = va_arg(args, PCRTUTF16); 547 if (RT_VALID_PTR(pwszStr)) 548 { 549 int cwcStr = _strnlenUtf16(pwszStr, (unsigned)cchPrecision); 550 if (!(fFlags & RTSTR_F_LEFT)) 551 while (--cchWidth >= cwcStr) 552 cch += pfnOutput(pvArgOutput, " ", 1); 553 cchWidth -= cwcStr; 554 while (cwcStr-- > 0) 555 { 556 /** @todo \#ifndef IN_RC*/ 557 #ifdef IN_RING3 558 RTUNICP Cp; 559 RTUtf16GetCpEx(&pwszStr, &Cp); 560 char *pszEnd = RTStrPutCp(szTmp, Cp); 561 *pszEnd = '\0'; 562 cch += pfnOutput(pvArgOutput, szTmp, pszEnd - szTmp); 563 #else 564 char ch = (char)*pwszStr++; 565 cch += pfnOutput(pvArgOutput, &ch, 1); 566 #endif 567 } 568 while (--cchWidth >= 0) 569 cch += pfnOutput(pvArgOutput, " ", 1); 570 } 571 else 572 cch = rtStrFormatBadPointer(cch, pfnOutput, pvArgOutput, cchWidth, fFlags, 573 pwszStr, szTmp, RT_STR_TUPLE("!BadStrW")); 574 } 575 else if (chArgSize == 'L') 576 { 577 /* unicp -> utf8 */ 578 PCRTUNICP puszStr = va_arg(args, PCRTUNICP); 579 if (RT_VALID_PTR(puszStr)) 580 { 581 int cchStr = _strnlenUni(puszStr, (unsigned)cchPrecision); 582 if (!(fFlags & RTSTR_F_LEFT)) 583 while (--cchWidth >= cchStr) 584 cch += pfnOutput(pvArgOutput, " ", 1); 585 586 cchWidth -= cchStr; 587 while (cchStr-- > 0) 588 { 589 /** @todo \#ifndef IN_RC*/ 590 #ifdef IN_RING3 591 char *pszEnd = RTStrPutCp(szTmp, *puszStr++); 592 cch += pfnOutput(pvArgOutput, szTmp, pszEnd - szTmp); 593 #else 594 char ch = (char)*puszStr++; 595 cch += pfnOutput(pvArgOutput, &ch, 1); 596 #endif 597 } 598 while (--cchWidth >= 0) 599 cch += pfnOutput(pvArgOutput, " ", 1); 600 } 601 else 602 cch = rtStrFormatBadPointer(cch, pfnOutput, pvArgOutput, cchWidth, fFlags, 603 puszStr, szTmp, RT_STR_TUPLE("!BadStrU")); 604 } 605 else 606 { 607 const char *pszStr = va_arg(args, const char *); 608 if (RT_VALID_PTR(pszStr)) 609 { 610 int cchStr = _strnlen(pszStr, (unsigned)cchPrecision); 611 if (!(fFlags & RTSTR_F_LEFT)) 612 while (--cchWidth >= cchStr) 613 cch += pfnOutput(pvArgOutput, " ", 1); 614 615 cch += pfnOutput(pvArgOutput, pszStr, cchStr); 616 526 617 while (--cchWidth >= cchStr) 527 618 cch += pfnOutput(pvArgOutput, " ", 1); 528 cchWidth -= cchStr; 529 while (cchStr-- > 0) 530 { 531 /** @todo \#ifndef IN_RC*/ 532 #ifdef IN_RING3 533 RTUNICP Cp; 534 RTUtf16GetCpEx(&pwszStr, &Cp); 535 char *pszEnd = RTStrPutCp(szTmp, Cp); 536 *pszEnd = '\0'; 537 cch += pfnOutput(pvArgOutput, szTmp, pszEnd - szTmp); 538 #else 539 char ch = (char)*pwszStr++; 540 cch += pfnOutput(pvArgOutput, &ch, 1); 541 #endif 542 } 543 while (--cchWidth >= 0) 544 cch += pfnOutput(pvArgOutput, " ", 1); 545 } 546 else if (chArgSize == 'L') 547 { 548 /* unicp -> utf8 */ 549 int cchStr; 550 PCRTUNICP puszStr = va_arg(args, PCRTUNICP); 551 552 if (!VALID_PTR(puszStr)) 553 { 554 static RTUNICP s_uszNull[] = {'<', 'N', 'U', 'L', 'L', '>', '\0' }; 555 puszStr = s_uszNull; 556 } 557 cchStr = _strnlenUni(puszStr, (unsigned)cchPrecision); 558 if (!(fFlags & RTSTR_F_LEFT)) 559 while (--cchWidth >= cchStr) 560 cch += pfnOutput(pvArgOutput, " ", 1); 561 562 cchWidth -= cchStr; 563 while (cchStr-- > 0) 564 { 565 /** @todo \#ifndef IN_RC*/ 566 #ifdef IN_RING3 567 char *pszEnd = RTStrPutCp(szTmp, *puszStr++); 568 cch += pfnOutput(pvArgOutput, szTmp, pszEnd - szTmp); 569 #else 570 char ch = (char)*puszStr++; 571 cch += pfnOutput(pvArgOutput, &ch, 1); 572 #endif 573 } 574 while (--cchWidth >= 0) 575 cch += pfnOutput(pvArgOutput, " ", 1); 576 } 577 else 578 { 579 int cchStr; 580 const char *pszStr = va_arg(args, char*); 581 582 if (!VALID_PTR(pszStr)) 583 pszStr = "<NULL>"; 584 cchStr = _strnlen(pszStr, (unsigned)cchPrecision); 585 if (!(fFlags & RTSTR_F_LEFT)) 586 while (--cchWidth >= cchStr) 587 cch += pfnOutput(pvArgOutput, " ", 1); 588 589 cch += pfnOutput(pvArgOutput, pszStr, cchStr); 590 591 while (--cchWidth >= cchStr) 592 cch += pfnOutput(pvArgOutput, " ", 1); 619 } 620 else 621 cch = rtStrFormatBadPointer(cch, pfnOutput, pvArgOutput, cchWidth, fFlags, 622 pszStr, szTmp, RT_STR_TUPLE("!BadStr")); 593 623 } 594 624 break; … … 727 757 } 728 758 } 729 cchNum = RTStrFormatNumber( (char *)&szTmp, u64Value, uBase, cchWidth, cchPrecision, fFlags);730 cch += pfnOutput(pvArgOutput, (char *)&szTmp, cchNum);759 cchNum = RTStrFormatNumber(&szTmp[0], u64Value, uBase, cchWidth, cchPrecision, fFlags); 760 cch += pfnOutput(pvArgOutput, &szTmp[0], cchNum); 731 761 break; 732 762 }
Note:
See TracChangeset
for help on using the changeset viewer.