Changeset 80496 in vbox
- Timestamp:
- Aug 29, 2019 11:58:21 AM (6 years ago)
- svn:sync-xref-src-repo-rev:
- 132989
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/string.h
r80358 r80496 1477 1477 * decimal point by default, can do 0-3 via precision 1478 1478 * field. No rounding when calculating fraction. 1479 * The space flag add a space between the value and 1480 * unit. 1481 * - \%RhcB - Same a \%Rhcb only the 'i' is skipped in the unit. 1479 1482 * - \%Rhci - SI variant of \%Rhcb, fraction is rounded. 1480 1483 * - \%Rhub - Human readable number formatting, using … … 1482 1485 * integer as input. Does one decimal point by 1483 1486 * default, can do 0-3 via precision field. No 1484 * rounding when calculating fraction. 1487 * rounding when calculating fraction. The space 1488 * flag add a space between the value and unit. 1489 * - \%RhuB - Same a \%Rhub only the 'i' is skipped in the unit. 1485 1490 * - \%Rhui - SI variant of \%Rhub, fraction is rounded. 1486 1491 * -
trunk/src/VBox/Runtime/common/string/strformatrt.cpp
r76553 r80496 989 989 #endif /* IN_RING3 */ 990 990 991 /* 992 * Human readable sizes. 993 */ 991 994 case 'c': 992 995 case 'u': … … 997 1000 uint64_t uFraction = 0; 998 1001 const char *pszPrefix = NULL; 999 unsigned cchFixedPart;1000 1002 char ch2 = *(*ppszFormat)++; 1001 AssertMsgReturn(ch2 == 'b' || ch2 == ' i', ("invalid type '%.10s'!\n", pszFormatOrg), 0);1003 AssertMsgReturn(ch2 == 'b' || ch2 == 'B' || ch2 == 'i', ("invalid type '%.10s'!\n", pszFormatOrg), 0); 1002 1004 uValue = va_arg(*pArgs, uint64_t); 1003 1005 1004 1006 if (!(fFlags & RTSTR_F_PRECISION)) 1005 cchPrecision = 1; 1007 cchPrecision = 1; /** @todo default to flexible decimal point. */ 1006 1008 else if (cchPrecision > 3) 1007 1009 cchPrecision = 3; … … 1009 1011 cchPrecision = 0; 1010 1012 1011 cchFixedPart = cchPrecision + (cchPrecision != 0) + (ch == 'c'); 1012 1013 if (ch2 == 'b') 1013 if (ch2 == 'b' || ch2 == 'B') 1014 1014 { 1015 1015 static const struct … … 1040 1040 uValue >>= s_aUnits[i].cShift; 1041 1041 pszPrefix = s_aUnits[i].pszPrefix; 1042 cchFixedPart += 2;1043 1042 break; 1044 1043 } … … 1075 1074 } 1076 1075 pszPrefix = s_aUnits[i].pszPrefix; 1077 cchFixedPart += 1;1078 1076 break; 1079 1077 } … … 1089 1087 RTSTR_F_ZEROPAD | RTSTR_F_WIDTH); 1090 1088 } 1089 if (fFlags & RTSTR_F_BLANK) 1090 szBuf[cchBuf++] = ' '; 1091 1091 szBuf[cchBuf++] = *pszPrefix++; 1092 if (*pszPrefix )1092 if (*pszPrefix && ch2 != 'B') 1093 1093 szBuf[cchBuf++] = *pszPrefix; 1094 1094 } 1095 else if (fFlags & RTSTR_F_BLANK) 1096 szBuf[cchBuf++] = ' '; 1095 1097 if (ch == 'c') 1096 1098 szBuf[cchBuf++] = 'B'; -
trunk/src/VBox/Runtime/testcase/tstRTStrFormat.cpp
r76553 r80496 775 775 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%10Rhcb%u", UINT64_C(6678345), 42); 776 776 CHECKSTR(" 6.3MiB42"); 777 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%10Rhcb%u", UINT64_C(6710886), 42); 778 CHECKSTR(" 6.3MiB42"); 779 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%10Rhcb%u", UINT64_C(6710887), 42); 780 CHECKSTR(" 6.4MiB42"); 781 cch = RTStrPrintf(pszBuf, BUF_SIZE, "% 10Rhcb%u", UINT64_C(6710887), 42); 782 CHECKSTR(" 6.4 MiB42"); 783 cch = RTStrPrintf(pszBuf, BUF_SIZE, "% 10RhcB%u", UINT64_C(6710887), 42); 784 CHECKSTR(" 6.4 MB42"); 777 785 778 786 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%10Rhub%u", UINT64_C(6678345), 42); 779 787 CHECKSTR(" 6.3Mi42"); 788 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%10RhuB%u", UINT64_C(6678345), 42); 789 CHECKSTR(" 6.3M42"); 780 790 781 791 cch = RTStrPrintf(pszBuf, BUF_SIZE, "%10Rhci%u", UINT64_C(6678345), 42);
Note:
See TracChangeset
for help on using the changeset viewer.