Changeset 33563 in vbox for trunk/include/iprt/cpp
- Timestamp:
- Oct 28, 2010 2:46:26 PM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 67169
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/cpp/ministring.h
r33074 r33563 65 65 MiniString() 66 66 : m_psz(NULL), 67 m_c bLength(0),67 m_cch(0), 68 68 m_cbAllocated(0) 69 69 { … … 118 118 size_t length() const 119 119 { 120 return m_c bLength;120 return m_cch; 121 121 } 122 122 … … 149 149 { 150 150 if ( cb != m_cbAllocated 151 && cb > m_c bLength + 1151 && cb > m_cch + 1 152 152 ) 153 153 { … … 235 235 * Appends the given character to "this". 236 236 * 237 * @param c 237 * @param ch The character to append. 238 238 * 239 239 * @throws std::bad_alloc On allocation error. The object is left unchanged. … … 241 241 * @returns Reference to the object. 242 242 */ 243 MiniString &append(char c); 243 MiniString &append(char ch); 244 245 /** 246 * Appends the given unicode code point to "this". 247 * 248 * @param uc The unicode code point to append. 249 * 250 * @throws std::bad_alloc On allocation error. The object is left unchanged. 251 * 252 * @returns Reference to the object. 253 */ 254 MiniString &appendCodePoint(RTUNICP uc); 244 255 245 256 /** … … 287 298 { 288 299 if (length()) 300 { 301 /* Folding an UTF-8 string may result in a shorter encoding (see 302 testcase), so recalculate the length afterwars. */ 289 303 ::RTStrToUpper(m_psz); 304 size_t cchNew = strlen(m_psz); 305 Assert(cchNew <= m_cch); 306 m_cch = cchNew; 307 } 290 308 return *this; 291 309 } … … 299 317 { 300 318 if (length()) 319 { 320 /* Folding an UTF-8 string may result in a shorter encoding (see 321 testcase), so recalculate the length afterwars. */ 301 322 ::RTStrToLower(m_psz); 323 size_t cchNew = strlen(m_psz); 324 Assert(cchNew <= m_cch); 325 m_cch = cchNew; 326 } 302 327 return *this; 303 328 } … … 361 386 if (m_psz) 362 387 { 363 m_c bLength = strlen(m_psz);364 m_cbAllocated = m_c bLength + 1; /* (Required for the Utf8Str::asOutParam case) */388 m_cch = strlen(m_psz); 389 m_cbAllocated = m_cch + 1; /* (Required for the Utf8Str::asOutParam case) */ 365 390 } 366 391 else 367 392 { 368 m_c bLength = 0;393 m_cch = 0; 369 394 m_cbAllocated = 0; 370 395 } … … 434 459 } 435 460 461 /** 462 * Compares the two strings. 463 * 464 * @returns true if equal, false if not. 465 * @param that The string to compare with. 466 */ 467 bool equals(const MiniString &that) const 468 { 469 return that.length() == length() 470 && memcmp(that.m_psz, m_psz, length()) == 0; 471 } 472 473 /** 474 * Compares the two strings. 475 * 476 * @returns true if equal, false if not. 477 * @param pszThat The string to compare with. 478 */ 479 bool equals(const char *pszThat) const 480 { 481 return RTStrCmp(pszThat, m_psz) == 0; 482 } 483 484 /** 485 * Compares the two strings ignoring differences in case. 486 * 487 * @returns true if equal, false if not. 488 * @param that The string to compare with. 489 */ 490 bool equalsIgnoreCase(const MiniString &that) const 491 { 492 /* Unfolded upper and lower case characters may require different 493 amount of encoding space, so the length optimization doesn't work. */ 494 return RTStrICmp(that.m_psz, m_psz) == 0; 495 } 496 497 /** 498 * Compares the two strings ignoring differences in case. 499 * 500 * @returns true if equal, false if not. 501 * @param pszThat The string to compare with. 502 */ 503 bool equalsIgnoreCase(const char *pszThat) const 504 { 505 return RTStrICmp(pszThat, m_psz) == 0; 506 } 507 436 508 /** @name Comparison operators. 437 509 * @{ */ 438 bool operator==(const MiniString &that) const { return !compare(that); }439 bool operator!=(const MiniString &that) const { return ! !compare(that); }510 bool operator==(const MiniString &that) const { return equals(that); } 511 bool operator!=(const MiniString &that) const { return !equals(that); } 440 512 bool operator<( const MiniString &that) const { return compare(that) < 0; } 441 513 bool operator>( const MiniString &that) const { return compare(that) > 0; } 442 514 443 bool operator==(const char * that) const { return !compare(that); }444 bool operator!=(const char * that) const { return !!compare(that); }445 bool operator<( const char * that) const { return compare(that) < 0; }446 bool operator>( const char * that) const { return compare(that) > 0; }515 bool operator==(const char *pszThat) const { return equals(pszThat); } 516 bool operator!=(const char *pszThat) const { return !equals(pszThat); } 517 bool operator<( const char *pszThat) const { return compare(pszThat) < 0; } 518 bool operator>( const char *pszThat) const { return compare(pszThat) > 0; } 447 519 /** @} */ 448 520 … … 567 639 RTStrFree(m_psz); 568 640 m_psz = NULL; 569 m_c bLength = 0;641 m_cch = 0; 570 642 m_cbAllocated = 0; 571 643 } … … 591 663 void copyFrom(const MiniString &s) 592 664 { 593 if ((m_c bLength = s.m_cbLength))594 { 595 m_cbAllocated = m_c bLength + 1;665 if ((m_cch = s.m_cch)) 666 { 667 m_cbAllocated = m_cch + 1; 596 668 m_psz = (char *)RTStrAlloc(m_cbAllocated); 597 669 if (RT_LIKELY(m_psz)) … … 599 671 else 600 672 { 601 m_c bLength = 0;673 m_cch = 0; 602 674 m_cbAllocated = 0; 603 675 #ifdef RT_EXCEPTIONS_ENABLED … … 631 703 if (pcsz && *pcsz) 632 704 { 633 m_c bLength = strlen(pcsz);634 m_cbAllocated = m_c bLength + 1;705 m_cch = strlen(pcsz); 706 m_cbAllocated = m_cch + 1; 635 707 m_psz = (char *)RTStrAlloc(m_cbAllocated); 636 708 if (RT_LIKELY(m_psz)) … … 638 710 else 639 711 { 640 m_c bLength = 0;712 m_cch = 0; 641 713 m_cbAllocated = 0; 642 714 #ifdef RT_EXCEPTIONS_ENABLED … … 647 719 else 648 720 { 649 m_c bLength = 0;721 m_cch = 0; 650 722 m_cbAllocated = 0; 651 723 m_psz = NULL; … … 654 726 655 727 char *m_psz; /**< The string buffer. */ 656 size_t m_c bLength;/**< strlen(m_psz) - i.e. no terminator included. */728 size_t m_cch; /**< strlen(m_psz) - i.e. no terminator included. */ 657 729 size_t m_cbAllocated; /**< Size of buffer that m_psz points to; at least m_cbLength + 1. */ 658 730 };
Note:
See TracChangeset
for help on using the changeset viewer.