- Timestamp:
- Jul 26, 2017 2:31:35 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/cpp/ministring.h
r68094 r68123 50 50 * behave the same. In both cases, RTCString allocates no memory, reports 51 51 * a zero length and zero allocated bytes for both, and returns an empty 52 * C string from c_str().52 * C-style string from c_str(). 53 53 * 54 54 * @note RTCString ASSUMES that all strings it deals with are valid UTF-8. … … 92 92 93 93 /** 94 * Creates a copy of a C string.94 * Creates a copy of a C-style string. 95 95 * 96 96 * This allocates strlen(pcsz) + 1 bytes for the new instance, unless s is empty. … … 126 126 127 127 /** 128 * Create a partial copy of a C string.128 * Create a partial copy of a C-style string. 129 129 * 130 130 * @param a_pszSrc The source string (UTF-8). … … 330 330 331 331 /** 332 * Assigns a copy of another RTCString. 333 * 334 * @param a_rSrc Reference to the source string. 335 * @throws std::bad_alloc On allocation error. The object is left unchanged. 336 */ 337 RTCString &assign(const RTCString &a_rSrc); 338 339 /** 340 * Assigns a copy of a C-style string. 341 * 342 * @param a_pszSrc Pointer to the C-style source string. 343 * @throws std::bad_alloc On allocation error. The object is left unchanged. 344 * @remarks ASSUMES valid 345 */ 346 RTCString &assign(const char *a_pszSrc); 347 348 /** 349 * Assigns a partial copy of another RTCString. 350 * 351 * @param a_rSrc The source string. 352 * @param a_offSrc The byte offset into the source string. 353 * @param a_cchSrc The max number of chars (encoded UTF-8 bytes) 354 * to copy from the source string. 355 */ 356 RTCString &assign(const RTCString &a_rSrc, size_t a_offSrc, size_t a_cchSrc = npos); 357 358 /** 359 * Assigns a partial copy of a C-style string. 360 * 361 * @param a_pszSrc The source string (UTF-8). 362 * @param a_cchSrc The max number of chars (encoded UTF-8 bytes) 363 * to copy from the source string. 364 */ 365 RTCString &assign(const char *a_pszSrc, size_t a_cchSrc); 366 367 /** 368 * Assigs a string containing @a a_cTimes repetitions of the character @a a_ch. 369 * 370 * @param a_cTimes The number of times the character is repeated. 371 * @param a_ch The character to fill the string with. 372 */ 373 RTCString &assign(size_t a_cTimes, char a_ch); 374 375 /** 332 376 * Assigns the output of the string format operation (RTStrPrintf). 333 377 * … … 358 402 359 403 /** 360 * Appends the string @a that to @a this. 361 * 362 * @param that The string to append. 363 * 364 * @throws std::bad_alloc On allocation error. The object is left unchanged. 365 * 366 * @returns Reference to the object. 367 */ 368 RTCString &append(const RTCString &that); 369 370 /** 371 * Appends the string @a pszThat to @a this. 372 * 373 * @param pszThat The C string to append. 374 * 375 * @throws std::bad_alloc On allocation error. The object is left unchanged. 376 * 377 * @returns Reference to the object. 378 */ 379 RTCString &append(const char *pszThat); 404 * Appends the string @a that to @a rThat. 405 * 406 * @param rThat The string to append. 407 * @throws std::bad_alloc On allocation error. The object is left unchanged. 408 * @returns Reference to the object. 409 */ 410 RTCString &append(const RTCString &rThat); 411 412 /** 413 * Appends the string @a pszSrc to @a this. 414 * 415 * @param pszSrc The C-style string to append. 416 * @throws std::bad_alloc On allocation error. The object is left unchanged. 417 * @returns Reference to the object. 418 */ 419 RTCString &append(const char *pszSrc); 380 420 381 421 /** … … 386 426 * not codepoint). 387 427 * @param cchMax The maximum number of bytes to append. 388 * 389 * @throws std::bad_alloc On allocation error. The object is left unchanged. 390 * 428 * @throws std::bad_alloc On allocation error. The object is left unchanged. 391 429 * @returns Reference to the object. 392 430 */ … … 396 434 * Appends the first @a cchMax chars from string @a pszThat to @a this. 397 435 * 398 * @param pszThat The C string to append.436 * @param pszThat The C-style string to append. 399 437 * @param cchMax The maximum number of bytes to append. 400 * 401 * @throws std::bad_alloc On allocation error. The object is left unchanged. 402 * 438 * @throws std::bad_alloc On allocation error. The object is left unchanged. 403 439 * @returns Reference to the object. 404 440 */ … … 409 445 * 410 446 * @param ch The character to append. 411 * 412 * @throws std::bad_alloc On allocation error. The object is left unchanged. 413 * 447 * @throws std::bad_alloc On allocation error. The object is left unchanged. 414 448 * @returns Reference to the object. 415 449 */ … … 420 454 * 421 455 * @param uc The unicode code point to append. 422 * 423 * @throws std::bad_alloc On allocation error. The object is left unchanged. 424 * 456 * @throws std::bad_alloc On allocation error. The object is left unchanged. 425 457 * @returns Reference to the object. 426 458 */ … … 430 462 * Shortcut to append(), RTCString variant. 431 463 * 432 * @param that The string to append. 433 * 464 * @param rThat The string to append. 434 465 * @returns Reference to the object. 435 466 */ … … 442 473 * Shortcut to append(), const char* variant. 443 474 * 444 * @param pszThat The C string to append. 445 * 475 * @param pszThat The C-style string to append. 446 476 * @returns Reference to the object. 447 477 */ … … 579 609 * Returns the byte at the given index, or a null byte if the index is not 580 610 * smaller than length(). This does _not_ count codepoints but simply points 581 * into the member C string.611 * into the member C-style string. 582 612 * 583 613 * @param i The index into the string buffer. … … 592 622 593 623 /** 594 * Returns the contained string as a C-style const char* pointer. 595 * This never returns NULL; if the string is empty, this returns a 596 * pointer to static null byte. 624 * Returns the contained string as a const C-style string pointer. 625 * 626 * This never returns NULL; if the string is empty, this returns a pointer to 627 * static null byte. 597 628 * 598 629 * @returns const pointer to C-style string. -
trunk/src/VBox/Runtime/common/string/ministring.cpp
r68094 r68123 50 50 51 51 52 RTCString &RTCString::assign(const RTCString &a_rSrc) 53 { 54 size_t const cchSrc = a_rSrc.length(); 55 if (cchSrc > 0) 56 { 57 reserve(cchSrc + 1); 58 memcpy(m_psz, a_rSrc.c_str(), cchSrc); 59 m_psz[cchSrc] = '\0'; 60 m_cch = cchSrc; 61 return *this; 62 } 63 setNull(); 64 return *this; 65 66 } 67 68 RTCString &RTCString::assign(const char *a_pszSrc) 69 { 70 if (a_pszSrc) 71 { 72 size_t cchSrc = strlen(a_pszSrc); 73 if (cchSrc) 74 { 75 reserve(cchSrc + 1); 76 memcpy(m_psz, a_pszSrc, cchSrc); 77 m_psz[cchSrc] = '\0'; 78 m_cch = cchSrc; 79 return *this; 80 } 81 } 82 setNull(); 83 return *this; 84 } 85 86 RTCString &RTCString::assign(const RTCString &a_rSrc, size_t a_offSrc, size_t a_cchSrc /*= npos*/) 87 { 88 AssertReturn(&a_rSrc != this, *this); 89 if (a_offSrc < a_rSrc.length()) 90 { 91 size_t cchMax = a_rSrc.length() - a_offSrc; 92 if (a_cchSrc > cchMax) 93 a_cchSrc = cchMax; 94 reserve(a_cchSrc + 1); 95 memcpy(m_psz, a_rSrc.c_str(), a_cchSrc); 96 m_psz[a_cchSrc] = '\0'; 97 m_cch = a_cchSrc; 98 } 99 else 100 setNull(); 101 return *this; 102 } 103 104 RTCString &RTCString::assign(const char *a_pszSrc, size_t a_cchSrc) 105 { 106 if (a_cchSrc) 107 { 108 a_cchSrc = RTStrNLen(a_pszSrc, a_cchSrc); 109 reserve(a_cchSrc + 1); 110 memcpy(m_psz, a_pszSrc, a_cchSrc); 111 m_psz[a_cchSrc] = '\0'; 112 m_cch = a_cchSrc; 113 } 114 else 115 setNull(); 116 return *this; 117 } 118 119 RTCString &RTCString::assign(size_t a_cTimes, char a_ch) 120 { 121 reserve(a_cTimes + 1); 122 memset(m_psz, a_ch, a_cTimes); 123 return *this; 124 } 125 126 52 127 RTCString &RTCString::printf(const char *pszFormat, ...) 53 128 {
Note:
See TracChangeset
for help on using the changeset viewer.