1/* 2 * Copyright 2007-2014 Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Stefano Ceccherini, burton666@freemail.it 7 * Marc Flerackers, mflerackers@androme.be 8 * Niels Sascha Reedijk, niels.reedijk@gmail.com 9 * John Scipione, jscipione@gmail.com 10 * Oliver Tappe, openbeos@hirschaefer.de 11 * 12 * Corresponds to: 13 * headers/os/support/String.h rev 50791 14 * src/kits/support/String.cpp rev 52836 15 */ 16 17 18/*! 19 \file String.h 20 \ingroup support 21 \ingroup libbe 22 \brief Defines the BString class and global operators and functions for 23 handling strings. 24*/ 25 26 27/*! 28 \class BString String.h 29 \ingroup support 30 \ingroup libbe 31 \brief String class supporting common string operations. 32 33 BString is a string allocation and manipulation class. The object 34 takes care to allocate and free memory for you, so it will always be 35 "big enough" to store your strings. 36 37 While BString is in essence a wrapper around a byte-array, which can always 38 be accessed with the BString::String() method, it does have some 39 understanding of UTF-8 and it can be used for the manipulation of UTF-8 40 strings. For all operations that perform on bytes, there is an equivalent 41 that operates on UTF-8 strings. See for example the BString::CopyInto() and 42 BString::CopyCharsInto() methods. The main difference is that if there are 43 any position argumens, the regular method counts the bytes and the 44 Chars methods counts characters. 45 46 \since BeOS R5 47*/ 48 49 50/*! 51 \fn BString::BString() 52 \brief Creates an empty BString. 53 54 \since BeOS R5 55*/ 56 57 58/*! 59 \fn BString::BString(const char* string) 60 \brief Creates and initializes a BString from \a string. 61 62 \param string The \a string to copy from. 63 64 \since BeOS R5 65*/ 66 67 68/*! 69 \fn BString::BString(const BString& string) 70 \brief Creates and initializes a BString as a copy of another \a string. 71 72 \param string The BString object to copy from. 73 74 \since BeOS R5 75*/ 76 77 78/*! 79 \fn BString::BString(const char* string, int32 maxLength) 80 \brief Creates and initializes a BString from a \a string up to 81 \a maxLength characters. 82 83 If \a maxLength is greater than the length of the source \a string then the 84 entire source \a string is copied. If \a maxLength is less than or equal 85 to 0 then the result is an empty BString. 86 87 \warning In BeOS R5 passing in a negative \a maxLength argument will copy 88 the entire \a string. 89 90 \param string The \a string data to initialize the BString to. 91 \param maxLength Maximum number of characters (bytes) to copy. 92 93 \since BeOS R5 94*/ 95 96 97/*! 98 \fn BString::~BString() 99 \brief Free all resources associated with the object. 100 101 The destructor also frees the internal buffer associated with the string. 102 103 \since BeOS R5 104*/ 105 106 107/*! 108 \name Access 109*/ 110 111 112//! @{ 113 114 115/*! 116 \fn const char* BString::String() const 117 \brief Return a pointer to the object string, \c NUL terminated. 118 119 The pointer to the object string is guaranteed to be \c NUL 120 terminated. You can't modify or free the pointer. Once the BString 121 object is deleted, the pointer becomes invalid. 122 123 If you want to manipulate the internal string of the object directly, 124 have a look at LockBuffer(). 125 126 \return A pointer to the object string. 127 128 \since BeOS R5 129*/ 130 131 132/*! 133 \fn int32 BString::Length() const 134 \brief Get the length of the string in bytes. 135 136 \return An integer with the length of the string, measured in bytes. 137 138 \sa CountChars() 139 140 \since BeOS R5 141*/ 142 143 144/*! 145 \fn int32 BString::CountChars() const 146 \brief Returns the length of the object measured in characters. 147 148 BString is somewhat aware of UTF-8 characters, so this method will count 149 the actual number of characters in the string. 150 151 \return An integer which is the number of characters in the string. 152 153 \sa Length() 154 155 \since BeOS R5 156*/ 157 158 159/*! 160 \fn int32 BString::CountBytes(int32 fromCharOffset, int32 charCount) const 161 \brief Count the number of bytes starting from a specified character 162 163 BString is somewhat aware of UTF-8 characters, which can take up more than 164 one byte. With this method you can count the number of bytes a subset of 165 the string contains. 166 167 \warning This method does not check whether the input is outside of the 168 boundaries, so make sure that you check your input values. 169 170 \param fromCharOffset The index of the character (not the byte!) from 171 which to start the count 172 \param charCount The number of characters to count 173 174 \return An integer with the number of bytes. 175 176 \since Haiku R1 177*/ 178 179 180/*! 181 \fn bool BString::IsEmpty() const 182 \brief Check whether the string is empty. 183 184 \return Returns \c true if the string is empty. 185 186 \since Haiku R1 187*/ 188 189 190/*! 191 \fn uint32 BString::HashValue() const 192 \brief Return a hash value for the current string 193 194 \sa HashValue(const char*) 195 196 \since Haiku R1 197*/ 198 199 200/*! 201 \fn static uint32 BString::HashValue(const char* string) 202 \brief Return the hash value of a specified \c string 203 204 This allows you to use the BString::HashValue() method on any arbitrary 205 \c string. 206 207 \param string The string that you want to have hashed. 208 209 \sa HashValue() 210 211 \since Haiku R1 212*/ 213 214 215//! @} 216 217 218/*! 219 \name Assignment 220 221 To assign a string to the object, thus overriding the previous string 222 that was stored, there are different methods to use. Use one of the 223 overloaded Adopt() methods to take over data from another object. Use 224 one of the assignment operators to copy data from another object, or 225 use one of the SetTo() methods for more advanced copying. 226*/ 227 228 229//! @{ 230 231 232/*! 233 \fn BString& BString::operator=(const BString& string) 234 \brief Re-initialize the object to a copy of the data of a BString. 235 236 \param string The \a string to copy. 237 238 \return The function always returns \c *this. 239 240 \sa Adopt(BString&) 241 \sa SetTo(const BString&, int32) 242 243 \since BeOS R5 244*/ 245 246 247/*! 248 \fn BString& BString::operator=(const char* str) 249 \brief Re-initialize the BString to a copy of the data of a string. 250 251 \param str The string data to re-initialize the BString to. 252 253 \return This method always returns \c *this. 254 255 \sa SetTo(const char*, int32) 256 257 \since BeOS R5 258*/ 259 260 261/*! 262 \fn BString& BString::operator=(char c) 263 \brief Re-initialize the BString to a character. 264 265 \param c The \c char to re-initialize the BString to. 266 267 \return This method always returns \c *this. 268 269 \since BeOS R5 270*/ 271 272 273/*! 274 \fn BString& BString::SetTo(const char* str) 275 \brief Re-initialize the BString to a copy of the data of a string. 276 277 This method calls operator=(const char*). 278 279 \param str The string data to re-initialize the BString to. 280 281 \return This method always returns \c *this. 282 283 \sa SetTo(const char*, int32) 284 285 \since BeOS R5 286*/ 287 288 289/*! 290 \fn BString& BString::SetTo(const char* str, int32 maxLength) 291 \brief Re-initialize the BString to a copy of the data of a string. 292 293 \param str The string data to re-initialize the BString to. 294 \param maxLength Maximum number of characters (bytes) to copy. 295 296 \return This method always returns \c *this. 297 298 \sa operator=(const char*) 299 300 \since BeOS R5 301*/ 302 303 304/*! 305 \fn BString& BString::SetTo(const BString& from) 306 \brief Re-initialize the BString to a copy of the data of a BString. 307 308 \param from The string data to re-initialize the BString to. 309 310 \return The function always returns \c *this. 311 312 \sa SetTo(const BString&, int32) 313 \sa Adopt(BString&) 314 315 \since BeOS R5 316*/ 317 318 319/*! 320 \fn BString& BString::SetTo(const BString& string, int32 maxLength) 321 \brief Re-initialize the string to a copy of the given BString object. 322 323 \param string The string data to re-initialize the BString to. 324 \param maxLength Maximum number of characters (bytes) to copy. 325 326 \return The function always returns \c *this. 327 328 \sa operator=(const BString&) 329 \sa Adopt(BString&, int32) 330 331 \since BeOS R5 332*/ 333 334 335/*! 336 \fn BString& BString::Adopt(BString& from) 337 \brief Adopt the data of the given BString object. 338 339 This method adopts the data from a BString removing the data from \a from 340 and putting it into the BString. 341 342 \warning The object that is adopted from is not deleted, only its private 343 data is initialized to a \c NULL string. If the \a from object 344 was created on the heap you need to clean it up yourself. 345 346 \param from The string data to adopt. 347 348 \return The function always returns \c *this. 349 350 \sa operator=(const BString&) 351 352 \since BeOS R5 353*/ 354 355 356/*! 357 \fn BString& BString::Adopt(BString& from, int32 maxLength) 358 \brief Adopt the data of the given BString object up to \a maxLength 359 characters. 360 361 This method adopts the data from a BString removing the data from \a from 362 and putting it into the BString. 363 364 \param from The string object to adopt. 365 \param maxLength Maximum number of characters (bytes) to adopt. 366 367 \return The function always returns \c *this. 368 369 \sa SetTo(const BString&, int32) 370 371 \since BeOS R5 372*/ 373 374 375/*! 376 \fn BString& BString::SetTo(char c, int32 count) 377 \brief Re-initialize the object to a string composed of a character you 378 specify. 379 380 This method lets you specify the length of a string and what character 381 you want the string to contain repeatedly. 382 383 \param c The character you want to initialize the BString. 384 \param count The length of the string. 385 386 \return The function always returns \c *this. 387 388 \sa operator=(char c) 389 390 \since BeOS R5 391*/ 392 393 394/*! 395 \fn BString& BString::SetToChars(const char* string, int32 charCount) 396 \brief UTF-8 aware version of SetTo(const char*, int32) 397 398 \param string The \a string to copy. 399 \param charCount The number of UTF-8 characters to copy. 400 401 \see SetTo(const char*, int32) 402 403 \since Haiku R1 404*/ 405 406 407/*! 408 \fn BString& BString::SetToChars(const BString& string, int32 charCount) 409 \brief UTF-8 aware version of SetTo(BString&, int32) 410 411 \param string The \a string to copy. 412 \param charCount The number of UTF-8 characters to copy. 413 414 \see SetTo(BString&, int32) 415 416 \return This method always returns \c *this. 417 418 \since Haiku R1 419*/ 420 421 422/*! 423 \fn BString& BString::AdoptChars(BString& from, int32 charCount) 424 \brief UTF-8 aware version of Adopt(BString&, int32) 425 426 \param from The string data to start adopting from. 427 \param charCount Number of UTF-8 characters to adopt. 428 429 \return This method always returns \c *this. 430 431 \since Haiku R1 432*/ 433 434 435/*! 436 \fn BString& BString::SetToFormat(const char* format, ...) 437 \brief Sets the string to a formatted string ala <tt>sprintf()</tt>. 438 439 \param format The \a format string to use. 440 \param ... The rest of the parameters that are filled into \a format. 441 442 \return This method always returns \c *this. 443 444 \since Haiku R1 445*/ 446 447 448/*! 449 \fn BString& BString::SetToFormatVarArgs(const char* format, va_list args) 450 \brief Sets the string to a formatted string ala <tt>sprintf()</tt>. 451 452 \param format The \a format string to use. 453 \param args The rest of the parameters that are filled into \a format. 454 455 \return This method always returns \c *this. 456 457 \since Haiku R1 458*/ 459 460 461/*! 462 \fn int BString::ScanWithFormat(const char* format, ...) 463 \brief Parse a formatted string and save elements to variables ala 464 <tt>scanf()</tt>. 465 466 \param format The \a format string to use. 467 \param ... The parameters that you want to store the parsed data into. 468 469 \return This method returns the number of items that were parsed. 470 471 \since Haiku R1 472*/ 473 474 475/*! 476 \fn int BString::ScanWithFormatVarArgs(const char* format, va_list args) 477 \brief Parse a formatted string and save elements to variables ala 478 <tt>scanf()</tt>. 479 480 \param format The \a format string to use. 481 \param args The parameters that you want to store the parsed data into. 482 483 \return This method returns the number of items that were parsed. 484 485 \since Haiku R1 486*/ 487 488 489//! @} 490 491 492/*! 493 \name Substring Copying 494*/ 495 496 497//! @{ 498 499 500/*! 501 \fn BString& BString::CopyInto(BString& into, int32 fromOffset, 502 int32 length) const 503 \brief Copy the object's data (or part of it) into another BString. 504 505 This methods makes sure you don't copy more bytes than are available 506 in the string. If the length exceeds the length of the string, it only 507 copies the number of characters that are actually available. 508 509 \param into The BString to copy into. 510 \param fromOffset The (zero-based) offset where to begin the copy. 511 \param length The number of bytes to copy. 512 513 \return This method always returns a pointer to the string passed as the 514 \c into parameter. 515 516 \since BeOS R5 517*/ 518 519 520/*! 521 \fn void BString::CopyInto(char* into, int32 fromOffset, int32 length) const 522 \brief Copy the BString data (or part of it) into the supplied buffer. 523 524 This methods makes sure you don't copy more bytes than are available 525 in the string. If the length exceeds the length of the string, it only 526 copies the number of characters that are actually available. 527 528 It's up to you to make sure your buffer is large enough. 529 530 \param into The buffer where to copy the object. 531 \param fromOffset The (zero-based) offset where to begin the copy. 532 \param length The number of bytes to copy. 533 534 \since BeOS R5 535*/ 536 537 538/*! 539 \fn BString& BString::CopyCharsInto(BString& into, int32 fromOffset, 540 int32 charCount) const 541 \brief UTF-8 aware version of CopyInto(BString&, int32, int32) const. 542 543 \param into The BString to copy into. 544 \param fromOffset The (zero-based) offset in bytes where to begin the copy. 545 \param charCount The number of UTF-8 characters to copy. 546 547 \return This method always returns a pointer to the string passed as the 548 \c into parameter. 549 550 \see CopyInto(BString&, int32, int32) const 551 552 \since Haiku R1 553*/ 554 555 556/*! 557 \fn bool BString::CopyCharsInto(char* into, int32* intoLength, 558 int32 fromCharOffset, int32 charCount) const 559 \brief UTF-8 aware version of CopyInto(char*, int32, int32) const. 560 561 \param into The buffer where to copy the object. 562 \param intoLength The length of \a into in bytes. 563 \param fromCharOffset The (zero-based) offset UTF-8 characters where to 564 begin the copy. 565 \param charCount The number of UTF-8 characters to copy. 566 567 \see CopyInto(char*, int32, int32) const 568 569 \return \c false if \a into was \c NULL, \c true otherwise. 570 571 \since Haiku R1 572*/ 573 574 575/*! 576 \fn bool BString::Split(const char* separator, bool noEmptyStrings, 577 BStringList& _list) const 578 \brief Split the string by the \a separator chars into \a _list. 579 580 \param separator The list of \a separator characters to split on. 581 \param noEmptyStrings If \c true, do not add empty strings to \a _list. 582 \param _list The BStringList to add the strings into. 583 584 \since Haiku R1 585*/ 586 587 588//! @} 589 590 591/*! 592 \name Appending 593*/ 594 595 596//! @{ 597 598 599/*! 600 \fn BString& BString::operator+=(const BString& string) 601 \brief Append the given \a string to the end of the BString 602 603 \param string The string to append. 604 605 \return This method always returns \c *this. 606 607 \sa Append(const BString&, int32) 608 609 \since BeOS R5 610*/ 611 612 613/*! 614 \fn BString& BString::operator+=(const char* str) 615 \brief Append the given string to the end of the BString. 616 617 \param str A pointer to the NULL-terminated string to append. 618 619 \return This method always returns \c *this. 620 621 \sa Append(const char*, int32) 622 623 \since BeOS R5 624*/ 625 626 627/*! 628 \fn BString& BString::operator+=(char c) 629 \brief Append the given character to the end of the BString. 630 631 \param c The character to append. 632 633 \return This method always returns \c *this. 634 635 \sa Append(char, int32) 636*/ 637 638 639/*! 640 \fn BString& BString::operator+=(const BString& string) 641 \brief Append the given \a string to the end of the BString. 642 643 \param string The string to append. 644 645 \return This method always returns \c *this. 646 647 \sa Append(const BString&, int32) 648*/ 649 650 651/*! 652 \fn BString& BString::Append(const BString& string) 653 \brief Append the given \a string to the end of the BString. 654 655 \param string The string to append. 656 657 \return This method always returns \c *this. 658 659 \sa Append(const BString&, int32) 660 661 \since BeOS R5 662*/ 663 664 665/*! 666 \fn BString& BString::Append(const char* str) 667 \brief Append the string data to the end of the BString. 668 669 This method calls operator+=(const char *str). 670 671 \sa Append(const char*, int32) 672 673 \since BeOS R5 674*/ 675 676 677/*! 678 \fn BString& BString::Append(const BString& string, int32 length) 679 \brief Append a part of the given \a string to the end of the BString. 680 681 \param string The BString to append. 682 \param length The maximum number of bytes to append. 683 684 \return This method always returns \c *this. 685 686 \sa operator+=(const BString&) 687 688 \since BeOS R5 689*/ 690 691 692/*! 693 \fn BString& BString::Append(const char* str, int32 length) 694 \brief Append a part of the given string to end of the BString. 695 696 \param str A pointer to the string to append. 697 \param length The maximum number of bytes to append. 698 699 \return This method always returns \c *this. 700 701 \sa operator+=(const char*) 702 703 \since BeOS R5 704*/ 705 706 707/*! 708 \fn BString& BString::Append(char c, int32 count) 709 \brief Append the given character repeatedly to the end of the BString. 710 711 \param c The character to append. 712 \param count The number of times this character should be appended. 713 714 \return This method always returns \c *this. 715 716 \sa operator+=(char c) 717 718 \since BeOS R5 719*/ 720 721 722/*! 723 \fn BString& BString::AppendChars(const BString& string, int32 charCount) 724 \brief UTF-8 aware version of Append(const BString&, int32). 725 726 \param string The \a string to append. 727 \param charCount The maximum number of UTF-8 characters to append. 728 729 \return This method always returns \c *this. 730 731 \see Append(const BString&, int32) 732 733 \since Haiku R1 734*/ 735 736 737/*! 738 \fn BString& BString::AppendChars(const char* string, int32 charCount) 739 \brief UTF-8 aware version of Append(const char*, int32). 740 741 \param string The \a string to append. 742 \param charCount The maximum number of UTF-8 characters to append. 743 744 \return This method always returns \c *this. 745 746 \see Append(const char*, int32) 747 748 \since Haiku R1 749*/ 750 751 752//! @} 753 754 755/*! 756 \name Prepending 757*/ 758 759 760//! @{ 761 762 763/*! 764 \fn BString& BString::Prepend(const char* str) 765 \brief Prepend the given string to the beginning of the BString. 766 767 \param str The \a string to prepend. 768 769 \return This method always returns \c *this. 770 771 \sa Prepend(const char*, int32) 772 773 \since BeOS R5 774*/ 775 776 777/*! 778 \fn BString& BString::Prepend(const BString& string) 779 \brief Prepend the given BString to the beginning of the BString. 780 781 \param string The \a string to prepend. 782 783 \return This method always returns \c *this. 784 785 \sa Prepend(const BString&, int32) 786 787 \since BeOS R5 788*/ 789 790 791/*! 792 \fn BString& BString::Prepend(const char* str, int32 length) 793 \brief Prepend the given string to the beginning of the BString. 794 795 \param str The \a string to prepend. 796 \param length The maximum number of bytes to prepend. 797 798 \return This method always returns \c *this. 799 800 \sa Prepend(const char*) 801 802 \since BeOS R5 803*/ 804 805 806/*! 807 \fn BString& BString::Prepend(const BString& string, int32 length) 808 \brief Prepend the given BString to the beginning of the BString. 809 810 \param string The \a string to prepend. 811 \param length The maximum number of bytes to prepend. 812 813 \return This method always returns \c *this. 814 815 \sa Prepend(const BString&) 816 817 \since BeOS R5 818*/ 819 820 821/*! 822 \fn BString& BString::Prepend(char c, int32 count) 823 \brief Prepend the given character \a count times to the beginning of the 824 BString. 825 826 \param c The character to prepend. 827 \param count The number of times this character should be prepended. 828 829 \return This method always returns \c *this. 830 831 \since BeOS R5 832*/ 833 834 835/*! 836 \fn BString& BString::PrependChars(const char* string, int32 charCount) 837 \brief UTF-8 aware version of Prepend(const char*, int32). 838 839 \param string The \a string to prepend. 840 \param charCount The maximum number of UTF-8 characters to prepend. 841 842 \return This method always returns \c *this. 843 844 \see Prepend(const char*, int32) 845 846 \since Haiku R1 847*/ 848 849 850/*! 851 \fn BString& BString::PrependChars(const BString& string, int32 charCount) 852 \brief UTF-8 aware version of Prepend(const BString&, int32). 853 854 \param string The \a string to prepend. 855 \param charCount The maximum number of UTF-8 characters to prepend. 856 857 \return This method always returns \c *this. 858 859 \see Prepend(const BString&, int32) 860 861 \since Haiku R1 862*/ 863 864 865//! @} 866 867 868/*! 869 \name Inserting 870*/ 871 872 873//! @{ 874 875 876/*! 877 \fn BString& BString::Insert(const char* string, int32 position) 878 \brief Inserts the given string at the given position into the BString 879 data. 880 881 \param string The \a string to insert. 882 \param position The offset in bytes where to insert the \a string into 883 the BString's data. 884 885 \return This method always returns \c *this. 886 887 \sa Insert(const char*, int32, int32) 888 \sa Insert(const char*, int32, int32, int32) 889 890 \since BeOS R5 891*/ 892 893 894/*! 895 \fn BString& BString::Insert(const char* string, int32 length, 896 int32 position) 897 \brief Inserts the given string at the given position into the BString 898 data. 899 900 \param string The \a string to insert. 901 \param length The number of bytes to insert. 902 \param position The offset in bytes into the data of the BString where to 903 insert the string. 904 905 \return This method always returns \c *this. 906 907 \sa Insert(const char*, int32) 908 \sa Insert(const char*, int32, int32, int32) 909 910 \since BeOS R5 911*/ 912 913 914/*! 915 \fn BString& BString::Insert(const char* string, int32 fromOffset, 916 int32 length, int32 position) 917 \brief Inserts the given string at the given position into the BString 918 data. 919 920 \param string The \a string to insert. 921 \param fromOffset The offset in bytes in the \a string to be inserted. 922 \param length The number of bytes to insert. 923 \param position The offset in bytes into the data of the BString where to 924 insert the string. 925 926 \return This method always returns \c *this. 927 928 \sa Insert(const char*, int32) 929 \sa Insert(const char*, int32, int32) 930 931 \since BeOS R5 932*/ 933 934 935/*! 936 \fn BString& BString::Insert(const BString& string, int32 position) 937 \brief Inserts the given BString at the given position into the BString 938 data. 939 940 \param string The \a string to insert. 941 \param position The offset in bytes into the data of the BString where to 942 insert the string. 943 944 \return This method always returns \c *this. 945 946 \sa Insert(const BString&, int32, int32) 947 \sa Insert(const BString&, int32, int32, int32) 948 949 \since BeOS R5 950*/ 951 952 953/*! 954 \fn BString& BString::Insert(const BString& string, int32 length, int32 position) 955 \brief Inserts the given BString at the given position into the BString 956 data. 957 958 \param string The \a string to insert. 959 \param length The number of bytes to insert. 960 \param position The offset in bytes into the data of the BString where to 961 insert the string. 962 963 \return This method always returns \c *this. 964 965 \sa Insert(const BString&, int32) 966 \sa Insert(const BString&, int32, int32, int32) 967 968 \since BeOS R5 969*/ 970 971 972/*! 973 \fn BString& BString::Insert(const BString& string, int32 fromOffset, 974 int32 length, int32 position) 975 \brief Inserts the given string at the given position into the BString 976 data. 977 978 \param string The \a string to insert. 979 \param fromOffset The offset in bytes of the string to be inserted. 980 \param length The amount of bytes to insert. 981 \param position The offset in bytes into the data of the BString where to 982 insert the string. 983 984 \return This method always returns \c *this. 985 986 \sa Insert(const BString&, int32) 987 \sa Insert(const BString&, int32, int32) 988 989 \since BeOS R5 990*/ 991 992 993/*! 994 \fn BString& BString::Insert(char c, int32 count, int32 pos) 995 \brief Inserts the given character repeatedly at the given position 996 into the BString data. 997 998 \param c The character to insert. 999 \param count The number of times to insert the character. 1000 \param pos The offset in bytes into the data of the BString where to 1001 insert the string. 1002 1003 \return This method always returns \c *this. 1004 1005 \since BeOS R5 1006*/ 1007 1008 1009/*! 1010 \fn BString& BString::InsertChars(const char* string, int32 charPosition) 1011 \brief UTF-8 aware version of Insert(const char*, int32). 1012 1013 \param string The \a string to insert. 1014 \param charPosition The offset in UTF-8 characters where to insert 1015 the string into the data of the BString. 1016 1017 \return This method always returns \c *this. 1018 1019 \see Insert(const char*, int32) 1020 1021 \since Haiku R1 1022*/ 1023 1024 1025/*! 1026 \fn BString& BString::InsertChars(const char* string, int32 charCount, 1027 int32 charPosition) 1028 \brief UTF-8 aware version of Insert(const char*, int32, int32). 1029 1030 \param string The \a string to insert. 1031 \param charCount The number of UTF-8 characters to insert. 1032 \param charPosition The offset in UTF-8 characters where to insert 1033 the string into the data of the BString. 1034 1035 \return This method always returns \c *this. 1036 1037 \see Insert(const char*, int32, int32) 1038 1039 \since Haiku R1 1040*/ 1041 1042 1043/*! 1044 \fn BString& BString::InsertChars(const char* string, int32 fromCharOffset, 1045 int32 charCount, int32 charPosition) 1046 \brief UTF-8 aware version of Insert(const char*, int32, int32, int32). 1047 1048 \param string The \a string to insert. 1049 \param fromCharOffset The offset in UTF-8 characters of the string to be 1050 inserted. 1051 \param charCount The number of UTF-8 characters to insert. 1052 \param charPosition The offset in UTF-8 characters where to insert 1053 the string into the data of the BString. 1054 1055 \return This method always returns \c *this. 1056 1057 \see Insert(const char*, int32, int32, int32) 1058 1059 \since Haiku R1 1060*/ 1061 1062 1063/*! 1064 \fn BString& BString::InsertChars(const BString& string, int32 charPosition) 1065 \brief UTF-8 aware version of Insert(const BString&, int32). 1066 1067 \param string The \a string to insert. 1068 \param charPosition The offset in UTF-8 characters where to insert 1069 the string into the data of the BString. 1070 1071 \return This method always returns \c *this. 1072 1073 \see Insert(const BString&, int32) 1074 1075 \since Haiku R1 1076*/ 1077 1078 1079/*! 1080 \fn BString& BString::InsertChars(const BString& string, int32 charCount, 1081 int32 charPosition) 1082 \brief UTF-8 aware version of Insert(const BString&, int32, int32). 1083 1084 \param string The \a string to insert. 1085 \param charCount The number of UTF-8 characters to insert. 1086 \param charPosition The offset in UTF-8 characters where to insert 1087 the string into the data of the BString. 1088 1089 \return This method always returns \c *this. 1090 1091 \see Insert(const BString&, int32, int32) 1092 1093 \since Haiku R1 1094*/ 1095 1096 1097/*! 1098 \fn BString& BString::InsertChars(const BString& string, int32 fromCharOffset, 1099 int32 charCount, int32 charPosition) 1100 \brief UTF-8 aware version of Insert(const BString&, int32, int32, int32). 1101 1102 \param string The \a string to insert. 1103 \param fromCharOffset The offset in UTF-8 characters of the string to be 1104 inserted. 1105 \param charCount The number of UTF-8 characters to insert. 1106 \param charPosition The offset in UTF-8 characters where to insert 1107 the string into the data of the BString. 1108 1109 \return This method always returns \c *this. 1110 1111 \see Insert(const BString&, int32, int32, int32) 1112 1113 \since Haiku R1 1114*/ 1115 1116 1117//! @} 1118 1119 1120/*! 1121 \name Removing 1122*/ 1123 1124 1125//! @{ 1126 1127 1128/*! 1129 \fn BString& BString::Trim() 1130 \brief Removes spaces from the beginning and end of the string. 1131 1132 The definition of a space is set by the <tt>isspace()</tt> function. 1133 1134 \return This method always returns \c *this. 1135 1136 \since Haiku R1 1137*/ 1138 1139 1140 1141/*! 1142 \fn BString& BString::Truncate(int32 newLength, bool lazy) 1143 \brief Truncate the string to the new length. 1144 1145 \param newLength The new length of the string in bytes. 1146 \param lazy If true, the memory-optimization is postponed until later. 1147 1148 \return This method always returns \c *this. 1149 1150 \since BeOS R5 1151*/ 1152 1153 1154/*! 1155 \fn BString& BString::TruncateChars(int32 newCharCount, bool lazy) 1156 \brief UTF-8 aware version of Truncate(int32, bool). 1157 1158 \param newCharCount The new length of the string in UTF-8 characters. 1159 \param lazy If true, the memory-optimization is postponed until later. 1160 1161 \see Truncate(int32, bool) 1162 1163 \since Haiku R1 1164*/ 1165 1166 1167/*! 1168 \fn BString& BString::Remove(int32 from, int32 length) 1169 \brief Remove some bytes, starting at the given offset 1170 1171 \param from The offset in bytes to start removing. 1172 \param length The number of bytes to remove. 1173 1174 \return This function always returns \c *this. 1175 1176 \since BeOS R5 1177*/ 1178 1179 1180/*! 1181 \fn BString& BString::RemoveChars(int32 fromCharOffset, int32 charCount) 1182 \brief UTF-8 aware version of Remove(int32, int32). 1183 1184 \param fromCharOffset The offset in UTF-8 characters to start removing. 1185 \param charCount The number of UTF-8 characters to remove. 1186 1187 \return This function always returns \c *this. 1188 1189 \see Remove(int32, int32) 1190 1191 \since Haiku R1 1192*/ 1193 1194 1195/*! 1196 \fn BString& BString::RemoveFirst(const BString& string) 1197 \brief Remove the first occurrence of the given BString. 1198 1199 \param string The BString to remove. 1200 1201 \return This function always returns \c *this. 1202 1203 \since BeOS R5 1204*/ 1205 1206 1207/*! 1208 \fn BString& BString::RemoveLast(const BString& string) 1209 \brief Remove the last occurrence of the given BString. 1210 1211 \param string The BString to remove. 1212 1213 \return This function always returns \c *this. 1214 1215 \since BeOS R5 1216*/ 1217 1218 1219/*! 1220 \fn BString& BString::RemoveAll(const BString& string) 1221 \brief Remove all occurrences of the given BString. 1222 1223 \param string The BString to remove. 1224 1225 \return This function always returns \c *this. 1226 1227 \since BeOS R5 1228*/ 1229 1230 1231/*! 1232 \fn BString& BString::RemoveFirst(const char* string) 1233 \brief Remove the first occurrence of the given string. 1234 1235 \param string A pointer to the string to remove. 1236 1237 \return This function always returns \c *this. 1238 1239 \since BeOS R5 1240*/ 1241 1242 1243/*! 1244 \fn BString& BString::RemoveLast(const char* string) 1245 \brief Remove the last occurrence of the given string. 1246 1247 \param string A pointer to the string to remove. 1248 1249 \return This function always returns \c *this. 1250 1251 \since BeOS R5 1252*/ 1253 1254 1255/*! 1256 \fn BString& BString::RemoveAll(const char* str) 1257 \brief Remove all occurrences of the given string. 1258 1259 \param str A pointer to the string to remove. 1260 1261 \return This function always returns \c *this. 1262 1263 \since BeOS R5 1264*/ 1265 1266 1267/*! 1268 \fn BString& BString::RemoveSet(const char* setOfCharsToRemove) 1269 \brief Remove all the characters specified. 1270 1271 \param setOfCharsToRemove The set of characters to remove. 1272 1273 \return This function always returns \c *this. 1274 1275 \since BeOS R5 1276*/ 1277 1278 1279/*! 1280 \fn BString& BString::RemoveCharsSet(const char* setOfCharsToRemove) 1281 \brief UTF-8 aware version of RemoveSet(const char*). 1282 1283 \param setOfCharsToRemove The set of characters to remove. 1284 1285 \return This function always returns \c *this. 1286 1287 \see RemoveSet(const char*) 1288 1289 \since Haiku R1 1290*/ 1291 1292 1293/*! 1294 \fn BString& BString::MoveInto(BString& into, int32 from, int32 length) 1295 \brief Move the BString data (or part of it) into another BString. 1296 1297 \param into The BString to move the string into. 1298 \param from The offset (zero-based) in bytes where to begin the move. 1299 \param length The number of bytes to move. 1300 1301 \return This method always returns \c into. 1302 1303 \since BeOS R5 1304*/ 1305 1306 1307/*! 1308 \fn void BString::MoveInto(char* into, int32 from, int32 length) 1309 \brief Move the BString data (or part of it) into the given buffer. 1310 1311 \param into The buffer to move the string into. 1312 \param from The offset (zero-based) in bytes where to begin the move. 1313 \param length The number of bytes to move. 1314 1315 \since BeOS R5 1316*/ 1317 1318 1319/*! 1320 \fn BString& BString::MoveCharsInto(BString& into, int32 fromCharOffset, 1321 int32 charCount) 1322 \brief UTF-8 aware version of MoveInto(BString&, int32, int32) 1323 1324 \param into The BString where to move the string into. 1325 \param fromCharOffset The offset (zero-based) in UTF-8 characters where to 1326 begin the move. 1327 \param charCount The number of UTF-8 characters to move. 1328 1329 \see MoveInto(BString&, int32, int32) 1330 1331 \since Haiku R1 1332*/ 1333 1334 1335/*! 1336 \fn bool BString::MoveCharsInto(char* into, int32* intoLength, 1337 int32 fromCharOffset, int32 charCount) 1338 \brief UTF-8 aware version of MoveInto(char*, int32*, int32, int32). 1339 1340 \param into The buffer to move the string into. 1341 \param intoLength The offset (zero-based) in bytes where to begin the move. 1342 \param fromCharOffset The offset (zero-based) in UTF-8 characters where to 1343 begin the move. 1344 \param charCount The number of UTF-8 characters to move. 1345 1346 \returns \c false if \a into was \c NULL, \c true otherwise. 1347 1348 \see MoveInto(char*, int32*, int32, int32) 1349 1350 \since Haiku R1 1351*/ 1352 1353 1354//! @} 1355 1356 1357/*! 1358 \name Comparison 1359 1360 There are two different comparison methods. First of all there 1361 is the whole range of operators that return a boolean value, secondly 1362 there are methods that return an integer value, both case sensitive 1363 and case insensitive. 1364 1365 There are also global comparison operators and global compare functions. 1366 You might need these in case you have a sort routine that takes a generic 1367 comparison function, such as BList::SortItems(). 1368 See the String.h documentation file to see the specifics, though basically 1369 there are the same as implemented in this class. 1370*/ 1371 1372 1373//! @{ 1374 1375 1376/*! 1377 \fn bool BString::operator<(const BString& string) const 1378 \brief Lexicographically compare if this BString is less than the given 1379 \a string. 1380 1381 \param string The \a string to compare against. 1382 1383 \since BeOS R5 1384*/ 1385 1386 1387/*! 1388 \fn bool BString::operator<=(const BString& string) const 1389 \brief Lexicographically compare if this BString is less than or equal to 1390 the given \a string. 1391 1392 \param string The \a string to compare against. 1393 1394 \since BeOS R5 1395*/ 1396 1397 1398/*! 1399 \fn bool BString::operator==(const BString& string) const 1400 \brief Lexicographically compare if this BString is equal to the given 1401 \a string. 1402 1403 \param string The \a string to compare against. 1404 1405 \since BeOS R5 1406*/ 1407 1408 1409/*! 1410 \fn bool BString::operator>=(const BString& string) const 1411 \brief Lexicographically compare if this BString is greater than or equal 1412 to the given \a string. 1413 1414 \param string The string to compare against. 1415 1416 \since BeOS R5 1417*/ 1418 1419 1420/*! 1421 \fn bool BString::operator>(const BString& string) const 1422 \brief Lexicographically compare if this BString is greater than the given 1423 \a string. 1424 1425 \param string The string to compare against. 1426 1427 \since BeOS R5 1428*/ 1429 1430 1431/*! 1432 \fn bool BString::operator!=(const BString& string) const 1433 \brief Lexicographically compare if this BString is not equal to the given 1434 \a string. 1435 1436 \param string The string to compare against. 1437 1438 \since BeOS R5 1439*/ 1440 1441 1442/*! 1443 \fn bool BString::operator<(const char* string) const 1444 \brief Lexicographically compare if this BString is less than the given 1445 \a string. 1446 1447 \param string The string to compare against. 1448 1449 \since BeOS R5 1450*/ 1451 1452 1453/*! 1454 \fn bool BString::operator<=(const char* string) const 1455 \brief Lexicographically compare if this BString is less than or equal to 1456 the given \a string. 1457 1458 \param string The \a string to compare against. 1459 1460 \since BeOS R5 1461*/ 1462 1463 1464/*! 1465 \fn bool BString::operator==(const char* string) const 1466 \brief Lexicographically compare if this BString is equal to the given 1467 \a string. 1468 1469 \param string The \a string to compare against. 1470 1471 \since BeOS R5 1472*/ 1473 1474 1475/*! 1476 \fn bool BString::operator>=(const char* string) const 1477 \brief Lexicographically compare if this string is more than or equal 1478 to a given \a string. 1479 1480 \param string The \a string to compare against. 1481 1482 \since BeOS R5 1483*/ 1484 1485 1486/*! 1487 \fn bool BString::operator>(const char* string) const 1488 \brief Lexicographically compare if this string is more than a given string. 1489 1490 \param string The \a string to compare against. 1491 1492 \since BeOS R5 1493*/ 1494 1495 1496/*! 1497 \fn bool BString::operator!=(const char* string) const 1498 \brief Lexicographically compare if this string is not equal to a given 1499 string. 1500 1501 \param string The \a string to compare against. 1502 1503 \since BeOS R5 1504*/ 1505 1506 1507/*! 1508 \fn BString::operator const char*() const 1509 \brief Return an empty string. 1510 1511 \return An empty string. 1512 1513 \since Haiku R1 1514*/ 1515 1516 1517/*! 1518 \fn int BString::Compare(const BString& string) const 1519 \brief Lexicographically compare this BString to another \a string. 1520 1521 \param string The \a string to compare against. 1522 1523 \return An int representing the strings relationship to each other. 1524 \retval >0 The BString sorts lexicographically after \a string. 1525 \retval =0 The BString is equal to \a string. 1526 \retval <0 The BString sorts lexicographically before \a string. 1527 1528 \since BeOS R5 1529*/ 1530 1531 1532/*! 1533 \fn int BString::Compare(const char* string) const 1534 \brief Lexicographically compare this BString to another \a string. 1535 1536 \param string The \a string to compare against. 1537 1538 \return An int representing the strings relationship to each other. 1539 \retval >0 The BString sorts lexicographically after \a string. 1540 \retval =0 The BString is equal to \a string. 1541 \retval <0 The BString sorts lexicographically before \a string. 1542 1543 \sa Compare(const BString&) const 1544 1545 \since BeOS R5 1546*/ 1547 1548 1549/*! 1550 \fn int BString::Compare(const BString& string, int32 length) const 1551 \brief Lexicographically compare \a length characters of this BString to 1552 another \a string. 1553 1554 \param string The \a string to compare against. 1555 \param length The number of bytes to compare. 1556 1557 \return An int representing the strings relationship to each other. 1558 \retval >0 The BString sorts lexicographically after \a string. 1559 \retval =0 The BString is equal to \a string. 1560 \retval <0 The BString sorts lexicographically before \a string. 1561 1562 \since BeOS R5 1563*/ 1564 1565 1566/*! 1567 \fn int BString::Compare(const char* string, int32 length) const 1568 \brief Lexicographically compare \a length characters of this BString to 1569 another \a string. 1570 1571 \param string The \a string to compare against. 1572 \param length The number of bytes to compare. 1573 1574 \return An int representing the strings relationship to each other. 1575 \retval >0 The BString sorts lexicographically after \a string. 1576 \retval =0 The BString is equal to \a string. 1577 \retval <0 The BString sorts lexicographically before \a string. 1578 1579 \sa Compare(const BString&, int32) const 1580 1581 \since BeOS R5 1582*/ 1583 1584 1585/*! 1586 \fn int BString::CompareAt(size_t offset, const BString& string, 1587 int32 length) const 1588 \brief Lexicographically compare \a length of characters of this BString to 1589 another \a string, starting at \a offset. 1590 1591 \param offset The offset (in bytes) to start comparison. 1592 \param string The \a string to compare against. 1593 \param length The number of bytes to compare. 1594 1595 \return An int representing the strings relationship to each other. 1596 \retval >0 The BString sorts lexicographically after \a string. 1597 \retval =0 The BString is equal to \a string. 1598 \retval <0 The BString sorts lexicographically before \a string. 1599 1600 \sa Compare(const BString&, int32) const 1601 1602 \since Haiku R1 1603*/ 1604 1605 1606/*! 1607 \fn int BString::CompareChars(const BString& string, int32 charCount) const 1608 \brief UTF-8 aware version of Compare(const BString&, int32). 1609 1610 \param string The \a string to compare against. 1611 \param charCount The number of UTF-8 characters to compare. 1612 1613 \return An int representing the strings relationship to each other. 1614 \retval >0 The BString sorts lexicographically after \a string. 1615 \retval =0 The BString is equal to \a string. 1616 \retval <0 The BString sorts lexicographically before \a string. 1617 1618 \see Compare(const BString&, int32) 1619 1620 \since Haiku R1 1621*/ 1622 1623 1624/*! 1625 \fn int BString::CompareChars(const char* string, int32 charCount) const 1626 \brief UTF-8 aware version of Compare(const char*, int32). 1627 1628 \param string The \a string to compare against. 1629 \param charCount The number of UTF-8 characters to compare. 1630 1631 \return An int representing the strings relationship to each other. 1632 \retval >0 The BString sorts lexicographically after \a string. 1633 \retval =0 The BString is equal to \a string. 1634 \retval <0 The BString sorts lexicographically before \a string. 1635 1636 \see Compare(const char*, int32) 1637 1638 \since Haiku R1 1639*/ 1640 1641 1642/*! 1643 \fn int BString::ICompare(const BString& string) const 1644 \brief Lexicographically compare this BString to another \a string 1645 case-insensitively. 1646 1647 \param string The \a string to compare against. 1648 1649 \return An int representing the strings relationship to each other. 1650 \retval >0 The BString sorts lexicographically after \a string. 1651 \retval =0 The BString is equal to \a string. 1652 \retval <0 The BString sorts lexicographically before \a string. 1653 1654 \sa Compare(const BString&) const 1655 1656 \since BeOS R5 1657*/ 1658 1659 1660/*! 1661 \fn int BString::ICompare(const char* string) const 1662 \brief Lexicographically compare this BString to another \a string 1663 case-insensitively. 1664 1665 \param string The \a string to compare against. 1666 1667 \return An int representing the strings relationship to each other. 1668 \retval >0 The BString sorts lexicographically after \a string. 1669 \retval =0 The BString is equal to \a string. 1670 \retval <0 The BString sorts lexicographically before \a string. 1671 1672 \sa Compare(const BString&) const 1673 1674 \since BeOS R5 1675*/ 1676 1677 1678/*! 1679 \fn int BString::ICompare(const BString& string, int32 length) const 1680 \brief Lexicographically compare \a length characters of this BString 1681 to another \a string. 1682 1683 \param string The \a string to compare against. 1684 \param length The number of characters to compare. 1685 1686 \return An int representing the strings relationship to each other. 1687 \retval >0 The BString sorts lexicographically after \a string. 1688 \retval =0 The BString is equal to \a string. 1689 \retval <0 The BString sorts lexicographically before \a string. 1690 1691 \sa Compare(const BString&, int32) const 1692 1693 \since BeOS R5 1694*/ 1695 1696 1697/*! 1698 \fn int BString::ICompare(const char* string, int32 length) const 1699 \brief Lexicographically compare \a length characters of this BString 1700 to another \a string. 1701 1702 \param string The \a string to compare against. 1703 \param length The number of characters to compare 1704 1705 \return An int representing the strings relationship to each other. 1706 \retval >0 The BString sorts lexicographically after \a string. 1707 \retval =0 The BString is equal to \a string. 1708 \retval <0 The BString sorts lexicographically before \a string. 1709 1710 \sa Compare(const BString&, int32) const 1711 1712 \since BeOS R5 1713*/ 1714 1715 1716//! @} 1717 1718 1719/*! 1720 \name Searching 1721*/ 1722 1723 1724//! @{ 1725 1726 1727/*! 1728 \fn int32 BString::FindFirst(const BString& string) const 1729 \brief Find the first occurrence of the given \a string. 1730 1731 \param string The \a string to search for. 1732 1733 \return The offset (zero-based) into the data where the given BString 1734 was found or \c B_ERROR if we could not find \c string. 1735 1736 \sa IFindFirst(const BString&) const 1737 1738 \since BeOS R5 1739*/ 1740 1741 1742/*! 1743 \fn int32 BString::FindFirst(const char* string) const 1744 \brief Find the first occurrence of the given \a string. 1745 1746 \param string The \a string to search for. 1747 1748 \return The offset (zero-based) into the data where the given string 1749 was found, \c B_BAD_VALUE if the \c string pointer is invalid, 1750 or \c B_ERROR if we could not find \c string. 1751 1752 \sa IFindFirst(const char*) const 1753 \sa StartsWith(const char*) const 1754 \sa StartsWith(const char*, int32) const 1755 1756 \since BeOS R5 1757*/ 1758 1759 1760/*! 1761 \fn int32 BString::FindFirst(const BString& string, int32 fromOffset) const 1762 \brief Find the first occurrence of the given \a string starting from 1763 the given offset. 1764 1765 \param string The \a string to search for. 1766 \param fromOffset The offset in bytes to start the search. 1767 1768 \return An integer which is the offset (zero-based) into the data 1769 where the given BString was found or \c B_ERROR if we could 1770 not find the \c string. 1771 1772 \sa IFindFirst(const BString&, int32) const 1773 \sa StartsWith(const char*, int32) const 1774 1775 \since BeOS R5 1776*/ 1777 1778 1779/*! 1780 \fn int32 BString::FindFirst(const char* string, int32 fromOffset) const 1781 \brief Find the first occurrence of the given \a string, starting from the 1782 given offset. 1783 1784 \param string The \a string to search for. 1785 \param fromOffset The offset in bytes to start the search. 1786 1787 \return The offset (zero-based) into the data where the given string 1788 was found, \c B_BAD_VALUE if the \c string pointer is invalid, 1789 or \c B_ERROR if we could not find the \c string. 1790 1791 \sa IFindFirst(const char*, int32) const 1792 1793 \since BeOS R5 1794*/ 1795 1796 1797/*! 1798 \fn int32 BString::FindFirst(char c) const 1799 \brief Find the first occurrence of the given character. 1800 1801 \param c The character to search for. 1802 1803 \return The offset (zero-based) into the data where the given character 1804 was found, or \c B_ERROR if we could not find the character. 1805 1806 \since BeOS R5 1807*/ 1808 1809 1810/*! 1811 \fn int32 BString::FindFirst(char c, int32 fromOffset) const 1812 \brief Find the first occurrence of the given character, starting from the 1813 given offset. 1814 1815 \param c The character to search for. 1816 \param fromOffset The offset where to start the search. 1817 1818 \return The offset (zero-based) into the data where the given character 1819 was found, or \c B_ERROR if we could not find the character. 1820 1821 \since BeOS R5 1822*/ 1823 1824 1825/*! 1826 \fn int32 BString::FindFirstChars(const BString& string, 1827 int32 fromCharOffset) const 1828 \brief UTF-8 aware version of FindFirst(const BString&, int32). 1829 1830 \param string The \a string to search for. 1831 \param fromCharOffset The offset in UTF-8 characters to start the search. 1832 1833 \return An integer which is the offset (zero-based) into the data 1834 where the given BString was found or \c B_ERROR if we could 1835 not find the \c string. 1836 1837 \see FindFirst(const BString&, int32) 1838 1839 \since Haiku R1 1840*/ 1841 1842 1843/*! 1844 \fn int32 BString::FindFirstChars(const char* string, 1845 int32 fromCharOffset) const 1846 \brief UTF-8 aware version of FindFirst(const char*, int32). 1847 1848 \param string The \a string to search for. 1849 \param fromCharOffset The offset in UTF-8 characters to start the search. 1850 1851 \see FindChars(const char*, int32) 1852 1853 \since Haiku R1 1854*/ 1855 1856 1857/*! 1858 \fn int32 BString::FindLast(const BString& string) const 1859 \brief Find the last occurrence of the given \a string. 1860 1861 \param string The \a string to search for. 1862 1863 \return The offset (zero-based) into the data where the given BString 1864 was found, or \c B_ERROR if we could not find the \c string. 1865 1866 \sa IFindLast(const BString&) const 1867 \sa EndsWith(const BString&) const 1868 1869 \since BeOS R5 1870*/ 1871 1872 1873/*! 1874 \fn int32 BString::FindLast(const char* string) const 1875 \brief Find the last occurrence of the given string. 1876 1877 \param string The string to search for. 1878 1879 \return The offset in bytes (zero-based) into the data where the given 1880 string was found, \c B_BAD_VALUE if the \c string pointer is invalid, 1881 or \c B_ERROR if we could not find the \c string. 1882 1883 \sa IFindLast(const char*) const 1884 \sa EndsWith(const char*) const 1885 \sa EndsWith(const char*, int32) const 1886 1887 \since BeOS R5 1888*/ 1889 1890 1891/*! 1892 \fn int32 BString::FindLast(const BString& string, int32 beforeOffset) const 1893 \brief Find the last occurrence of the given BString, 1894 starting from the given offset, and going backwards. 1895 1896 \param string The BString to search for. 1897 \param beforeOffset The offset in bytes to start the search. 1898 1899 \return The offset (zero-based) into the data where the given BString 1900 was found, or \c B_ERROR if we could not find the \c string. 1901 1902 \sa IFindLast(const BString&, int32) const 1903 1904 \since BeOS R5 1905*/ 1906 1907 1908/*! 1909 \fn int32 BString::FindLast(const char* string, int32 beforeOffset) const 1910 \brief Find the last occurrence of the given string, 1911 starting from the given offset, and going backwards. 1912 1913 \param string The string to search for. 1914 \param beforeOffset The offset in bytes to start the search. 1915 1916 \return The offset (zero-based) into the data where the given string 1917 was found, \c B_BAD_VALUE if the \c string pointer is invalid, 1918 or \c B_ERROR if we could not find the \c string. 1919 1920 \sa IFindLast(const char*, int32) const 1921 1922 \since BeOS R5 1923*/ 1924 1925 1926/*! 1927 \fn int32 BString::FindLast(char c) const 1928 \brief Find the last occurrence of the given character. 1929 1930 \param c The character to search for. 1931 \return The offset (zero-based) into the data where the given BString 1932 was found, or \c B_ERROR if we could not find the character. 1933 1934 \since BeOS R5 1935*/ 1936 1937 1938/*! 1939 \fn int32 BString::FindLast(char c, int32 beforeOffset) const 1940 \brief Find the last occurrence of the given character, 1941 starting from the given offset going backwards from the end. 1942 1943 \param c The character to search for. 1944 \param beforeOffset The offset in bytes to start the search. 1945 1946 \return The offset (zero-based) into the data where the given character 1947 was found, or \c B_ERROR Could not find the character. 1948 1949 \since BeOS R5 1950*/ 1951 1952 1953/*! 1954 \fn int32 BString::FindLastChars(const BString& string, 1955 int32 beforeCharOffset) const 1956 \brief UTF-8 aware version of FindLast(const BString&, int32). 1957 1958 \param string The BString to search for. 1959 \param beforeCharOffset The offset in UTF-8 characters to start the search. 1960 1961 \return The offset in bytes (zero-based) into the data where the given 1962 BString was found, or \c B_ERROR if we could not find the 1963 \c string. 1964 1965 \see FindLast(const BString&, int32) 1966 1967 \since Haiku R1 1968*/ 1969 1970 1971/*! 1972 \fn int32 BString::FindLastChars(const char* string, 1973 int32 beforeCharOffset) const 1974 \brief UTF-8 aware version of FindLast(const char*, int32). 1975 1976 \param string The string to search for. 1977 \param beforeCharOffset The offset in UTF-8 characters to start the search. 1978 1979 \return The offset in bytes (zero-based) into the data where the given 1980 string was found, \c B_BAD_VALUE if the \c string pointer is 1981 invalid, or \c B_ERROR if we could not find the \c string. 1982 1983 \see FindLast(const char*, int32) 1984 1985 \since Haiku R1 1986*/ 1987 1988 1989/*! 1990 \fn int32 BString::IFindFirst(const BString& string) const 1991 \brief Find the first occurrence of the given \a string case-insensitively. 1992 1993 \copydetails FindFirst(const BString&) const 1994*/ 1995 1996 1997/*! 1998 \fn int32 BString::IFindFirst(const char* string) const 1999 \brief Find the first occurrence of the given \a string case-insensitively. 2000 2001 \param string The \a string to search for. 2002 2003 \copydetails FindFirst(const char*) const 2004*/ 2005 2006 2007/*! 2008 \fn int32 BString::IFindFirst(const BString& string, int32 fromOffset) const 2009 \brief Find the first occurrence of the given BString case-insensitively, 2010 starting from the given offset. 2011 2012 \copydetails FindFirst(const BString&, int32) const 2013*/ 2014 2015 2016/*! 2017 \fn int32 BString::IFindFirst(const char* string, int32 fromOffset) const 2018 \brief Find the first occurrence of the given string case-insensitively, 2019 starting from the given offset. 2020 2021 \copydetails FindFirst(const char*, int32) const 2022*/ 2023 2024 2025/*! 2026 \fn int32 BString::IFindLast(const BString& string) const 2027 \brief Find the last occurrence of the given BString case-insensitively. 2028 2029 \copydetails FindLast(const BString&) const 2030*/ 2031 2032 2033/*! 2034 \fn int32 BString::IFindLast(const char* string) const 2035 \brief Find the last occurrence of the given string case-insensitively. 2036 2037 \copydetails FindLast(const char*) const 2038*/ 2039 2040 2041/*! 2042 \fn int32 BString::IFindLast(const BString& string, int32 beforeOffset) const 2043 \brief Find the last occurrence of the given BString case-insensitively, 2044 starting from the given offset going backwards. 2045 2046 \copydetails FindLast(const BString&, int32) const 2047*/ 2048 2049 2050/*! 2051 \fn int32 BString::IFindLast(const char* string, int32 beforeOffset) const 2052 \brief Find the last occurrence of the given string case-insensitively, 2053 starting from the given offset going backwards. 2054 2055 \copydetails FindLast(const char*, int32) const 2056*/ 2057 2058 2059/*! 2060 \fn bool BString::StartsWith(const BString& string) const 2061 \brief Returns whether or not the BString starts with \a string. 2062 2063 \param string The \a string to search for. 2064 2065 \return \c true if the BString started with \a string, \c false otherwise. 2066 2067 \since Haiku R1 2068*/ 2069 2070 2071/*! 2072 \fn bool BString::StartsWith(const char* string) const 2073 \brief Returns whether or not the BString starts with \a string. 2074 2075 \param string The \a string to search for. 2076 2077 \return \c true if the BString started with \a string, \c false otherwise. 2078 2079 \since Haiku R1 2080*/ 2081 2082 2083/*! 2084 \fn bool BString::StartsWith(const char* string, int32 length) const 2085 \brief Returns whether or not the BString starts with \a length characters 2086 of \a string. 2087 2088 \param string The \a string to search for. 2089 \param length The number of characters (bytes) of \a string to search for. 2090 2091 \return \c true if the BString started with \a length characters of 2092 \a string, \c false otherwise. 2093 2094 \since Haiku R1 2095*/ 2096 2097 2098/*! 2099 \fn bool BString::IStartsWith(const BString& string) const 2100 \brief Returns whether or not the BString starts with \a string 2101 case-insensitively. 2102 2103 \param string The \a string to search for. 2104 2105 \return \c true if the BString started with \a string case-insensitively, 2106 \c false otherwise. 2107 2108 \since Haiku R1 2109*/ 2110 2111 2112/*! 2113 \fn bool BString::IStartsWith(const char* string) const 2114 \brief Returns whether or not the BString starts with \a string 2115 case-insensitively. 2116 2117 \param string The \a string to search for. 2118 2119 \return \c true if the BString started with \a string case-insensitively, 2120 \c false otherwise. 2121 2122 \since Haiku R1 2123*/ 2124 2125 2126/*! 2127 \fn bool BString::IStartsWith(const char* string, int32 length) const 2128 \brief Returns whether or not the BString starts with \a length characters 2129 of \a string case-insensitively. 2130 2131 \param string The \a string to search for. 2132 \param length The number of characters (bytes) of \a string to search for. 2133 2134 \return \c true if the BString started with \a length characters of 2135 \a string case-insensitively, \c false otherwise. 2136 2137 \since Haiku R1 2138*/ 2139 2140 2141/*! 2142 \fn bool BString::EndsWith(const BString& string) const 2143 \brief Returns whether or not the BString ends with \a string. 2144 2145 \param string The \a string to search for. 2146 2147 \return \c true if the BString ended with \a string, \c false otherwise. 2148 2149 \since Haiku R1 2150*/ 2151 2152 2153/*! 2154 \fn bool BString::EndsWith(const char* string) const 2155 \brief Returns whether or not the BString ends with \a string. 2156 2157 \param string The \a string to search for. 2158 2159 \return \c true if the BString ended with \a string, \c false otherwise. 2160 2161 \since Haiku R1 2162*/ 2163 2164 2165/*! 2166 \fn bool BString::EndsWith(const char* string, int32 length) const 2167 \brief Returns whether or not the BString ends with \a length characters 2168 of \a string. 2169 2170 \param string The \a string to search for. 2171 \param length The number of characters (bytes) of \a string to search for. 2172 2173 \return \c true if the BString ended with \a length characters of 2174 \a string, \c false otherwise. 2175 2176 \since Haiku R1 2177*/ 2178 2179 2180/*! 2181 \fn bool BString::IEndsWith(const BString& string) const 2182 \brief Returns whether or not the BString ends with \a string 2183 case-insensitively. 2184 2185 \param string The \a string to search for. 2186 2187 \return \c true if the BString ended with \a string case-insensitively, 2188 \c false otherwise. 2189 2190 \since Haiku R1 2191*/ 2192 2193 2194/*! 2195 \fn bool BString::IEndsWith(const char* string) const 2196 \brief Returns whether or not the BString ends with \a string 2197 case-insensitively. 2198 2199 \param string The \a string to search for. 2200 2201 \return \c true if the BString ended with \a string case-insensitively, 2202 \c false otherwise. 2203 2204 \since Haiku R1 2205*/ 2206 2207 2208/*! 2209 \fn bool BString::IEndsWith(const char* string, int32 length) const 2210 \brief Returns whether or not the BString ends with \a length characters 2211 of \a string case-insensitively. 2212 2213 \param string The \a string to search for. 2214 \param length The number of characters (bytes) of \a string to search for. 2215 2216 \return \c true if the BString ended with \a length characters of 2217 \a string case-insensitively, \c false otherwise. 2218 2219 \since Haiku R1 2220*/ 2221 2222 2223//! @} 2224 2225 2226/*! 2227 \name Replacing 2228*/ 2229 2230 2231//! @{ 2232 2233 2234/*! 2235 \fn BString& BString::ReplaceFirst(char replaceThis, char withThis) 2236 \brief Replace the first occurrence of a character with another character. 2237 2238 \param replaceThis The character to replace. 2239 \param withThis The character to put in its place. 2240 2241 \return This method always returns \c *this. 2242 2243 \sa IReplaceFirst(char, char) 2244 2245 \since BeOS R5 2246*/ 2247 2248 2249/*! 2250 \fn BString& BString::ReplaceLast(char replaceThis, char withThis) 2251 \brief Replace the last occurrence of a character with another character. 2252 2253 \param replaceThis The character to replace. 2254 \param withThis The character to put in its place 2255 2256 \return This method always returns \c *this. 2257 2258 \sa IReplaceLast(char, char) 2259 2260 \since BeOS R5 2261*/ 2262 2263 2264/*! 2265 \fn BString& BString::ReplaceAll(char replaceThis, char withThis, 2266 int32 fromOffset) 2267 \brief Replace all occurrences of a character with another character. 2268 2269 \param replaceThis The character to replace. 2270 \param withThis The character to put in its place 2271 \param fromOffset The offset in bytes to start looking for the character. 2272 2273 \return This method always returns \c *this. 2274 2275 \sa IReplaceAll(char, char, int32) 2276 2277 \since BeOS R5 2278*/ 2279 2280 2281/*! 2282 \fn BString& BString::Replace(char replaceThis, char withThis, 2283 int32 maxReplaceCount, int32 fromOffset) 2284 \brief Replace a number of occurrences of a character with another 2285 character. 2286 2287 \param replaceThis The character to replace. 2288 \param withThis The character to put in its place 2289 \param maxReplaceCount The maximum number of characters that should be 2290 replaced. 2291 \param fromOffset The offset in bytes to start looking for the character 2292 2293 \return This method always returns \c *this. 2294 2295 \sa IReplace(char, char, int32, int32) 2296 2297 \since BeOS R5 2298*/ 2299 2300 2301/*! 2302 \fn BString& BString::ReplaceFirst(const char* replaceThis, 2303 const char* withThis) 2304 \brief Replace the first occurrence of a string with another string. 2305 2306 \param replaceThis The string to replace. 2307 \param withThis The string to put in its place 2308 2309 \return This method always returns \c *this. 2310 2311 \sa IReplaceFirst(const char*, const char*) 2312 2313 \since BeOS R5 2314*/ 2315 2316 2317/*! 2318 \fn BString& BString::ReplaceLast(const char* replaceThis, 2319 const char* withThis) 2320 \brief Replace the last occurrence of a string with another string. 2321 2322 \param replaceThis The string to replace. 2323 \param withThis The string to put in its place 2324 2325 \return This method always returns \c *this. 2326 2327 \sa IReplaceLast(const char*, const char*) 2328 2329 \since BeOS R5 2330*/ 2331 2332 2333/*! 2334 \fn BString& BString::ReplaceAll(const char* replaceThis, 2335 const char* withThis, int32 fromOffset) 2336 \brief Replace all occurrences of a string with another string. 2337 2338 \param replaceThis The string to replace. 2339 \param withThis The string to put in its place 2340 \param fromOffset The offset in bytes to start looking for the string. 2341 2342 \return This method always returns \c *this. 2343 2344 \sa IReplaceAll(const char*, const char*, int32) 2345 2346 \since BeOS R5 2347*/ 2348 2349 2350/*! 2351 \fn BString& BString::Replace(const char* replaceThis, 2352 const char* withThis, int32 maxReplaceCount, int32 fromOffset) 2353 \brief Replace a number of occurrences of a string with another string. 2354 2355 \param replaceThis The string to replace. 2356 \param withThis The string to put in its place 2357 \param maxReplaceCount The maximum number of occurrences that should 2358 be replaced. 2359 \param fromOffset The offset in bytes to start looking for the string. 2360 2361 \return This method always returns \c *this. 2362 2363 \sa IReplace(const char*, const char*, int32, int32) 2364 2365 \since BeOS R5 2366*/ 2367 2368 2369/*! 2370 \fn BString& BString::ReplaceAllChars(const char* replaceThis, 2371 const char* withThis, int32 fromCharOffset) 2372 \brief UTF-8 aware version of ReplaceAll(const char*, const char*, int32). 2373 2374 \param replaceThis The string to replace. 2375 \param withThis The string to put in its place 2376 \param fromCharOffset The offset in UTF-8 characters to start looking for 2377 the string. 2378 2379 \return This method always returns \c *this. 2380 2381 \see ReplaceAll(const char*, const char*, int32) 2382 2383 \since Haiku R1 2384*/ 2385 2386 2387/*! 2388 \fn BString& BString::ReplaceChars(const char* replaceThis, 2389 const char* withThis, int32 maxReplaceCount, int32 fromCharOffset) 2390 \brief UTF-8 aware version of 2391 ReplaceAll(const char*, const char*, int32, int32). 2392 2393 \param replaceThis The string to replace. 2394 \param withThis The string to put in its place 2395 \param maxReplaceCount The maximum number of occurrences that should 2396 be replaced. 2397 \param fromCharOffset The offset in UTF-8 characters to start looking for 2398 the string. 2399 2400 \return This method always returns \c *this. 2401 2402 \see ReplaceAll(const char*, const char*, int32, int32) 2403 2404 \since Haiku R1 2405*/ 2406 2407 2408/*! 2409 \fn BString& BString::IReplaceFirst(char replaceThis, char withThis) 2410 \brief Replace the first occurrence of a character with another 2411 character case-insensitively. 2412 2413 \param replaceThis The string to replace. 2414 \param withThis The string to put in its place 2415 2416 \sa ReplaceFirst(char, char) 2417 2418 \since BeOS R5 2419*/ 2420 2421 2422/*! 2423 \fn BString& BString::IReplaceLast(char replaceThis, char withThis) 2424 \brief Replace the last occurrence of a character with another 2425 character case-insensitively. 2426 2427 \param replaceThis The string to replace. 2428 \param withThis The string to put in its place 2429 2430 \sa ReplaceLast(char, char) 2431 2432 \since BeOS R5 2433*/ 2434 2435 2436/*! 2437 \fn BString& BString::IReplaceAll(char replaceThis, char withThis, 2438 int32 fromOffset) 2439 \brief Replace all occurrences of a character with another character 2440 case-insensitively. 2441 2442 \param replaceThis The string to replace. 2443 \param withThis The string to put in its place 2444 \param fromOffset The offset where to start looking for the string 2445 2446 \sa ReplaceAll(char, char, int32) 2447 2448 \since BeOS R5 2449*/ 2450 2451 2452/*! 2453 \fn BString& BString::IReplace(char replaceThis, char withThis, 2454 int32 maxReplaceCount, int32 fromOffset) 2455 \brief Replace a number of occurrences of a character with another 2456 character case-insensitively. 2457 2458 \param replaceThis The char to replace. 2459 \param withThis The char to put in its place 2460 \param maxReplaceCount The maximum number of occurrences that should 2461 be replaced. 2462 \param fromOffset The offset where to start looking for the string 2463 2464 \sa Replace(char, char, int32, int32) 2465 2466 \since BeOS R5 2467*/ 2468 2469 2470/*! 2471 \fn BString& BString::IReplaceFirst(const char* replaceThis, 2472 const char* withThis) 2473 \brief Replace the first occurrence of a string with another string 2474 case-insensitively. 2475 2476 \param replaceThis The string to replace. 2477 \param withThis The string to put in its place. 2478 2479 \sa ReplaceFirst(const char*, const char*) 2480 2481 \since BeOS R5 2482*/ 2483 2484 2485/*! 2486 \fn BString& BString::IReplaceLast(const char* replaceThis, 2487 const char* withThis) 2488 \brief Replace the last occurrence of a string with another string. Case-insensitive. 2489 2490 \param replaceThis The string to replace. 2491 \param withThis The string to put in its place. 2492 2493 \sa ReplaceLast(const char*, const char*) 2494 2495 \since BeOS R5 2496*/ 2497 2498 2499/*! 2500 \fn BString& BString::IReplaceAll(const char* replaceThis, 2501 const char* withThis, int32 fromOffset) 2502 \brief Replace all occurrences of a string with another string 2503 case-insensitively. 2504 2505 \param replaceThis The string to replace. 2506 \param withThis The string to put in its place. 2507 \param fromOffset The offset where to start looking for the string. 2508 2509 \sa ReplaceAll(const char*, const char*, int32) 2510 2511 \since BeOS R5 2512*/ 2513 2514 2515/*! 2516 \fn BString& BString::IReplace(const char* replaceThis, 2517 const char* withThis, int32 maxReplaceCount, int32 fromOffset) 2518 \brief Replace a number of occurrences of a string with another string 2519 case-insensitively. 2520 2521 \param replaceThis The string to replace. 2522 \param withThis The string to put in its place 2523 \param maxReplaceCount The maximum number of occurrences that should 2524 be replaced. 2525 \param fromOffset The offset where to start looking for the string 2526 2527 \sa Replace(const char*, const char*, int32, int32) 2528 2529 \since BeOS R5 2530*/ 2531 2532 2533/*! 2534 \fn BString& BString::ReplaceSet(const char* setOfBytes, char with) 2535 \brief Replaces characters that are in a certain set with a chosen 2536 character. 2537 2538 \param setOfBytes The set of characters that need to be replaced. 2539 \param with The character to replace the occurrences with. 2540 2541 \return This method always returns \c *this. 2542 2543 \since BeOS R5 2544*/ 2545 2546 2547/*! 2548 \fn BString& BString::ReplaceSet(const char* setOfBytes, const char* with) 2549 \brief Replaces characters that are in a certain set with a chosen string. 2550 2551 \param setOfBytes The set of chars that need to be replaced. 2552 \param with The string to replace the occurrences with. 2553 2554 \return This method always returns \c *this. 2555 2556 \since BeOS R5 2557*/ 2558 2559 2560/*! 2561 \fn BString& BString::ReplaceCharsSet(const char* setOfChars, 2562 const char* with) 2563 \brief UTF-8 aware version of ReplaceSet(const char*, const char*) 2564 2565 \param setOfChars The set of UTF-8 characters that need to be replaced. 2566 \param with The string to replace the occurrences with. 2567 2568 \return This method always returns \c *this. 2569 2570 \since Haiku R1 2571*/ 2572 2573 2574// @} 2575 2576 2577/*! 2578 \name Indexing 2579*/ 2580 2581 2582//! @{ 2583 2584 2585/*! 2586 \fn char& BString::operator[](int32 index) 2587 \brief Return a reference to the data at the given offset. 2588 2589 This function can be used to read a byte. 2590 There is no bounds checking though, so make sure the \c index 2591 you supply is valid. 2592 2593 \param index The index (zero-based) of the byte to get. 2594 2595 \return Returns a reference to the specified byte. 2596 2597 \sa ByteAt(int32 index) for a safer version. 2598 2599 \since BeOS R5 2600*/ 2601 2602 2603/*! 2604 \fn char BString::operator[](int32 index) const 2605 \brief Returns the character in the string at the given offset. 2606 2607 This function can be used to read a byte. There is no bound checking 2608 though, use ByteAt() if you don't know if the \c index parameter is 2609 valid. 2610 2611 \param index The index (zero-based) of the byte to get. 2612 2613 \return Returns a reference to the specified byte. 2614 2615 \since BeOS R5 2616*/ 2617 2618 2619/*! 2620 \fn char BString::ByteAt(int32 index) const 2621 \brief Returns the character in the string at the given offset. 2622 2623 This function can be used to read a single byte. 2624 2625 \param index The index (zero-based) of the byte to get. 2626 2627 \return A reference to the specified byte, if out of bounds return 0. 2628 2629 \since BeOS R5 2630*/ 2631 2632 2633/*! 2634 \fn const char* BString::CharAt(int32 charIndex, int32* bytes) const 2635 \brief UTF-8 aware version of ByteAt(int32). 2636 2637 \param charIndex The index (zero-based) of the UTF-8 character to get. 2638 \param bytes An int32 pointer to hold the UTF-8 character. 2639 2640 \return A reference to the specified UTF-8 character, if out of bounds 2641 return 0. 2642 2643 \see ByteAt(int32) 2644 2645 \since Haiku R1 2646*/ 2647 2648 2649/*! 2650 \fn bool BString::CharAt(int32 charIndex, char* buffer, 2651 int32* bytes) const 2652 \brief UTF-8 aware version of ByteAt(int32) with a \a buffer parameter. 2653 2654 \param charIndex The index (zero-based) of the UTF-8 character to get. 2655 \param buffer Set to the position in the string where the character is 2656 found. 2657 \param bytes An int32 pointer to hold the UTF-8 character. 2658 2659 \see ByteAt(int32, char*, int32*) 2660 2661 \since Haiku R1 2662*/ 2663 2664 2665//! @} 2666 2667 2668/*! 2669 \name Low-Level Manipulation 2670*/ 2671 2672 2673//! @{ 2674 2675 2676/*! 2677 \fn char* BString::LockBuffer(int32 maxLength) 2678 \brief Locks the buffer and return the internal string for manipulation. 2679 2680 If you want to do any low-level string manipulation on the internal buffer, 2681 you should call this method. This method includes the possibility to grow 2682 the buffer so that you don't have to worry about that yourself. 2683 2684 Make sure you call UnlockBuffer() when you're done with the manipulation. 2685 2686 \param maxLength The size of the buffer in bytes. If you don't want a 2687 bigger buffer, passing anything under the length of the string will 2688 simply return it as is. 2689 2690 \return A pointer to the buffer to manipulate. 2691 2692 \sa UnlockBuffer() 2693 2694 \since BeOS R5 2695*/ 2696 2697 2698/*! 2699 \fn BString& BString::UnlockBuffer(int32 length) 2700 \brief Unlocks the buffer after you are done with low-level manipulation. 2701 2702 \param length The length in bytes to trim the string to in order to keep 2703 the internal buffer sane. If you don't pass a value in it, 2704 <tt>strlen()</tt> will be used to determine the length. 2705 2706 \return This method always returns \c *this. 2707 2708 \since BeOS R5 2709*/ 2710 2711 2712/*! 2713 \fn BString& BString::SetByteAt(int32 pos, char to) 2714 \brief Set a byte at position \a pos to character \a to. 2715 2716 \param pos The index of the byte to replace. 2717 \param to The new value that should replace the previous byte. 2718 2719 \return This method always returns \c *this. 2720 2721 \since Haiku R1 2722*/ 2723 2724 2725//! @} 2726 2727 2728/*! 2729 \name Case Manipulation 2730*/ 2731 2732 2733//! @{ 2734 2735 2736/*! 2737 \fn BString& BString::ToLower() 2738 \brief Convert each of the characters in the BString to lowercase. 2739 2740 \return This method always returns \c *this. 2741 2742 \since BeOS R5 2743*/ 2744 2745 2746/*! 2747 \fn BString& BString::ToUpper() 2748 \brief Convert each of the characters in the BString to uppercase. 2749 2750 \return This method always returns \c *this. 2751 2752 \since BeOS R5 2753*/ 2754 2755 2756/*! 2757 \fn BString& BString::Capitalize() 2758 \brief Convert the first character to uppercase, and the rest to lowercase. 2759 2760 \return This method always returns \c *this. 2761 2762 \since BeOS R5 2763*/ 2764 2765 2766/*! 2767 \fn BString& BString::CapitalizeEachWord() 2768 \brief Convert the first character of every word to uppercase, and the rest 2769 to lowercase. 2770 2771 Converts the first character of every "word" (series of alphabetical 2772 characters separated by non alphabetical characters) to uppercase, and 2773 the rest to lowercase. 2774 2775 \return This method always returns \c *this. 2776 2777 \since BeOS R5 2778*/ 2779 2780 2781//! @} 2782 2783 2784/*! 2785 \name Escaping and De-escaping 2786 2787 This class contains some methods to help you with escaping and 2788 de-escaping certain characters. Note that this is the C-style of 2789 escaping, where you place a character before the character that is 2790 to be escaped, and not HTML style escaping, where certain characters 2791 are replaced by something else. 2792*/ 2793 2794 2795//! @{ 2796 2797 2798/*! 2799 \fn BString& BString::CharacterEscape(const char* original, 2800 const char* setOfCharsToEscape, char escapeWith) 2801 \brief Escape selected characters on a given string. 2802 2803 This version sets itself to the string supplied in the \c original 2804 parameter, and then escapes the selected characters with a supplied 2805 character. 2806 2807 \param original The string to be escaped. 2808 \param setOfCharsToEscape The set of characters that need to be escaped. 2809 \param escapeWith The character to escape with. 2810 2811 \return This method always returns \c *this. 2812 2813 \sa CharacterDeescape(char) 2814 \sa CharacterDeescape(const char*, char) 2815 2816 \since BeOS R5 2817*/ 2818 2819 2820/*! 2821 \fn BString& BString::CharacterEscape(const char* setOfCharsToEscape, 2822 char escapeWith) 2823 \brief Escape selected characters of this string. 2824 2825 \param setOfCharsToEscape The set of characters that need to be escaped. 2826 \param escapeWith The character to escape with. 2827 2828 \return This method always returns \c *this. 2829 2830 \sa CharacterDeescape(char) 2831 2832 \since BeOS R5 2833*/ 2834 2835 2836/*! 2837 \fn BString& BString::CharacterDeescape(const char* original, 2838 char escapeChar) 2839 \brief Remove the character to escape with from a given string. 2840 2841 This version sets itself to the string supplied in the \c original 2842 parameter, and then removes the escape characters. 2843 2844 \param original The string to be escaped. 2845 \param escapeChar The character that was used to escape with. 2846 2847 \return This method always returns \c *this. 2848 2849 \sa CharacterEscape(const char*, const char*, char) 2850 2851 \since BeOS R5 2852*/ 2853 2854 2855/*! 2856 \fn BString& BString::CharacterDeescape(char escapeChar) 2857 \brief Remove the character to escape with from this string. 2858 2859 \param escapeChar The character that was used to escape with. 2860 2861 \return This method always returns \c *this. 2862 2863 \sa CharacterEscape(const char*, char) 2864*/ 2865 2866 2867//! @} 2868 2869 2870/*! 2871 \name sprintf() Replacement Methods 2872 2873 These methods may be slower than <tt>sprintf()</tt>, but they are overflow safe. 2874*/ 2875 2876 2877//! @{ 2878 2879 2880/*! 2881 \fn BString& BString::operator<<(const char* string) 2882 \brief Append \a string to the BString. 2883 2884 \param string The \a string to append. 2885 2886 \return This method always returns \c *this. 2887 2888 \since BeOS R5 2889*/ 2890 2891 2892/*! 2893 \fn BString& BString::operator<<(const BString& string) 2894 \brief Append \a string to the BString. 2895 2896 \param string The \a string to append. 2897 2898 \return This method always returns \c *this. 2899*/ 2900 2901 2902/*! 2903 \fn BString& BString::operator<<(char c) 2904 \brief Append \a c to the BString. 2905 2906 \param c The character to append. 2907 2908 \return This method always returns \c *this. 2909 2910 \since BeOS R5 2911*/ 2912 2913 2914/*! 2915 \fn BString& BString::operator<<(bool value) 2916 \brief Convert the \c bool \c value to a string and append it. 2917 2918 In case the \a value is true, the string "true" is appended to the string. 2919 Otherwise, the string "false" is appended. 2920 2921 \param value The boolean \c value ("true" of "false") to append. 2922 2923 \return This method always returns \c *this. 2924 2925 \since BeOS R5 2926*/ 2927 2928 2929/*! 2930 \fn BString& BString::operator<<(int value) 2931 \brief Convert the \c int \a value to a string and append it. 2932 2933 \param value The \c int \a value to append. 2934 2935 \return This method always returns \c *this. 2936 2937 \since BeOS R5 2938*/ 2939 2940 2941/*! 2942 \fn BString& BString::operator<<(unsigned int value) 2943 \brief Convert the <tt>unsigned int</tt> \a value to a string and append it. 2944 2945 \param value The <tt>unsigned int</tt> \a value to append. 2946 2947 \return This method always returns \c *this. 2948 2949 \since BeOS R5 2950*/ 2951 2952 2953/*! 2954 \fn BString& BString::operator<<(unsigned long value) 2955 \brief Convert the <tt>unsigned long</tt> \a value to a string and append it. 2956 2957 \param value The <tt>unsigned long</tt> \a value to append. 2958 2959 \return This method always returns \c *this. 2960 2961 \since BeOS R5 2962*/ 2963 2964 2965/*! 2966 \fn BString& BString::operator<<(long value) 2967 \brief Convert the \c long \a value to a string and append it. 2968 2969 \param value The \c long \a value to append. 2970 2971 \return This method always returns \c *this. 2972 2973 \since BeOS R5 2974*/ 2975 2976 2977/*! 2978 \fn BString& BString::operator<<(unsigned long long value) 2979 \brief Convert the <tt>unsigned long long</tt> \a value to a string and 2980 append it. 2981 2982 \param value The <tt>unsigned long long</tt> \a value to append. 2983 2984 \return This method always returns \c *this. 2985 2986 \since BeOS R5 2987*/ 2988 2989 2990/*! 2991 \fn BString& BString::operator<<(long long value) 2992 \brief Convert the <tt>long long</tt> \a value to a string and append it. 2993 2994 \param value The <tt>long long</tt> \a value to append. 2995 2996 \return This method always returns \c *this. 2997 2998 \since BeOS R5 2999*/ 3000 3001 3002/*! 3003 \fn BString& BString::operator<<(float value) 3004 \brief Convert the \c float \a value to a string and append it. 3005 3006 Using this operator will append using <tt>%.2f</tt> formatting. 3007 3008 \param value The \c float \a value to append. 3009 3010 \return This method always returns \c *this. 3011 3012 \since BeOS R5 3013*/ 3014 3015 3016/*! 3017 \fn BString& BString::operator<<(double value) 3018 \brief Convert the \c double \a value to a string and append it. 3019 3020 Using this operator will append using <tt>%.2f</tt> formatting. 3021 3022 \param value The \c double \a value to append. 3023 3024 \return This method always returns \c *this. 3025 3026 \since BeOS R5 3027*/ 3028 3029 3030//! @} 3031 3032 3033/************* end of BString class, start of general operators ************/ 3034/*! 3035 \addtogroup support_globals 3036*/ 3037 3038 3039//! @{ 3040 3041 3042/*! 3043 \fn bool operator<(const char* a, const BString& b) 3044 \brief Lexicographically compare if \c a is less than the given BString \a b. 3045 3046 From String.h and in libbe.so. 3047 3048 \param a The first string to compare. 3049 \param b The second string to compare. 3050 3051 \return \c true if \a a is less than \a b, \c false otherwise. 3052 3053 \sa BString::operator<(const char*) const 3054 3055 \since BeOS R5 3056*/ 3057 3058 3059/*! 3060 \fn bool operator<=(const char* a, const BString& b) 3061 \brief Lexicographically compare if \c a is less than or equal to a 3062 given BString \a b. 3063 3064 From String.h and in libbe.so. 3065 3066 \param a The first string to compare. 3067 \param b The second string to compare. 3068 3069 \return \c true if \a a is less than or equal to \a b, 3070 \c false otherwise. 3071 3072 \sa BString::operator<=(const char*) const 3073 3074 \since BeOS R5 3075*/ 3076 3077 3078/*! 3079 \fn bool operator==(const char* a, const BString& b) 3080 \brief Lexicographically compare if \c a is equal to a given BString \a b. 3081 3082 From String.h and in libbe.so. 3083 3084 \param a The first string to compare. 3085 \param b The second string to compare. 3086 3087 \sa BString::operator==(const char*) const 3088 3089 \return \c true if \a a is equal to \a b, \c false otherwise. 3090 3091 \since BeOS R5 3092*/ 3093 3094 3095/*! 3096 \fn bool operator>(const char* a, const BString& b) 3097 \brief Lexicographically compare if \c a is greater than a given BString \a b. 3098 3099 From String.h and in libbe.so. 3100 3101 \param a The first string to compare. 3102 \param b The second string to compare. 3103 3104 \sa BString::operator>(const char*) const 3105 3106 \return \c true if \a a is greater than \a b, \c false otherwise. 3107 3108 \since BeOS R5 3109*/ 3110 3111 3112/*! 3113 \fn bool operator>=(const char* a, const BString& b) 3114 \brief Lexicographically compare if \c a is greater than or equal to a 3115 given BString \a b. 3116 3117 From String.h and in libbe.so. 3118 3119 \param a The first string to compare. 3120 \param b The second string to compare. 3121 3122 \return \c true if \a a is greater than or equal to \a b, 3123 \c false otherwise. 3124 3125 \sa BString::operator>=(const char*) const 3126 3127 \since BeOS R5 3128*/ 3129 3130 3131/*! 3132 \fn bool operator!=(const char* a, const BString& b) 3133 \brief Lexicographically compare if \c a is not equal to given BString \a b. 3134 3135 From String.h and in libbe.so. 3136 3137 \param a The first string to compare. 3138 \param b The second string to compare. 3139 3140 \return \c true if \a a is NOT equal to \a b, \c false otherwise. 3141 3142 \sa BString::operator!=(const char*) const 3143 3144 \since BeOS R5 3145*/ 3146 3147 3148/*! 3149 \fn int Compare(const BString& a, const BString& b) 3150 \brief Lexicographically compare two strings. 3151 3152 This function is useful if you need a global compare function to feed to 3153 BList::SortItems(). 3154 3155 \param a The first string to compare. 3156 \param b The second string to compare. 3157 3158 From String.h and in libbe.so. 3159 3160 \return An int representing the strings relationship to each other. 3161 \retval >0 \a a sorts lexicographically after \a b. 3162 \retval =0 \a a is equal to \a b. 3163 \retval <0 \a a sorts lexicographically before \a b. 3164 3165 \sa BString::Compare(const BString&) const 3166 3167 \since BeOS R5 3168*/ 3169 3170 3171/*! 3172 \fn int ICompare(const BString& a, const BString& b) 3173 \brief Lexicographically compare two strings case-insensitively. 3174 3175 This function is useful if you need a global compare function to feed to 3176 BList::SortItems(). 3177 3178 From String.h and in libbe.so. 3179 3180 \param a The first string to compare. 3181 \param b The second string to compare. 3182 3183 \return An int representing the strings relationship to each other. 3184 \retval >0 \a a sorts lexicographically after \a b. 3185 \retval =0 \a a is equal to \a b. 3186 \retval <0 \a a sorts lexicographically before \a b. 3187 3188 \sa BString::Compare(const BString&) const 3189 3190 \since BeOS R5 3191*/ 3192 3193 3194/*! 3195 \fn int Compare(const BString* a, const BString* b) 3196 \brief Lexicographically compare two strings. 3197 3198 This function is useful if you need a global compare function to feed to 3199 BList::SortItems(). 3200 3201 From String.h and in libbe.so. 3202 3203 \param a The first string to compare. 3204 \param b The second string to compare. 3205 3206 \return An int representing the strings relationship to each other. 3207 \retval >0 \a a sorts lexicographically after \a b. 3208 \retval =0 \a a is equal to \a b. 3209 \retval <0 \a a sorts lexicographically before \a b. 3210 3211 \sa BString::Compare(const BString&) const 3212 3213 \since BeOS R5 3214*/ 3215 3216 3217/*! 3218 \fn int ICompare(const BString* a, const BString* b) 3219 \brief Lexicographically compare two strings case-insensitively. 3220 3221 This function is useful if you need a global compare function to feed to 3222 BList::SortItems(). 3223 3224 From String.h and in libbe.so. 3225 3226 \param a The first string to compare. 3227 \param b The second string to compare. 3228 3229 \return An int representing the strings relationship to each other. 3230 \retval >0 \a a sorts lexicographically after \a b. 3231 \retval =0 \a a is equal to \a b. 3232 \retval <0 \a a sorts lexicographically before \a b. 3233 3234 \sa BString::Compare(const BString&) const 3235 3236 \since BeOS R5 3237*/ 3238 3239 3240//! @} 3241