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