Changeset 19942 in vbox for trunk/src/VBox/Runtime/common/string
- Timestamp:
- May 23, 2009 3:42:57 PM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 47644
- Location:
- trunk/src/VBox/Runtime/common/string
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/string/strformat.cpp
r14066 r19942 170 170 static int rtStrFormatNumber(char *psz, KSIZE64 ullValue, unsigned int uiBase, signed int cchWidth, signed int cchPrecision, unsigned int fFlags) 171 171 { 172 const char *pachDigits = "0123456789abcdef";173 char *pszStart = psz;172 const char *pachDigits = "0123456789abcdef"; 173 char *pszStart = psz; 174 174 int cchValue; 175 175 unsigned long ul; 176 #if 0177 unsigned long ullow;178 #endif179 176 int i; 180 177 int j; 181 178 182 /** @todo Formatting of 64 bit numbers is broken, fix it! */183 184 179 /* 185 * Validate and ad djust input...180 * Validate and adjust input... 186 181 */ 187 /** @todo r=bird: Dmitry, who is calling this code with uiBase == 0? */ 188 if (uiBase == 0) 189 uiBase = 10; 190 kASSERT((uiBase >= 2 || uiBase <= 16)); 182 Assert(uiBase >= 2 || uiBase <= 16); 191 183 if (fFlags & RTSTR_F_CAPITAL) 192 184 pachDigits = "0123456789ABCDEF"; 193 185 if (fFlags & RTSTR_F_LEFT) 194 186 fFlags &= ~RTSTR_F_ZEROPAD; 187 if ( (fFlags & RTSTR_F_THOUSAND_SEP) 188 && ( uiBase != 10 189 || (fFlags & RTSTR_F_ZEROPAD))) /** @todo implement RTSTR_F_ZEROPAD + RTSTR_F_THOUSAND_SEP. */ 190 fFlags &= ~RTSTR_F_THOUSAND_SEP; 195 191 196 192 /* … … 218 214 } while (ul); 219 215 } 216 if (fFlags & RTSTR_F_THOUSAND_SEP) 217 { 218 if (cchValue <= 3) 219 fFlags &= ~RTSTR_F_THOUSAND_SEP; 220 else 221 cchValue += cchValue / 3 - (cchValue % 3 == 0); 222 } 220 223 221 224 /* … … 281 284 { 282 285 uint64_t u64 = *(uint64_t *)(void *)&ullValue; 283 do 284 { 285 psz[i--] = pachDigits[u64 % uiBase]; 286 u64 /= uiBase; 287 } while (u64); 286 if (fFlags & RTSTR_F_THOUSAND_SEP) 287 { 288 do 289 { 290 if ((-i - 1) % 4 == 3) 291 psz[i--] = ' '; 292 psz[i--] = pachDigits[u64 % uiBase]; 293 u64 /= uiBase; 294 } while (u64); 295 } 296 else 297 { 298 do 299 { 300 psz[i--] = pachDigits[u64 % uiBase]; 301 u64 /= uiBase; 302 } while (u64); 303 } 288 304 } 289 305 else 290 306 { 291 307 ul = (fFlags & RTSTR_F_VALSIGNED) && (ullValue.ulLo & 0x80000000) ? -(int32_t)ullValue.ulLo : ullValue.ulLo; 292 do308 if (fFlags & RTSTR_F_THOUSAND_SEP) 293 309 { 294 psz[i--] = pachDigits[ul % uiBase]; 295 ul /= uiBase; 296 } while (ul); 310 do 311 { 312 if ((-i - 1) % 4 == 3) 313 psz[i--] = ' '; 314 psz[i--] = pachDigits[ul % uiBase]; 315 ul /= uiBase; 316 } while (ul); 317 } 318 else 319 { 320 do 321 { 322 psz[i--] = pachDigits[ul % uiBase]; 323 ul /= uiBase; 324 } while (ul); 325 } 297 326 } 298 299 327 300 328 /* … … 358 386 switch (*pszFormat++) 359 387 { 360 case '#': fFlags |= RTSTR_F_SPECIAL; continue; 361 case '-': fFlags |= RTSTR_F_LEFT; continue; 362 case '+': fFlags |= RTSTR_F_PLUS; continue; 363 case ' ': fFlags |= RTSTR_F_BLANK; continue; 364 case '0': fFlags |= RTSTR_F_ZEROPAD; continue; 388 case '#': fFlags |= RTSTR_F_SPECIAL; continue; 389 case '-': fFlags |= RTSTR_F_LEFT; continue; 390 case '+': fFlags |= RTSTR_F_PLUS; continue; 391 case ' ': fFlags |= RTSTR_F_BLANK; continue; 392 case '0': fFlags |= RTSTR_F_ZEROPAD; continue; 393 case '\'': fFlags |= RTSTR_F_THOUSAND_SEP; continue; 365 394 } 366 395 pszFormat--; -
trunk/src/VBox/Runtime/common/string/strformatrt.cpp
r13837 r19942 414 414 case RTSF_FP16: 415 415 { 416 fFlags &= ~(RTSTR_F_VALSIGNED | RTSTR_F_BIT_MASK | RTSTR_F_WIDTH | RTSTR_F_PRECISION );416 fFlags &= ~(RTSTR_F_VALSIGNED | RTSTR_F_BIT_MASK | RTSTR_F_WIDTH | RTSTR_F_PRECISION | RTSTR_F_THOUSAND_SEP); 417 417 cch = RTStrFormatNumber(&szBuf[0], u.fp16.sel, 16, 4, -1, fFlags | RTSTR_F_16BIT); 418 418 Assert(cch == 4); … … 425 425 case RTSF_FP32: 426 426 { 427 fFlags &= ~(RTSTR_F_VALSIGNED | RTSTR_F_BIT_MASK | RTSTR_F_WIDTH | RTSTR_F_PRECISION );427 fFlags &= ~(RTSTR_F_VALSIGNED | RTSTR_F_BIT_MASK | RTSTR_F_WIDTH | RTSTR_F_PRECISION | RTSTR_F_THOUSAND_SEP); 428 428 cch = RTStrFormatNumber(&szBuf[0], u.fp32.sel, 16, 4, -1, fFlags | RTSTR_F_16BIT); 429 429 Assert(cch == 4); … … 436 436 case RTSF_FP64: 437 437 { 438 fFlags &= ~(RTSTR_F_VALSIGNED | RTSTR_F_BIT_MASK | RTSTR_F_WIDTH | RTSTR_F_PRECISION );438 fFlags &= ~(RTSTR_F_VALSIGNED | RTSTR_F_BIT_MASK | RTSTR_F_WIDTH | RTSTR_F_PRECISION | RTSTR_F_THOUSAND_SEP); 439 439 cch = RTStrFormatNumber(&szBuf[0], u.fp64.sel, 16, 4, -1, fFlags | RTSTR_F_16BIT); 440 440 Assert(cch == 4);
Note:
See TracChangeset
for help on using the changeset viewer.