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::Append(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 \since BeOS R5 650*/ 651 652 653/*! 654 \fn BString& BString::Append(const char* str) 655 \brief Append the string data to the end of the BString. 656 657 This method calls operator+=(const char *str). 658 659 \sa Append(const char*, int32) 660 661 \since BeOS R5 662*/ 663 664 665/*! 666 \fn BString& BString::Append(const BString& string, int32 length) 667 \brief Append a part of the given \a string to the end of the BString. 668 669 \param string The BString to append. 670 \param length The maximum number of bytes to append. 671 672 \return This method always returns \c *this. 673 674 \sa operator+=(const BString&) 675 676 \since BeOS R5 677*/ 678 679 680/*! 681 \fn BString& BString::Append(const char* str, int32 length) 682 \brief Append a part of the given string to end of the BString. 683 684 \param str A pointer to the string to append. 685 \param length The maximum number of bytes to append. 686 687 \return This method always returns \c *this. 688 689 \sa operator+=(const char*) 690 691 \since BeOS R5 692*/ 693 694 695/*! 696 \fn BString& BString::Append(char c, int32 count) 697 \brief Append the given character repeatedly to the end of the BString. 698 699 \param c The character to append. 700 \param count The number of times this character should be appended. 701 702 \return This method always returns \c *this. 703 704 \sa operator+=(char c) 705 706 \since BeOS R5 707*/ 708 709 710/*! 711 \fn BString& BString::AppendChars(const BString& string, int32 charCount) 712 \brief UTF-8 aware version of Append(const BString&, int32). 713 714 \param string The \a string to append. 715 \param charCount The maximum number of UTF-8 characters to append. 716 717 \return This method always returns \c *this. 718 719 \see Append(const BString&, int32) 720 721 \since Haiku R1 722*/ 723 724 725/*! 726 \fn BString& BString::AppendChars(const char* string, int32 charCount) 727 \brief UTF-8 aware version of Append(const char*, int32). 728 729 \param string The \a string to append. 730 \param charCount The maximum number of UTF-8 characters to append. 731 732 \return This method always returns \c *this. 733 734 \see Append(const char*, int32) 735 736 \since Haiku R1 737*/ 738 739 740//! @} 741 742 743/*! 744 \name Prepending 745*/ 746 747 748//! @{ 749 750 751/*! 752 \fn BString& BString::Prepend(const char* str) 753 \brief Prepend the given string to the beginning of the BString. 754 755 \param str The \a string to prepend. 756 757 \return This method always returns \c *this. 758 759 \sa Prepend(const char*, int32) 760 761 \since BeOS R5 762*/ 763 764 765/*! 766 \fn BString& BString::Prepend(const BString& string) 767 \brief Prepend the given BString to the beginning of the BString. 768 769 \param string The \a string to prepend. 770 771 \return This method always returns \c *this. 772 773 \sa Prepend(const BString&, int32) 774 775 \since BeOS R5 776*/ 777 778 779/*! 780 \fn BString& BString::Prepend(const char* str, int32 length) 781 \brief Prepend the given string to the beginning of the BString. 782 783 \param str The \a string to prepend. 784 \param length The maximum number of bytes to prepend. 785 786 \return This method always returns \c *this. 787 788 \sa Prepend(const char*) 789 790 \since BeOS R5 791*/ 792 793 794/*! 795 \fn BString& BString::Prepend(const BString& string, int32 length) 796 \brief Prepend the given BString to the beginning of the BString. 797 798 \param string The \a string to prepend. 799 \param length The maximum number of bytes to prepend. 800 801 \return This method always returns \c *this. 802 803 \sa Prepend(const BString&) 804 805 \since BeOS R5 806*/ 807 808 809/*! 810 \fn BString& BString::Prepend(char c, int32 count) 811 \brief Prepend the given character \a count times to the beginning of the 812 BString. 813 814 \param c The character to prepend. 815 \param count The number of times this character should be prepended. 816 817 \return This method always returns \c *this. 818 819 \since BeOS R5 820*/ 821 822 823/*! 824 \fn BString& BString::PrependChars(const char* string, int32 charCount) 825 \brief UTF-8 aware version of Prepend(const char*, int32). 826 827 \param string The \a string to prepend. 828 \param charCount The maximum number of UTF-8 characters to prepend. 829 830 \return This method always returns \c *this. 831 832 \see Prepend(const char*, int32) 833 834 \since Haiku R1 835*/ 836 837 838/*! 839 \fn BString& BString::PrependChars(const BString& string, int32 charCount) 840 \brief UTF-8 aware version of Prepend(const BString&, int32). 841 842 \param string The \a string to prepend. 843 \param charCount The maximum number of UTF-8 characters to prepend. 844 845 \return This method always returns \c *this. 846 847 \see Prepend(const BString&, int32) 848 849 \since Haiku R1 850*/ 851 852 853//! @} 854 855 856/*! 857 \name Inserting 858*/ 859 860 861//! @{ 862 863 864/*! 865 \fn BString& BString::Insert(const char* string, int32 position) 866 \brief Inserts the given string at the given position into the BString 867 data. 868 869 \param string The \a string to insert. 870 \param position The offset in bytes where to insert the \a string into 871 the BString's data. 872 873 \return This method always returns \c *this. 874 875 \sa Insert(const char*, int32, int32) 876 \sa Insert(const char*, int32, int32, int32) 877 878 \since BeOS R5 879*/ 880 881 882/*! 883 \fn BString& BString::Insert(const char* string, int32 length, 884 int32 position) 885 \brief Inserts the given string at the given position into the BString 886 data. 887 888 \param string The \a string to insert. 889 \param length The number of bytes to insert. 890 \param position The offset in bytes into the data of the BString where to 891 insert the string. 892 893 \return This method always returns \c *this. 894 895 \sa Insert(const char*, int32) 896 \sa Insert(const char*, int32, int32, int32) 897 898 \since BeOS R5 899*/ 900 901 902/*! 903 \fn BString& BString::Insert(const char* string, int32 fromOffset, 904 int32 length, int32 position) 905 \brief Inserts the given string at the given position into the BString 906 data. 907 908 \param string The \a string to insert. 909 \param fromOffset The offset in bytes in the \a string to be inserted. 910 \param length The number of bytes to insert. 911 \param position The offset in bytes into the data of the BString where to 912 insert the string. 913 914 \return This method always returns \c *this. 915 916 \sa Insert(const char*, int32) 917 \sa Insert(const char*, int32, int32) 918 919 \since BeOS R5 920*/ 921 922 923/*! 924 \fn BString& BString::Insert(const BString& string, int32 position) 925 \brief Inserts the given BString at the given position into the BString 926 data. 927 928 \param string The \a string to insert. 929 \param position The offset in bytes into the data of the BString where to 930 insert the string. 931 932 \return This method always returns \c *this. 933 934 \sa Insert(const BString&, int32, int32) 935 \sa Insert(const BString&, int32, int32, int32) 936 937 \since BeOS R5 938*/ 939 940 941/*! 942 \fn BString& BString::Insert(const BString& string, int32 length, int32 position) 943 \brief Inserts the given BString at the given position into the BString 944 data. 945 946 \param string The \a string to insert. 947 \param length The number of bytes to insert. 948 \param position The offset in bytes into the data of the BString where to 949 insert the string. 950 951 \return This method always returns \c *this. 952 953 \sa Insert(const BString&, int32) 954 \sa Insert(const BString&, int32, int32, int32) 955 956 \since BeOS R5 957*/ 958 959 960/*! 961 \fn BString& BString::Insert(const BString& string, int32 fromOffset, 962 int32 length, int32 position) 963 \brief Inserts the given string at the given position into the BString 964 data. 965 966 \param string The \a string to insert. 967 \param fromOffset The offset in bytes of the string to be inserted. 968 \param length The amount of bytes to insert. 969 \param position The offset in bytes into the data of the BString where to 970 insert the string. 971 972 \return This method always returns \c *this. 973 974 \sa Insert(const BString&, int32) 975 \sa Insert(const BString&, int32, int32) 976 977 \since BeOS R5 978*/ 979 980 981/*! 982 \fn BString& BString::Insert(char c, int32 count, int32 pos) 983 \brief Inserts the given character repeatedly at the given position 984 into the BString data. 985 986 \param c The character to insert. 987 \param count The number of times to insert the character. 988 \param pos The offset in bytes into the data of the BString where to 989 insert the string. 990 991 \return This method always returns \c *this. 992 993 \since BeOS R5 994*/ 995 996 997/*! 998 \fn BString& BString::InsertChars(const char* string, int32 charPosition) 999 \brief UTF-8 aware version of Insert(const char*, int32). 1000 1001 \param string The \a string to insert. 1002 \param charPosition The offset in UTF-8 characters where to insert 1003 the string into the data of the BString. 1004 1005 \return This method always returns \c *this. 1006 1007 \see Insert(const char*, int32) 1008 1009 \since Haiku R1 1010*/ 1011 1012 1013/*! 1014 \fn BString& BString::InsertChars(const char* string, int32 charCount, 1015 int32 charPosition) 1016 \brief UTF-8 aware version of Insert(const char*, int32, int32). 1017 1018 \param string The \a string to insert. 1019 \param charCount The number of UTF-8 characters to insert. 1020 \param charPosition The offset in UTF-8 characters where to insert 1021 the string into the data of the BString. 1022 1023 \return This method always returns \c *this. 1024 1025 \see Insert(const char*, int32, int32) 1026 1027 \since Haiku R1 1028*/ 1029 1030 1031/*! 1032 \fn BString& BString::InsertChars(const char* string, int32 fromCharOffset, 1033 int32 charCount, int32 charPosition) 1034 \brief UTF-8 aware version of Insert(const char*, int32, int32, int32). 1035 1036 \param string The \a string to insert. 1037 \param fromCharOffset The offset in UTF-8 characters of the string to be 1038 inserted. 1039 \param charCount The number of UTF-8 characters to insert. 1040 \param charPosition The offset in UTF-8 characters where to insert 1041 the string into the data of the BString. 1042 1043 \return This method always returns \c *this. 1044 1045 \see Insert(const char*, int32, int32, int32) 1046 1047 \since Haiku R1 1048*/ 1049 1050 1051/*! 1052 \fn BString& BString::InsertChars(const BString& string, int32 charPosition) 1053 \brief UTF-8 aware version of Insert(const BString&, int32). 1054 1055 \param string The \a string to insert. 1056 \param charPosition The offset in UTF-8 characters where to insert 1057 the string into the data of the BString. 1058 1059 \return This method always returns \c *this. 1060 1061 \see Insert(const BString&, int32) 1062 1063 \since Haiku R1 1064*/ 1065 1066 1067/*! 1068 \fn BString& BString::InsertChars(const BString& string, int32 charCount, 1069 int32 charPosition) 1070 \brief UTF-8 aware version of Insert(const BString&, int32, int32). 1071 1072 \param string The \a string to insert. 1073 \param charCount The number of UTF-8 characters to insert. 1074 \param charPosition The offset in UTF-8 characters where to insert 1075 the string into the data of the BString. 1076 1077 \return This method always returns \c *this. 1078 1079 \see Insert(const BString&, int32, int32) 1080 1081 \since Haiku R1 1082*/ 1083 1084 1085/*! 1086 \fn BString& BString::InsertChars(const BString& string, int32 fromCharOffset, 1087 int32 charCount, int32 charPosition) 1088 \brief UTF-8 aware version of Insert(const BString&, int32, int32, int32). 1089 1090 \param string The \a string to insert. 1091 \param fromCharOffset The offset in UTF-8 characters of the string to be 1092 inserted. 1093 \param charCount The number of UTF-8 characters to insert. 1094 \param charPosition The offset in UTF-8 characters where to insert 1095 the string into the data of the BString. 1096 1097 \return This method always returns \c *this. 1098 1099 \see Insert(const BString&, int32, int32, int32) 1100 1101 \since Haiku R1 1102*/ 1103 1104 1105//! @} 1106 1107 1108/*! 1109 \name Removing 1110*/ 1111 1112 1113//! @{ 1114 1115 1116/*! 1117 \fn BString& BString::Trim() 1118 \brief Removes spaces from the beginning and end of the string. 1119 1120 The definition of a space is set by the <tt>isspace()</tt> function. 1121 1122 \return This method always returns \c *this. 1123 1124 \since Haiku R1 1125*/ 1126 1127 1128 1129/*! 1130 \fn BString& BString::Truncate(int32 newLength, bool lazy) 1131 \brief Truncate the string to the new length. 1132 1133 \param newLength The new length of the string in bytes. 1134 \param lazy If true, the memory-optimization is postponed until later. 1135 1136 \return This method always returns \c *this. 1137 1138 \since BeOS R5 1139*/ 1140 1141 1142/*! 1143 \fn BString& BString::TruncateChars(int32 newCharCount, bool lazy) 1144 \brief UTF-8 aware version of Truncate(int32, bool). 1145 1146 \param newCharCount The new length of the string in UTF-8 characters. 1147 \param lazy If true, the memory-optimization is postponed until later. 1148 1149 \see Truncate(int32, bool) 1150 1151 \since Haiku R1 1152*/ 1153 1154 1155/*! 1156 \fn BString& BString::Remove(int32 from, int32 length) 1157 \brief Remove some bytes, starting at the given offset 1158 1159 \param from The offset in bytes to start removing. 1160 \param length The number of bytes to remove. 1161 1162 \return This function always returns \c *this. 1163 1164 \since BeOS R5 1165*/ 1166 1167 1168/*! 1169 \fn BString& BString::RemoveChars(int32 fromCharOffset, int32 charCount) 1170 \brief UTF-8 aware version of Remove(int32, int32). 1171 1172 \param fromCharOffset The offset in UTF-8 characters to start removing. 1173 \param charCount The number of UTF-8 characters to remove. 1174 1175 \return This function always returns \c *this. 1176 1177 \see Remove(int32, int32) 1178 1179 \since Haiku R1 1180*/ 1181 1182 1183/*! 1184 \fn BString& BString::RemoveFirst(const BString& string) 1185 \brief Remove the first occurrence of the given BString. 1186 1187 \param string The BString to remove. 1188 1189 \return This function always returns \c *this. 1190 1191 \since BeOS R5 1192*/ 1193 1194 1195/*! 1196 \fn BString& BString::RemoveLast(const BString& string) 1197 \brief Remove the last 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::RemoveAll(const BString& string) 1209 \brief Remove all occurrences 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::RemoveFirst(const char* string) 1221 \brief Remove the first occurrence of the given string. 1222 1223 \param string A pointer to the string to remove. 1224 1225 \return This function always returns \c *this. 1226 1227 \since BeOS R5 1228*/ 1229 1230 1231/*! 1232 \fn BString& BString::RemoveLast(const char* string) 1233 \brief Remove the last 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::RemoveAll(const char* str) 1245 \brief Remove all occurrences of the given string. 1246 1247 \param str 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::RemoveSet(const char* setOfCharsToRemove) 1257 \brief Remove all the characters specified. 1258 1259 \param setOfCharsToRemove The set of characters to remove. 1260 1261 \return This function always returns \c *this. 1262 1263 \since BeOS R5 1264*/ 1265 1266 1267/*! 1268 \fn BString& BString::RemoveCharsSet(const char* setOfCharsToRemove) 1269 \brief UTF-8 aware version of RemoveSet(const char*). 1270 1271 \param setOfCharsToRemove The set of characters to remove. 1272 1273 \return This function always returns \c *this. 1274 1275 \see RemoveSet(const char*) 1276 1277 \since Haiku R1 1278*/ 1279 1280 1281/*! 1282 \fn BString& BString::MoveInto(BString& into, int32 from, int32 length) 1283 \brief Move the BString data (or part of it) into another BString. 1284 1285 \param into The BString to move the string into. 1286 \param from The offset (zero-based) in bytes where to begin the move. 1287 \param length The number of bytes to move. 1288 1289 \return This method always returns \c into. 1290 1291 \since BeOS R5 1292*/ 1293 1294 1295/*! 1296 \fn void BString::MoveInto(char* into, int32 from, int32 length) 1297 \brief Move the BString data (or part of it) into the given buffer. 1298 1299 \param into The buffer to move the string into. 1300 \param from The offset (zero-based) in bytes where to begin the move. 1301 \param length The number of bytes to move. 1302 1303 \since BeOS R5 1304*/ 1305 1306 1307/*! 1308 \fn BString& BString::MoveCharsInto(BString& into, int32 fromCharOffset, 1309 int32 charCount) 1310 \brief UTF-8 aware version of MoveInto(BString&, int32, int32) 1311 1312 \param into The BString where to move the string into. 1313 \param fromCharOffset The offset (zero-based) in UTF-8 characters where to 1314 begin the move. 1315 \param charCount The number of UTF-8 characters to move. 1316 1317 \see MoveInto(BString&, int32, int32) 1318 1319 \since Haiku R1 1320*/ 1321 1322 1323/*! 1324 \fn bool BString::MoveCharsInto(char* into, int32* intoLength, 1325 int32 fromCharOffset, int32 charCount) 1326 \brief UTF-8 aware version of MoveInto(char*, int32*, int32, int32). 1327 1328 \param into The buffer to move the string into. 1329 \param intoLength The offset (zero-based) in bytes where to begin the move. 1330 \param fromCharOffset The offset (zero-based) in UTF-8 characters where to 1331 begin the move. 1332 \param charCount The number of UTF-8 characters to move. 1333 1334 \returns \c false if \a into was \c NULL, \c true otherwise. 1335 1336 \see MoveInto(char*, int32*, int32, int32) 1337 1338 \since Haiku R1 1339*/ 1340 1341 1342//! @} 1343 1344 1345/*! 1346 \name Comparison 1347 1348 There are two different comparison methods. First of all there 1349 is the whole range of operators that return a boolean value, secondly 1350 there are methods that return an integer value, both case sensitive 1351 and case insensitive. 1352 1353 There are also global comparison operators and global compare functions. 1354 You might need these in case you have a sort routine that takes a generic 1355 comparison function, such as BList::SortItems(). 1356 See the String.h documentation file to see the specifics, though basically 1357 there are the same as implemented in this class. 1358*/ 1359 1360 1361//! @{ 1362 1363 1364/*! 1365 \fn bool BString::operator<(const BString& string) const 1366 \brief Lexicographically compare if this BString is less than the given 1367 \a string. 1368 1369 \param string The \a string to compare against. 1370 1371 \since BeOS R5 1372*/ 1373 1374 1375/*! 1376 \fn bool BString::operator<=(const BString& string) const 1377 \brief Lexicographically compare if this BString is less than or equal to 1378 the given \a string. 1379 1380 \param string The \a string to compare against. 1381 1382 \since BeOS R5 1383*/ 1384 1385 1386/*! 1387 \fn bool BString::operator==(const BString& string) const 1388 \brief Lexicographically compare if this BString is equal to the given 1389 \a string. 1390 1391 \param string The \a string to compare against. 1392 1393 \since BeOS R5 1394*/ 1395 1396 1397/*! 1398 \fn bool BString::operator>=(const BString& string) const 1399 \brief Lexicographically compare if this BString is greater than or equal 1400 to the given \a string. 1401 1402 \param string The string to compare against. 1403 1404 \since BeOS R5 1405*/ 1406 1407 1408/*! 1409 \fn bool BString::operator>(const BString& string) const 1410 \brief Lexicographically compare if this BString is greater than the given 1411 \a string. 1412 1413 \param string The string to compare against. 1414 1415 \since BeOS R5 1416*/ 1417 1418 1419/*! 1420 \fn bool BString::operator!=(const BString& string) const 1421 \brief Lexicographically compare if this BString is not equal to the given 1422 \a string. 1423 1424 \param string The string to compare against. 1425 1426 \since BeOS R5 1427*/ 1428 1429 1430/*! 1431 \fn bool BString::operator<(const char* string) const 1432 \brief Lexicographically compare if this BString is less than the given 1433 \a string. 1434 1435 \param string The string to compare against. 1436 1437 \since BeOS R5 1438*/ 1439 1440 1441/*! 1442 \fn bool BString::operator<=(const char* string) const 1443 \brief Lexicographically compare if this BString is less than or equal to 1444 the given \a string. 1445 1446 \param string The \a string to compare against. 1447 1448 \since BeOS R5 1449*/ 1450 1451 1452/*! 1453 \fn bool BString::operator==(const char* string) const 1454 \brief Lexicographically compare if this BString is equal to the given 1455 \a string. 1456 1457 \param string The \a string to compare against. 1458 1459 \since BeOS R5 1460*/ 1461 1462 1463/*! 1464 \fn bool BString::operator>=(const char* string) const 1465 \brief Lexicographically compare if this string is more than or equal 1466 to a given \a string. 1467 1468 \param string The \a string to compare against. 1469 1470 \since BeOS R5 1471*/ 1472 1473 1474/*! 1475 \fn bool BString::operator>(const char* string) const 1476 \brief Lexicographically compare if this string is more than a given string. 1477 1478 \param string The \a string to compare against. 1479 1480 \since BeOS R5 1481*/ 1482 1483 1484/*! 1485 \fn bool BString::operator!=(const char* string) const 1486 \brief Lexicographically compare if this string is not equal to a given 1487 string. 1488 1489 \param string The \a string to compare against. 1490 1491 \since BeOS R5 1492*/ 1493 1494 1495/*! 1496 \fn BString::operator const char*() const 1497 \brief Return an empty string. 1498 1499 \return An empty string. 1500 1501 \since Haiku R1 1502*/ 1503 1504 1505/*! 1506 \fn int BString::Compare(const BString& string) const 1507 \brief Lexicographically compare this BString to another \a string. 1508 1509 \param string The \a string to compare against. 1510 1511 \return An int representing the strings relationship to each other. 1512 \retval >0 The BString sorts lexicographically after \a string. 1513 \retval =0 The BString is equal to \a string. 1514 \retval <0 The BString sorts lexicographically before \a string. 1515 1516 \since BeOS R5 1517*/ 1518 1519 1520/*! 1521 \fn int BString::Compare(const char* string) const 1522 \brief Lexicographically compare this BString to another \a string. 1523 1524 \param string The \a string to compare against. 1525 1526 \return An int representing the strings relationship to each other. 1527 \retval >0 The BString sorts lexicographically after \a string. 1528 \retval =0 The BString is equal to \a string. 1529 \retval <0 The BString sorts lexicographically before \a string. 1530 1531 \sa Compare(const BString&) const 1532 1533 \since BeOS R5 1534*/ 1535 1536 1537/*! 1538 \fn int BString::Compare(const BString& string, int32 length) const 1539 \brief Lexicographically compare \a length characters of this BString to 1540 another \a string. 1541 1542 \param string The \a string to compare against. 1543 \param length The number of bytes to compare. 1544 1545 \return An int representing the strings relationship to each other. 1546 \retval >0 The BString sorts lexicographically after \a string. 1547 \retval =0 The BString is equal to \a string. 1548 \retval <0 The BString sorts lexicographically before \a string. 1549 1550 \since BeOS R5 1551*/ 1552 1553 1554/*! 1555 \fn int BString::Compare(const char* string, int32 length) const 1556 \brief Lexicographically compare \a length characters of this BString to 1557 another \a string. 1558 1559 \param string The \a string to compare against. 1560 \param length The number of bytes to compare. 1561 1562 \return An int representing the strings relationship to each other. 1563 \retval >0 The BString sorts lexicographically after \a string. 1564 \retval =0 The BString is equal to \a string. 1565 \retval <0 The BString sorts lexicographically before \a string. 1566 1567 \sa Compare(const BString&, int32) const 1568 1569 \since BeOS R5 1570*/ 1571 1572 1573/*! 1574 \fn int BString::CompareAt(size_t offset, const BString& string, 1575 int32 length) const 1576 \brief Lexicographically compare \a length of characters of this BString to 1577 another \a string, starting at \a offset. 1578 1579 \param offset The offset (in bytes) to start comparison. 1580 \param string The \a string to compare against. 1581 \param length The number of bytes to compare. 1582 1583 \return An int representing the strings relationship to each other. 1584 \retval >0 The BString sorts lexicographically after \a string. 1585 \retval =0 The BString is equal to \a string. 1586 \retval <0 The BString sorts lexicographically before \a string. 1587 1588 \sa Compare(const BString&, int32) const 1589 1590 \since Haiku R1 1591*/ 1592 1593 1594/*! 1595 \fn int BString::CompareChars(const BString& string, int32 charCount) const 1596 \brief UTF-8 aware version of Compare(const BString&, int32). 1597 1598 \param string The \a string to compare against. 1599 \param charCount The number of UTF-8 characters to compare. 1600 1601 \return An int representing the strings relationship to each other. 1602 \retval >0 The BString sorts lexicographically after \a string. 1603 \retval =0 The BString is equal to \a string. 1604 \retval <0 The BString sorts lexicographically before \a string. 1605 1606 \see Compare(const BString&, int32) 1607 1608 \since Haiku R1 1609*/ 1610 1611 1612/*! 1613 \fn int BString::CompareChars(const char* string, int32 charCount) const 1614 \brief UTF-8 aware version of Compare(const char*, int32). 1615 1616 \param string The \a string to compare against. 1617 \param charCount The number of UTF-8 characters to compare. 1618 1619 \return An int representing the strings relationship to each other. 1620 \retval >0 The BString sorts lexicographically after \a string. 1621 \retval =0 The BString is equal to \a string. 1622 \retval <0 The BString sorts lexicographically before \a string. 1623 1624 \see Compare(const char*, int32) 1625 1626 \since Haiku R1 1627*/ 1628 1629 1630/*! 1631 \fn int BString::ICompare(const BString& string) const 1632 \brief Lexicographically compare this BString to another \a string 1633 case-insensitively. 1634 1635 \param string The \a string to compare against. 1636 1637 \return An int representing the strings relationship to each other. 1638 \retval >0 The BString sorts lexicographically after \a string. 1639 \retval =0 The BString is equal to \a string. 1640 \retval <0 The BString sorts lexicographically before \a string. 1641 1642 \sa Compare(const BString&) const 1643 1644 \since BeOS R5 1645*/ 1646 1647 1648/*! 1649 \fn int BString::ICompare(const char* string) const 1650 \brief Lexicographically compare this BString to another \a string 1651 case-insensitively. 1652 1653 \param string The \a string to compare against. 1654 1655 \return An int representing the strings relationship to each other. 1656 \retval >0 The BString sorts lexicographically after \a string. 1657 \retval =0 The BString is equal to \a string. 1658 \retval <0 The BString sorts lexicographically before \a string. 1659 1660 \sa Compare(const BString&) const 1661 1662 \since BeOS R5 1663*/ 1664 1665 1666/*! 1667 \fn int BString::ICompare(const BString& string, int32 length) const 1668 \brief Lexicographically compare \a length characters of this BString 1669 to another \a string. 1670 1671 \param string The \a string to compare against. 1672 \param length The number of characters to compare. 1673 1674 \return An int representing the strings relationship to each other. 1675 \retval >0 The BString sorts lexicographically after \a string. 1676 \retval =0 The BString is equal to \a string. 1677 \retval <0 The BString sorts lexicographically before \a string. 1678 1679 \sa Compare(const BString&, int32) const 1680 1681 \since BeOS R5 1682*/ 1683 1684 1685/*! 1686 \fn int BString::ICompare(const char* string, int32 length) const 1687 \brief Lexicographically compare \a length characters of this BString 1688 to another \a string. 1689 1690 \param string The \a string to compare against. 1691 \param length The number of characters to compare 1692 1693 \return An int representing the strings relationship to each other. 1694 \retval >0 The BString sorts lexicographically after \a string. 1695 \retval =0 The BString is equal to \a string. 1696 \retval <0 The BString sorts lexicographically before \a string. 1697 1698 \sa Compare(const BString&, int32) const 1699 1700 \since BeOS R5 1701*/ 1702 1703 1704//! @} 1705 1706 1707/*! 1708 \name Searching 1709*/ 1710 1711 1712//! @{ 1713 1714 1715/*! 1716 \fn int32 BString::FindFirst(const BString& string) const 1717 \brief Find the first occurrence of the given \a string. 1718 1719 \param string The \a string to search for. 1720 1721 \return The offset (zero-based) into the data where the given BString 1722 was found or \c B_ERROR if we could not find \c string. 1723 1724 \sa IFindFirst(const BString&) const 1725 1726 \since BeOS R5 1727*/ 1728 1729 1730/*! 1731 \fn int32 BString::FindFirst(const char* string) const 1732 \brief Find the first occurrence of the given \a string. 1733 1734 \param string The \a string to search for. 1735 1736 \return The offset (zero-based) into the data where the given string 1737 was found, \c B_BAD_VALUE if the \c string pointer is invalid, 1738 or \c B_ERROR if we could not find \c string. 1739 1740 \sa IFindFirst(const char*) const 1741 \sa StartsWith(const char*) const 1742 \sa StartsWith(const char*, int32) const 1743 1744 \since BeOS R5 1745*/ 1746 1747 1748/*! 1749 \fn int32 BString::FindFirst(const BString& string, int32 fromOffset) const 1750 \brief Find the first occurrence of the given \a string starting from 1751 the given offset. 1752 1753 \param string The \a string to search for. 1754 \param fromOffset The offset in bytes to start the search. 1755 1756 \return An integer which is the offset (zero-based) into the data 1757 where the given BString was found or \c B_ERROR if we could 1758 not find the \c string. 1759 1760 \sa IFindFirst(const BString&, int32) const 1761 \sa StartsWith(const char*, int32) const 1762 1763 \since BeOS R5 1764*/ 1765 1766 1767/*! 1768 \fn int32 BString::FindFirst(const char* string, int32 fromOffset) const 1769 \brief Find the first occurrence of the given \a string, starting from the 1770 given offset. 1771 1772 \param string The \a string to search for. 1773 \param fromOffset The offset in bytes to start the search. 1774 1775 \return The offset (zero-based) into the data where the given string 1776 was found, \c B_BAD_VALUE if the \c string pointer is invalid, 1777 or \c B_ERROR if we could not find the \c string. 1778 1779 \sa IFindFirst(const char*, int32) const 1780 1781 \since BeOS R5 1782*/ 1783 1784 1785/*! 1786 \fn int32 BString::FindFirst(char c) const 1787 \brief Find the first occurrence of the given character. 1788 1789 \param c The character to search for. 1790 1791 \return The offset (zero-based) into the data where the given character 1792 was found, or \c B_ERROR if we could not find the character. 1793 1794 \since BeOS R5 1795*/ 1796 1797 1798/*! 1799 \fn int32 BString::FindFirst(char c, int32 fromOffset) const 1800 \brief Find the first occurrence of the given character, starting from the 1801 given offset. 1802 1803 \param c The character to search for. 1804 \param fromOffset The offset where to start the search. 1805 1806 \return The offset (zero-based) into the data where the given character 1807 was found, or \c B_ERROR if we could not find the character. 1808 1809 \since BeOS R5 1810*/ 1811 1812 1813/*! 1814 \fn int32 BString::FindFirstChars(const BString& string, 1815 int32 fromCharOffset) const 1816 \brief UTF-8 aware version of FindFirst(const BString&, int32). 1817 1818 \param string The \a string to search for. 1819 \param fromCharOffset The offset in UTF-8 characters to start the search. 1820 1821 \return An integer which is the offset (zero-based) into the data 1822 where the given BString was found or \c B_ERROR if we could 1823 not find the \c string. 1824 1825 \see FindFirst(const BString&, int32) 1826 1827 \since Haiku R1 1828*/ 1829 1830 1831/*! 1832 \fn int32 BString::FindFirstChars(const char* string, 1833 int32 fromCharOffset) const 1834 \brief UTF-8 aware version of FindFirst(const char*, int32). 1835 1836 \param string The \a string to search for. 1837 \param fromCharOffset The offset in UTF-8 characters to start the search. 1838 1839 \see FindChars(const char*, int32) 1840 1841 \since Haiku R1 1842*/ 1843 1844 1845/*! 1846 \fn int32 BString::FindLast(const BString& string) const 1847 \brief Find the last occurrence of the given \a string. 1848 1849 \param string The \a string to search for. 1850 1851 \return The offset (zero-based) into the data where the given BString 1852 was found, or \c B_ERROR if we could not find the \c string. 1853 1854 \sa IFindLast(const BString&) const 1855 \sa EndsWith(const BString&) const 1856 1857 \since BeOS R5 1858*/ 1859 1860 1861/*! 1862 \fn int32 BString::FindLast(const char* string) const 1863 \brief Find the last occurrence of the given string. 1864 1865 \param string The string to search for. 1866 1867 \return The offset in bytes (zero-based) into the data where the given 1868 string was found, \c B_BAD_VALUE if the \c string pointer is invalid, 1869 or \c B_ERROR if we could not find the \c string. 1870 1871 \sa IFindLast(const char*) const 1872 \sa EndsWith(const char*) const 1873 \sa EndsWith(const char*, int32) const 1874 1875 \since BeOS R5 1876*/ 1877 1878 1879/*! 1880 \fn int32 BString::FindLast(const BString& string, int32 beforeOffset) const 1881 \brief Find the last occurrence of the given BString, 1882 starting from the given offset, and going backwards. 1883 1884 \param string The BString to search for. 1885 \param beforeOffset The offset in bytes to start the search. 1886 1887 \return The offset (zero-based) into the data where the given BString 1888 was found, or \c B_ERROR if we could not find the \c string. 1889 1890 \sa IFindLast(const BString&, int32) const 1891 1892 \since BeOS R5 1893*/ 1894 1895 1896/*! 1897 \fn int32 BString::FindLast(const char* string, int32 beforeOffset) const 1898 \brief Find the last occurrence of the given string, 1899 starting from the given offset, and going backwards. 1900 1901 \param string The string to search for. 1902 \param beforeOffset The offset in bytes to start the search. 1903 1904 \return The offset (zero-based) into the data where the given string 1905 was found, \c B_BAD_VALUE if the \c string pointer is invalid, 1906 or \c B_ERROR if we could not find the \c string. 1907 1908 \sa IFindLast(const char*, int32) const 1909 1910 \since BeOS R5 1911*/ 1912 1913 1914/*! 1915 \fn int32 BString::FindLast(char c) const 1916 \brief Find the last occurrence of the given character. 1917 1918 \param c The character to search for. 1919 \return The offset (zero-based) into the data where the given BString 1920 was found, or \c B_ERROR if we could not find the character. 1921 1922 \since BeOS R5 1923*/ 1924 1925 1926/*! 1927 \fn int32 BString::FindLast(char c, int32 beforeOffset) const 1928 \brief Find the last occurrence of the given character, 1929 starting from the given offset going backwards from the end. 1930 1931 \param c The character to search for. 1932 \param beforeOffset The offset in bytes to start the search. 1933 1934 \return The offset (zero-based) into the data where the given character 1935 was found, or \c B_ERROR Could not find the character. 1936 1937 \since BeOS R5 1938*/ 1939 1940 1941/*! 1942 \fn int32 BString::FindLastChars(const BString& string, 1943 int32 beforeCharOffset) const 1944 \brief UTF-8 aware version of FindLast(const BString&, int32). 1945 1946 \param string The BString to search for. 1947 \param beforeCharOffset The offset in UTF-8 characters to start the search. 1948 1949 \return The offset in bytes (zero-based) into the data where the given 1950 BString was found, or \c B_ERROR if we could not find the 1951 \c string. 1952 1953 \see FindLast(const BString&, int32) 1954 1955 \since Haiku R1 1956*/ 1957 1958 1959/*! 1960 \fn int32 BString::FindLastChars(const char* string, 1961 int32 beforeCharOffset) const 1962 \brief UTF-8 aware version of FindLast(const char*, int32). 1963 1964 \param string The string to search for. 1965 \param beforeCharOffset The offset in UTF-8 characters to start the search. 1966 1967 \return The offset in bytes (zero-based) into the data where the given 1968 string was found, \c B_BAD_VALUE if the \c string pointer is 1969 invalid, or \c B_ERROR if we could not find the \c string. 1970 1971 \see FindLast(const char*, int32) 1972 1973 \since Haiku R1 1974*/ 1975 1976 1977/*! 1978 \fn int32 BString::IFindFirst(const BString& string) const 1979 \brief Find the first occurrence of the given \a string case-insensitively. 1980 1981 \copydetails FindFirst(const BString&) const 1982*/ 1983 1984 1985/*! 1986 \fn int32 BString::IFindFirst(const char* string) const 1987 \brief Find the first occurrence of the given \a string case-insensitively. 1988 1989 \copydetails FindFirst(const char*) const 1990*/ 1991 1992 1993/*! 1994 \fn int32 BString::IFindFirst(const BString& string, int32 fromOffset) const 1995 \brief Find the first occurrence of the given BString case-insensitively, 1996 starting from the given offset. 1997 1998 \copydetails FindFirst(const BString&, int32) const 1999*/ 2000 2001 2002/*! 2003 \fn int32 BString::IFindFirst(const char* string, int32 fromOffset) const 2004 \brief Find the first occurrence of the given string case-insensitively, 2005 starting from the given offset. 2006 2007 \copydetails FindFirst(const char*, int32) const 2008*/ 2009 2010 2011/*! 2012 \fn int32 BString::IFindLast(const BString& string) const 2013 \brief Find the last occurrence of the given BString case-insensitively. 2014 2015 \copydetails FindLast(const BString&) const 2016*/ 2017 2018 2019/*! 2020 \fn int32 BString::IFindLast(const char* string) const 2021 \brief Find the last occurrence of the given string case-insensitively. 2022 2023 \copydetails FindLast(const char*) const 2024*/ 2025 2026 2027/*! 2028 \fn int32 BString::IFindLast(const BString& string, int32 beforeOffset) const 2029 \brief Find the last occurrence of the given BString case-insensitively, 2030 starting from the given offset going backwards. 2031 2032 \copydetails FindLast(const BString&, int32) const 2033*/ 2034 2035 2036/*! 2037 \fn int32 BString::IFindLast(const char* string, int32 beforeOffset) const 2038 \brief Find the last occurrence of the given string case-insensitively, 2039 starting from the given offset going backwards. 2040 2041 \copydetails FindLast(const char*, int32) const 2042*/ 2043 2044 2045/*! 2046 \fn bool BString::StartsWith(const BString& string) const 2047 \brief Returns whether or not the BString starts with \a string. 2048 2049 \param string The \a string to search for. 2050 2051 \return \c true if the BString started with \a string, \c false otherwise. 2052 2053 \since Haiku R1 2054*/ 2055 2056 2057/*! 2058 \fn bool BString::StartsWith(const char* string) const 2059 \brief Returns whether or not the BString starts with \a string. 2060 2061 \param string The \a string to search for. 2062 2063 \return \c true if the BString started with \a string, \c false otherwise. 2064 2065 \since Haiku R1 2066*/ 2067 2068 2069/*! 2070 \fn bool BString::StartsWith(const char* string, int32 length) const 2071 \brief Returns whether or not the BString starts with \a length characters 2072 of \a string. 2073 2074 \param string The \a string to search for. 2075 \param length The number of characters (bytes) of \a string to search for. 2076 2077 \return \c true if the BString started with \a length characters of 2078 \a string, \c false otherwise. 2079 2080 \since Haiku R1 2081*/ 2082 2083 2084/*! 2085 \fn bool BString::IStartsWith(const BString& string) const 2086 \brief Returns whether or not the BString starts with \a string 2087 case-insensitively. 2088 2089 \param string The \a string to search for. 2090 2091 \return \c true if the BString started with \a string case-insensitively, 2092 \c false otherwise. 2093 2094 \since Haiku R1 2095*/ 2096 2097 2098/*! 2099 \fn bool BString::IStartsWith(const char* 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, int32 length) const 2114 \brief Returns whether or not the BString starts with \a length characters 2115 of \a string case-insensitively. 2116 2117 \param string The \a string to search for. 2118 \param length The number of characters (bytes) of \a string to search for. 2119 2120 \return \c true if the BString started with \a length characters of 2121 \a string case-insensitively, \c false otherwise. 2122 2123 \since Haiku R1 2124*/ 2125 2126 2127/*! 2128 \fn bool BString::EndsWith(const BString& string) const 2129 \brief Returns whether or not the BString ends with \a string. 2130 2131 \param string The \a string to search for. 2132 2133 \return \c true if the BString ended with \a string, \c false otherwise. 2134 2135 \since Haiku R1 2136*/ 2137 2138 2139/*! 2140 \fn bool BString::EndsWith(const char* string) const 2141 \brief Returns whether or not the BString ends with \a string. 2142 2143 \param string The \a string to search for. 2144 2145 \return \c true if the BString ended with \a string, \c false otherwise. 2146 2147 \since Haiku R1 2148*/ 2149 2150 2151/*! 2152 \fn bool BString::EndsWith(const char* string, int32 length) const 2153 \brief Returns whether or not the BString ends with \a length characters 2154 of \a string. 2155 2156 \param string The \a string to search for. 2157 \param length The number of characters (bytes) of \a string to search for. 2158 2159 \return \c true if the BString ended with \a length characters of 2160 \a string, \c false otherwise. 2161 2162 \since Haiku R1 2163*/ 2164 2165 2166/*! 2167 \fn bool BString::IEndsWith(const BString& string) const 2168 \brief Returns whether or not the BString ends with \a string 2169 case-insensitively. 2170 2171 \param string The \a string to search for. 2172 2173 \return \c true if the BString ended with \a string case-insensitively, 2174 \c false otherwise. 2175 2176 \since Haiku R1 2177*/ 2178 2179 2180/*! 2181 \fn bool BString::IEndsWith(const char* 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, int32 length) const 2196 \brief Returns whether or not the BString ends with \a length characters 2197 of \a string case-insensitively. 2198 2199 \param string The \a string to search for. 2200 \param length The number of characters (bytes) of \a string to search for. 2201 2202 \return \c true if the BString ended with \a length characters of 2203 \a string case-insensitively, \c false otherwise. 2204 2205 \since Haiku R1 2206*/ 2207 2208 2209//! @} 2210 2211 2212/*! 2213 \name Replacing 2214*/ 2215 2216 2217//! @{ 2218 2219 2220/*! 2221 \fn BString& BString::ReplaceFirst(char replaceThis, char withThis) 2222 \brief Replace the first occurrence of a character with another character. 2223 2224 \param replaceThis The character to replace. 2225 \param withThis The character to put in its place. 2226 2227 \return This method always returns \c *this. 2228 2229 \sa IReplaceFirst(char, char) 2230 2231 \since BeOS R5 2232*/ 2233 2234 2235/*! 2236 \fn BString& BString::ReplaceLast(char replaceThis, char withThis) 2237 \brief Replace the last occurrence of a character with another character. 2238 2239 \param replaceThis The character to replace. 2240 \param withThis The character to put in its place 2241 2242 \return This method always returns \c *this. 2243 2244 \sa IReplaceLast(char, char) 2245 2246 \since BeOS R5 2247*/ 2248 2249 2250/*! 2251 \fn BString& BString::ReplaceAll(char replaceThis, char withThis, 2252 int32 fromOffset) 2253 \brief Replace all occurrences of a character with another character. 2254 2255 \param replaceThis The character to replace. 2256 \param withThis The character to put in its place 2257 \param fromOffset The offset in bytes to start looking for the character. 2258 2259 \return This method always returns \c *this. 2260 2261 \sa IReplaceAll(char, char, int32) 2262 2263 \since BeOS R5 2264*/ 2265 2266 2267/*! 2268 \fn BString& BString::Replace(char replaceThis, char withThis, 2269 int32 maxReplaceCount, int32 fromOffset) 2270 \brief Replace a number of occurrences of a character with another 2271 character. 2272 2273 \param replaceThis The character to replace. 2274 \param withThis The character to put in its place 2275 \param maxReplaceCount The maximum number of characters that should be 2276 replaced. 2277 \param fromOffset The offset in bytes to start looking for the character 2278 2279 \return This method always returns \c *this. 2280 2281 \sa IReplace(char, char, int32, int32) 2282 2283 \since BeOS R5 2284*/ 2285 2286 2287/*! 2288 \fn BString& BString::ReplaceFirst(const char* replaceThis, 2289 const char* withThis) 2290 \brief Replace the first occurrence of a string with another string. 2291 2292 \param replaceThis The string to replace. 2293 \param withThis The string to put in its place 2294 2295 \return This method always returns \c *this. 2296 2297 \sa IReplaceFirst(const char*, const char*) 2298 2299 \since BeOS R5 2300*/ 2301 2302 2303/*! 2304 \fn BString& BString::ReplaceLast(const char* replaceThis, 2305 const char* withThis) 2306 \brief Replace the last occurrence of a string with another string. 2307 2308 \param replaceThis The string to replace. 2309 \param withThis The string to put in its place 2310 2311 \return This method always returns \c *this. 2312 2313 \sa IReplaceLast(const char*, const char*) 2314 2315 \since BeOS R5 2316*/ 2317 2318 2319/*! 2320 \fn BString& BString::ReplaceAll(const char* replaceThis, 2321 const char* withThis, int32 fromOffset) 2322 \brief Replace all occurrences of a string with another string. 2323 2324 \param replaceThis The string to replace. 2325 \param withThis The string to put in its place 2326 \param fromOffset The offset in bytes to start looking for the string. 2327 2328 \return This method always returns \c *this. 2329 2330 \sa IReplaceAll(const char*, const char*, int32) 2331 2332 \since BeOS R5 2333*/ 2334 2335 2336/*! 2337 \fn BString& BString::Replace(const char* replaceThis, 2338 const char* withThis, int32 maxReplaceCount, int32 fromOffset) 2339 \brief Replace a number of occurrences of a string with another string. 2340 2341 \param replaceThis The string to replace. 2342 \param withThis The string to put in its place 2343 \param maxReplaceCount The maximum number of occurrences that should 2344 be replaced. 2345 \param fromOffset The offset in bytes to start looking for the string. 2346 2347 \return This method always returns \c *this. 2348 2349 \sa IReplace(const char*, const char*, int32, int32) 2350 2351 \since BeOS R5 2352*/ 2353 2354 2355/*! 2356 \fn BString& BString::ReplaceAllChars(const char* replaceThis, 2357 const char* withThis, int32 fromCharOffset) 2358 \brief UTF-8 aware version of ReplaceAll(const char*, const char*, int32). 2359 2360 \param replaceThis The string to replace. 2361 \param withThis The string to put in its place 2362 \param fromCharOffset The offset in UTF-8 characters to start looking for 2363 the string. 2364 2365 \return This method always returns \c *this. 2366 2367 \see ReplaceAll(const char*, const char*, int32) 2368 2369 \since Haiku R1 2370*/ 2371 2372 2373/*! 2374 \fn BString& BString::ReplaceChars(const char* replaceThis, 2375 const char* withThis, int32 maxReplaceCount, int32 fromCharOffset) 2376 \brief UTF-8 aware version of 2377 ReplaceAll(const char*, const char*, int32, int32). 2378 2379 \param replaceThis The string to replace. 2380 \param withThis The string to put in its place 2381 \param maxReplaceCount The maximum number of occurrences that should 2382 be replaced. 2383 \param fromCharOffset The offset in UTF-8 characters to start looking for 2384 the string. 2385 2386 \return This method always returns \c *this. 2387 2388 \see ReplaceAll(const char*, const char*, int32, int32) 2389 2390 \since Haiku R1 2391*/ 2392 2393 2394/*! 2395 \fn BString& BString::IReplaceFirst(char replaceThis, char withThis) 2396 \brief Replace the first occurrence of a character with another 2397 character case-insensitively. 2398 2399 \param replaceThis The string to replace. 2400 \param withThis The string to put in its place 2401 2402 \sa ReplaceFirst(char, char) 2403 2404 \since BeOS R5 2405*/ 2406 2407 2408/*! 2409 \fn BString& BString::IReplaceLast(char replaceThis, char withThis) 2410 \brief Replace the last 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 ReplaceLast(char, char) 2417 2418 \since BeOS R5 2419*/ 2420 2421 2422/*! 2423 \fn BString& BString::IReplaceAll(char replaceThis, char withThis, 2424 int32 fromOffset) 2425 \brief Replace all occurrences of a character with another character 2426 case-insensitively. 2427 2428 \param replaceThis The string to replace. 2429 \param withThis The string to put in its place 2430 \param fromOffset The offset where to start looking for the string 2431 2432 \sa ReplaceAll(char, char, int32) 2433 2434 \since BeOS R5 2435*/ 2436 2437 2438/*! 2439 \fn BString& BString::IReplace(char replaceThis, char withThis, 2440 int32 maxReplaceCount, int32 fromOffset) 2441 \brief Replace a number of occurrences of a character with another 2442 character case-insensitively. 2443 2444 \param replaceThis The char to replace. 2445 \param withThis The char to put in its place 2446 \param maxReplaceCount The maximum number of occurrences that should 2447 be replaced. 2448 \param fromOffset The offset where to start looking for the string 2449 2450 \sa Replace(char, char, int32, int32) 2451 2452 \since BeOS R5 2453*/ 2454 2455 2456/*! 2457 \fn BString& BString::IReplaceFirst(const char* replaceThis, 2458 const char* withThis) 2459 \brief Replace the first occurrence of a string with another string 2460 case-insensitively. 2461 2462 \param replaceThis The string to replace. 2463 \param withThis The string to put in its place. 2464 2465 \sa ReplaceFirst(const char*, const char*) 2466 2467 \since BeOS R5 2468*/ 2469 2470 2471/*! 2472 \fn BString& BString::IReplaceLast(const char* replaceThis, 2473 const char* withThis) 2474 \brief Replace the last occurrence of a string with another string. Case-insensitive. 2475 2476 \param replaceThis The string to replace. 2477 \param withThis The string to put in its place. 2478 2479 \sa ReplaceLast(const char*, const char*) 2480 2481 \since BeOS R5 2482*/ 2483 2484 2485/*! 2486 \fn BString& BString::IReplaceAll(const char* replaceThis, 2487 const char* withThis, int32 fromOffset) 2488 \brief Replace all occurrences of a string with another string 2489 case-insensitively. 2490 2491 \param replaceThis The string to replace. 2492 \param withThis The string to put in its place. 2493 \param fromOffset The offset where to start looking for the string. 2494 2495 \sa ReplaceAll(const char*, const char*, int32) 2496 2497 \since BeOS R5 2498*/ 2499 2500 2501/*! 2502 \fn BString& BString::IReplace(const char* replaceThis, 2503 const char* withThis, int32 maxReplaceCount, int32 fromOffset) 2504 \brief Replace a number of occurrences of a string with another string 2505 case-insensitively. 2506 2507 \param replaceThis The string to replace. 2508 \param withThis The string to put in its place 2509 \param maxReplaceCount The maximum number of occurrences that should 2510 be replaced. 2511 \param fromOffset The offset where to start looking for the string 2512 2513 \sa Replace(const char*, const char*, int32, int32) 2514 2515 \since BeOS R5 2516*/ 2517 2518 2519/*! 2520 \fn BString& BString::ReplaceSet(const char* setOfBytes, char with) 2521 \brief Replaces characters that are in a certain set with a chosen 2522 character. 2523 2524 \param setOfBytes The set of characters that need to be replaced. 2525 \param with The character to replace the occurrences with. 2526 2527 \return This method always returns \c *this. 2528 2529 \since BeOS R5 2530*/ 2531 2532 2533/*! 2534 \fn BString& BString::ReplaceSet(const char* setOfBytes, const char* with) 2535 \brief Replaces characters that are in a certain set with a chosen string. 2536 2537 \param setOfBytes The set of chars that need to be replaced. 2538 \param with The string to replace the occurrences with. 2539 2540 \return This method always returns \c *this. 2541 2542 \since BeOS R5 2543*/ 2544 2545 2546/*! 2547 \fn BString& BString::ReplaceCharsSet(const char* setOfChars, 2548 const char* with) 2549 \brief UTF-8 aware version of ReplaceSet(const char*, const char*) 2550 2551 \param setOfChars The set of UTF-8 characters 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 Haiku R1 2557*/ 2558 2559 2560//! @} 2561 2562 2563/*! 2564 \name Indexing 2565*/ 2566 2567 2568//! @{ 2569 2570 2571/*! 2572 \fn char BString::operator[](int32 index) const 2573 \brief Returns the character in the string at the given offset. 2574 2575 This function can be used to read a byte. There is no bound checking 2576 though, use ByteAt() if you don't know if the \c index parameter is 2577 valid. 2578 2579 \param index The index (zero-based) of the byte to get. 2580 2581 \return Returns a reference to the specified byte. 2582 2583 \since BeOS R5 2584*/ 2585 2586 2587/*! 2588 \fn char BString::ByteAt(int32 index) const 2589 \brief Returns the character in the string at the given offset. 2590 2591 This function can be used to read a single byte. 2592 2593 \param index The index (zero-based) of the byte to get. 2594 2595 \return A reference to the specified byte, if out of bounds return 0. 2596 2597 \since BeOS R5 2598*/ 2599 2600 2601/*! 2602 \fn const char* BString::CharAt(int32 charIndex, int32* bytes) const 2603 \brief UTF-8 aware version of ByteAt(int32). 2604 2605 \param charIndex The index (zero-based) of the UTF-8 character to get. 2606 \param bytes An int32 pointer to hold the UTF-8 character. 2607 2608 \return A reference to the specified UTF-8 character, if out of bounds 2609 return 0. 2610 2611 \see ByteAt(int32) 2612 2613 \since Haiku R1 2614*/ 2615 2616 2617/*! 2618 \fn bool BString::CharAt(int32 charIndex, char* buffer, 2619 int32* bytes) const 2620 \brief UTF-8 aware version of ByteAt(int32) with a \a buffer parameter. 2621 2622 \param charIndex The index (zero-based) of the UTF-8 character to get. 2623 \param buffer Set to the position in the string where the character is 2624 found. 2625 \param bytes An int32 pointer to hold the UTF-8 character. 2626 2627 \see ByteAt(int32, char*, int32*) 2628 2629 \since Haiku R1 2630*/ 2631 2632 2633//! @} 2634 2635 2636/*! 2637 \name Low-Level Manipulation 2638*/ 2639 2640 2641//! @{ 2642 2643 2644/*! 2645 \fn char* BString::LockBuffer(int32 maxLength) 2646 \brief Locks the buffer and return the internal string for manipulation. 2647 2648 If you want to do any low-level string manipulation on the internal buffer, 2649 you should call this method. This method includes the possibility to grow 2650 the buffer so that you don't have to worry about that yourself. 2651 2652 Make sure you call UnlockBuffer() when you're done with the manipulation. 2653 2654 \param maxLength The size of the buffer in bytes. If you don't want a 2655 bigger buffer, passing anything under the length of the string will 2656 simply return it as is. 2657 2658 \return A pointer to the buffer to manipulate. 2659 2660 \sa UnlockBuffer() 2661 2662 \since BeOS R5 2663*/ 2664 2665 2666/*! 2667 \fn BString& BString::UnlockBuffer(int32 length) 2668 \brief Unlocks the buffer after you are done with low-level manipulation. 2669 2670 \param length The length in bytes to trim the string to in order to keep 2671 the internal buffer sane. If you don't pass a value in it, 2672 <tt>strlen()</tt> will be used to determine the length. 2673 2674 \return This method always returns \c *this. 2675 2676 \since BeOS R5 2677*/ 2678 2679 2680/*! 2681 \fn BString& BString::SetByteAt(int32 pos, char to) 2682 \brief Set a byte at position \a pos to character \a to. 2683 2684 \param pos The index of the byte to replace. 2685 \param to The new value that should replace the previous byte. 2686 2687 \return This method always returns \c *this. 2688 2689 \since Haiku R1 2690*/ 2691 2692 2693//! @} 2694 2695 2696/*! 2697 \name Case Manipulation 2698*/ 2699 2700 2701//! @{ 2702 2703 2704/*! 2705 \fn BString& BString::ToLower() 2706 \brief Convert each of the characters in the BString to lowercase. 2707 2708 \return This method always returns \c *this. 2709 2710 \since BeOS R5 2711*/ 2712 2713 2714/*! 2715 \fn BString& BString::ToUpper() 2716 \brief Convert each of the characters in the BString to uppercase. 2717 2718 \return This method always returns \c *this. 2719 2720 \since BeOS R5 2721*/ 2722 2723 2724/*! 2725 \fn BString& BString::Capitalize() 2726 \brief Convert the first character to uppercase, and the rest to lowercase. 2727 2728 \return This method always returns \c *this. 2729 2730 \since BeOS R5 2731*/ 2732 2733 2734/*! 2735 \fn BString& BString::CapitalizeEachWord() 2736 \brief Convert the first character of every word to uppercase, and the rest 2737 to lowercase. 2738 2739 Converts the first character of every "word" (series of alphabetical 2740 characters separated by non alphabetical characters) to uppercase, and 2741 the rest to lowercase. 2742 2743 \return This method always returns \c *this. 2744 2745 \since BeOS R5 2746*/ 2747 2748 2749//! @} 2750 2751 2752/*! 2753 \name Escaping and De-escaping 2754 2755 This class contains some methods to help you with escaping and 2756 de-escaping certain characters. Note that this is the C-style of 2757 escaping, where you place a character before the character that is 2758 to be escaped, and not HTML style escaping, where certain characters 2759 are replaced by something else. 2760*/ 2761 2762 2763//! @{ 2764 2765 2766/*! 2767 \fn BString& BString::CharacterEscape(const char* original, 2768 const char* setOfCharsToEscape, char escapeWith) 2769 \brief Escape selected characters on a given string. 2770 2771 This version sets itself to the string supplied in the \c original 2772 parameter, and then escapes the selected characters with a supplied 2773 character. 2774 2775 \param original The string to be escaped. 2776 \param setOfCharsToEscape The set of characters that need to be escaped. 2777 \param escapeWith The character to escape with. 2778 2779 \return This method always returns \c *this. 2780 2781 \sa CharacterDeescape(char) 2782 \sa CharacterDeescape(const char*, char) 2783 2784 \since BeOS R5 2785*/ 2786 2787 2788/*! 2789 \fn BString& BString::CharacterEscape(const char* setOfCharsToEscape, 2790 char escapeWith) 2791 \brief Escape selected characters of this string. 2792 2793 \param setOfCharsToEscape The set of characters that need to be escaped. 2794 \param escapeWith The character to escape with. 2795 2796 \return This method always returns \c *this. 2797 2798 \sa CharacterDeescape(char) 2799 2800 \since BeOS R5 2801*/ 2802 2803 2804/*! 2805 \fn BString& BString::CharacterDeescape(const char* original, 2806 char escapeChar) 2807 \brief Remove the character to escape with from a given string. 2808 2809 This version sets itself to the string supplied in the \c original 2810 parameter, and then removes the escape characters. 2811 2812 \param original The string to be escaped. 2813 \param escapeChar The character that was used to escape with. 2814 2815 \return This method always returns \c *this. 2816 2817 \sa CharacterEscape(const char*, const char*, char) 2818 2819 \since BeOS R5 2820*/ 2821 2822 2823/*! 2824 \fn BString& BString::CharacterDeescape(char escapeChar) 2825 \brief Remove the character to escape with from this string. 2826 2827 \param escapeChar The character that was used to escape with. 2828 2829 \return This method always returns \c *this. 2830 2831 \sa CharacterEscape(const char*, char) 2832*/ 2833 2834 2835//! @} 2836 2837 2838/*! 2839 \name sprintf() Replacement Methods 2840 2841 These methods may be slower than <tt>sprintf()</tt>, but they are overflow safe. 2842*/ 2843 2844 2845//! @{ 2846 2847 2848/*! 2849 \fn BString& BString::operator<<(const char* string) 2850 \brief Append \a string to the BString. 2851 2852 \param string The \a string to append. 2853 2854 \return This method always returns \c *this. 2855 2856 \since BeOS R5 2857*/ 2858 2859 2860/*! 2861 \fn BString& BString::operator<<(const BString& string) 2862 \brief Append \a string to the BString. 2863 2864 \param string The \a string to append. 2865 2866 \return This method always returns \c *this. 2867*/ 2868 2869 2870/*! 2871 \fn BString& BString::operator<<(char c) 2872 \brief Append \a c to the BString. 2873 2874 \param c The character to append. 2875 2876 \return This method always returns \c *this. 2877 2878 \since BeOS R5 2879*/ 2880 2881 2882/*! 2883 \fn BString& BString::operator<<(bool value) 2884 \brief Convert the \c bool \c value to a string and append it. 2885 2886 In case the \a value is true, the string "true" is appended to the string. 2887 Otherwise, the string "false" is appended. 2888 2889 \param value The boolean \c value ("true" of "false") to append. 2890 2891 \return This method always returns \c *this. 2892 2893 \since BeOS R5 2894*/ 2895 2896 2897/*! 2898 \fn BString& BString::operator<<(int value) 2899 \brief Convert the \c int \a value to a string and append it. 2900 2901 \param value The \c int \a value to append. 2902 2903 \return This method always returns \c *this. 2904 2905 \since BeOS R5 2906*/ 2907 2908 2909/*! 2910 \fn BString& BString::operator<<(unsigned int value) 2911 \brief Convert the <tt>unsigned int</tt> \a value to a string and append it. 2912 2913 \param value The <tt>unsigned int</tt> \a value to append. 2914 2915 \return This method always returns \c *this. 2916 2917 \since BeOS R5 2918*/ 2919 2920 2921/*! 2922 \fn BString& BString::operator<<(unsigned long value) 2923 \brief Convert the <tt>unsigned long</tt> \a value to a string and append it. 2924 2925 \param value The <tt>unsigned long</tt> \a value to append. 2926 2927 \return This method always returns \c *this. 2928 2929 \since BeOS R5 2930*/ 2931 2932 2933/*! 2934 \fn BString& BString::operator<<(long value) 2935 \brief Convert the \c long \a value to a string and append it. 2936 2937 \param value The \c long \a value to append. 2938 2939 \return This method always returns \c *this. 2940 2941 \since BeOS R5 2942*/ 2943 2944 2945/*! 2946 \fn BString& BString::operator<<(unsigned long long value) 2947 \brief Convert the <tt>unsigned long long</tt> \a value to a string and 2948 append it. 2949 2950 \param value The <tt>unsigned long long</tt> \a value to append. 2951 2952 \return This method always returns \c *this. 2953 2954 \since BeOS R5 2955*/ 2956 2957 2958/*! 2959 \fn BString& BString::operator<<(long long value) 2960 \brief Convert the <tt>long long</tt> \a value to a string and append it. 2961 2962 \param value The <tt>long long</tt> \a value to append. 2963 2964 \return This method always returns \c *this. 2965 2966 \since BeOS R5 2967*/ 2968 2969 2970/*! 2971 \fn BString& BString::operator<<(float value) 2972 \brief Convert the \c float \a value to a string and append it. 2973 2974 Using this operator will append using <tt>%.2f</tt> formatting. 2975 2976 \param value The \c float \a value to append. 2977 2978 \return This method always returns \c *this. 2979 2980 \since BeOS R5 2981*/ 2982 2983 2984/*! 2985 \fn BString& BString::operator<<(double value) 2986 \brief Convert the \c double \a value to a string and append it. 2987 2988 Using this operator will append using <tt>%.2f</tt> formatting. 2989 2990 \param value The \c double \a value to append. 2991 2992 \return This method always returns \c *this. 2993 2994 \since BeOS R5 2995*/ 2996 2997 2998//! @} 2999 3000 3001/************* end of BString class, start of general operators ************/ 3002/*! 3003 \addtogroup support_globals 3004*/ 3005 3006 3007//! @{ 3008 3009 3010/*! 3011 \fn bool operator<(const char* a, const BString& b) 3012 \brief Lexicographically compare if \c a is less than the given BString \a b. 3013 3014 From String.h and in libbe.so. 3015 3016 \param a The first string to compare. 3017 \param b The second string to compare. 3018 3019 \return \c true if \a a is less than \a b, \c false otherwise. 3020 3021 \sa BString::operator<(const char*) const 3022 3023 \since BeOS R5 3024*/ 3025 3026 3027/*! 3028 \fn bool operator<=(const char* a, const BString& b) 3029 \brief Lexicographically compare if \c a is less than or equal to a 3030 given BString \a b. 3031 3032 From String.h and in libbe.so. 3033 3034 \param a The first string to compare. 3035 \param b The second string to compare. 3036 3037 \return \c true if \a a is less than or equal to \a b, 3038 \c false otherwise. 3039 3040 \sa BString::operator<=(const char*) const 3041 3042 \since BeOS R5 3043*/ 3044 3045 3046/*! 3047 \fn bool operator==(const char* a, const BString& b) 3048 \brief Lexicographically compare if \c a is equal to a given BString \a b. 3049 3050 From String.h and in libbe.so. 3051 3052 \param a The first string to compare. 3053 \param b The second string to compare. 3054 3055 \sa BString::operator==(const char*) const 3056 3057 \return \c true if \a a is equal to \a b, \c false otherwise. 3058 3059 \since BeOS R5 3060*/ 3061 3062 3063/*! 3064 \fn bool operator>(const char* a, const BString& b) 3065 \brief Lexicographically compare if \c a is greater than a given BString \a b. 3066 3067 From String.h and in libbe.so. 3068 3069 \param a The first string to compare. 3070 \param b The second string to compare. 3071 3072 \sa BString::operator>(const char*) const 3073 3074 \return \c true if \a a is greater than \a b, \c false otherwise. 3075 3076 \since BeOS R5 3077*/ 3078 3079 3080/*! 3081 \fn bool operator>=(const char* a, const BString& b) 3082 \brief Lexicographically compare if \c a is greater than or equal to a 3083 given BString \a b. 3084 3085 From String.h and in libbe.so. 3086 3087 \param a The first string to compare. 3088 \param b The second string to compare. 3089 3090 \return \c true if \a a is greater than or equal to \a b, 3091 \c false otherwise. 3092 3093 \sa BString::operator>=(const char*) const 3094 3095 \since BeOS R5 3096*/ 3097 3098 3099/*! 3100 \fn bool operator!=(const char* a, const BString& b) 3101 \brief Lexicographically compare if \c a is not equal to given BString \a b. 3102 3103 From String.h and in libbe.so. 3104 3105 \param a The first string to compare. 3106 \param b The second string to compare. 3107 3108 \return \c true if \a a is NOT equal to \a b, \c false otherwise. 3109 3110 \sa BString::operator!=(const char*) const 3111 3112 \since BeOS R5 3113*/ 3114 3115 3116/*! 3117 \fn int Compare(const BString& a, const BString& b) 3118 \brief Lexicographically compare two strings. 3119 3120 This function is useful if you need a global compare function to feed to 3121 BList::SortItems(). 3122 3123 \param a The first string to compare. 3124 \param b The second string to compare. 3125 3126 From String.h and in libbe.so. 3127 3128 \return An int representing the strings relationship to each other. 3129 \retval >0 \a a sorts lexicographically after \a b. 3130 \retval =0 \a a is equal to \a b. 3131 \retval <0 \a a sorts lexicographically before \a b. 3132 3133 \sa BString::Compare(const BString&) const 3134 3135 \since BeOS R5 3136*/ 3137 3138 3139/*! 3140 \fn int ICompare(const BString& a, const BString& b) 3141 \brief Lexicographically compare two strings case-insensitively. 3142 3143 This function is useful if you need a global compare function to feed to 3144 BList::SortItems(). 3145 3146 From String.h and in libbe.so. 3147 3148 \param a The first string to compare. 3149 \param b The second string to compare. 3150 3151 \return An int representing the strings relationship to each other. 3152 \retval >0 \a a sorts lexicographically after \a b. 3153 \retval =0 \a a is equal to \a b. 3154 \retval <0 \a a sorts lexicographically before \a b. 3155 3156 \sa BString::Compare(const BString&) const 3157 3158 \since BeOS R5 3159*/ 3160 3161 3162/*! 3163 \fn int Compare(const BString* a, const BString* b) 3164 \brief Lexicographically compare two strings. 3165 3166 This function is useful if you need a global compare function to feed to 3167 BList::SortItems(). 3168 3169 From String.h and in libbe.so. 3170 3171 \param a The first string to compare. 3172 \param b The second string to compare. 3173 3174 \return An int representing the strings relationship to each other. 3175 \retval >0 \a a sorts lexicographically after \a b. 3176 \retval =0 \a a is equal to \a b. 3177 \retval <0 \a a sorts lexicographically before \a b. 3178 3179 \sa BString::Compare(const BString&) const 3180 3181 \since BeOS R5 3182*/ 3183 3184 3185/*! 3186 \fn int ICompare(const BString* a, const BString* b) 3187 \brief Lexicographically compare two strings case-insensitively. 3188 3189 This function is useful if you need a global compare function to feed to 3190 BList::SortItems(). 3191 3192 From String.h and in libbe.so. 3193 3194 \param a The first string to compare. 3195 \param b The second string to compare. 3196 3197 \return An int representing the strings relationship to each other. 3198 \retval >0 \a a sorts lexicographically after \a b. 3199 \retval =0 \a a is equal to \a b. 3200 \retval <0 \a a sorts lexicographically before \a b. 3201 3202 \sa BString::Compare(const BString&) const 3203 3204 \since BeOS R5 3205*/ 3206 3207 3208//! @} 3209