2 * Copyright 2007-2014 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
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
13 * headers/os/support/String.h rev 43319
14 * src/kits/support/String.cpp rev 42682
22 \brief Defines the BString class and global operators and functions for
28 \class BString String.h
31 \brief String class supporting common string operations.
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.
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.
51 \fn BString::BString()
52 \brief Creates an empty BString.
59 \fn BString::BString(const char* string)
60 \brief Creates and initializes a BString from \a string.
62 \param string The \a string to copy from.
69 \fn BString::BString(const BString& string)
70 \brief Creates and initializes a BString as a copy of another \a string.
72 \param string The BString object to copy from.
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.
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.
87 \warning In BeOS R5 passing in a negative \a maxLength argument will copy
90 \param string The \a string data to initialize the BString to.
91 \param maxLength Maximum number of characters (bytes) to copy.
98 \fn BString::~BString()
99 \brief Free all resources associated with the object.
101 The destructor also frees the internal buffer associated with the string.
116 \fn const char* BString::String() const
117 \brief Return a pointer to the object string, \c NUL terminated.
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.
123 If you want to manipulate the internal string of the object directly,
124 have a look at LockBuffer().
126 \return A pointer to the object string.
133 \fn int32 BString::Length() const
134 \brief Get the length of the string in bytes.
136 \return An integer with the length of the string, measured in bytes.
145 \fn int32 BString::CountChars() const
146 \brief Returns the length of the object measured in characters.
148 BString is somewhat aware of UTF-8 characters, so this method will count
149 the actual number of characters in the string.
151 \return An integer which is the number of characters in the string.
160 \fn int32 BString::CountBytes(int32 fromCharOffset, int32 charCount) const
161 \brief Count the number of bytes starting from a specified character
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
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.
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
174 \return An integer with the number of bytes.
181 \fn bool BString::IsEmpty() const
182 \brief Check whether the string is empty.
184 \return Returns \c true if the string is empty.
191 \fn uint32 BString::HashValue() const
192 \brief Return a hash value for the current string
194 \sa HashValue(const char*)
201 \fn static uint32 BString::HashValue(const char* string)
202 \brief Return the hash value of a specified \c string
204 This allows you to use the BString::HashValue() method on any arbitrary
207 \param string The string that you want to have hashed.
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.
233 \fn BString& BString::operator=(const BString& string)
234 \brief Re-initialize the object to a copy of the data of a BString.
236 \param string The \a string to copy.
238 \return The function always returns \c *this.
241 \sa SetTo(const BString&, int32)
248 \fn BString& BString::operator=(const char* str)
249 \brief Re-initialize the BString to a copy of the data of a string.
251 \param str The string data to re-initialize the BString to.
253 \return This method always returns \c *this.
255 \sa SetTo(const char*, int32)
262 \fn BString& BString::operator=(char c)
263 \brief Re-initialize the BString to a character.
265 \param c The \c char to re-initialize the BString to.
267 \return This method always returns \c *this.
274 \fn BString& BString::SetTo(const char* str)
275 \brief Re-initialize the BString to a copy of the data of a string.
277 This method calls operator=(const char*).
279 \param str The string data to re-initialize the BString to.
281 \return This method always returns \c *this.
283 \sa SetTo(const char*, int32)
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.
293 \param str The string data to re-initialize the BString to.
294 \param maxLength Maximum number of characters (bytes) to copy.
296 \return This method always returns \c *this.
298 \sa operator=(const char*)
305 \fn BString& BString::SetTo(const BString& from)
306 \brief Re-initialize the BString to a copy of the data of a BString.
308 \param from The string data to re-initialize the BString to.
310 \return The function always returns \c *this.
312 \sa SetTo(const BString&, int32)
320 \fn BString& BString::SetTo(const BString& string, int32 maxLength)
321 \brief Re-initialize the string to a copy of the given BString object.
323 \param string The string data to re-initialize the BString to.
324 \param maxLength Maximum number of characters (bytes) to copy.
326 \return The function always returns \c *this.
328 \sa operator=(const BString&)
329 \sa Adopt(BString&, int32)
336 \fn BString& BString::Adopt(BString& from)
337 \brief Adopt the data of the given BString object.
339 This method adopts the data from a BString removing the data from \a from
340 and putting it into the BString.
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.
346 \param from The string data to adopt.
348 \return The function always returns \c *this.
350 \sa operator=(const BString&)
357 \fn BString& BString::Adopt(BString& from, int32 maxLength)
358 \brief Adopt the data of the given BString object up to \a maxLength
361 This method adopts the data from a BString removing the data from \a from
362 and putting it into the BString.
364 \param from The string object to adopt.
365 \param maxLength Maximum number of characters (bytes) to adopt.
367 \return The function always returns \c *this.
369 \sa SetTo(const BString&, int32)
376 \fn BString& BString::SetTo(char c, int32 count)
377 \brief Re-initialize the object to a string composed of a character you
380 This method lets you specify the length of a string and what character
381 you want the string to contain repeatedly.
383 \param c The character you want to initialize the BString.
384 \param count The length of the string.
386 \return The function always returns \c *this.
388 \sa operator=(char c)
395 \fn BString& BString::SetToChars(const char* string, int32 charCount)
396 \brief UTF-8 aware version of SetTo(const char*, int32)
398 \param string The \a string to copy.
399 \param charCount The number of UTF-8 characters to copy.
401 \see SetTo(const char*, int32)
408 \fn BString& BString::SetToChars(const BString& string, int32 charCount)
409 \brief UTF-8 aware version of SetTo(BString&, int32)
411 \param string The \a string to copy.
412 \param charCount The number of UTF-8 characters to copy.
414 \see SetTo(BString&, int32)
416 \return This method always returns \c *this.
423 \fn BString& BString::AdoptChars(BString& from, int32 charCount)
424 \brief UTF-8 aware version of Adopt(BString&, int32)
426 \param from The string data to start adopting from.
427 \param charCount Number of UTF-8 characters to adopt.
429 \return This method always returns \c *this.
436 \fn BString& BString::SetToFormat(const char* format, ...)
437 \brief Sets the string to a formatted string ala <tt>sprintf()</tt>.
439 \param format The \a format string to use.
440 \param ... The rest of the parameters that are filled into \a format.
442 \return This method always returns \c *this.
452 \name Substring Copying
460 \fn BString& BString::CopyInto(BString& into, int32 fromOffset,
462 \brief Copy the object's data (or part of it) into another BString.
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.
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.
472 \return This method always returns a pointer to the string passed as the
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.
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.
487 It's up to you to make sure your buffer is large enough.
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.
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.
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.
506 \return This method always returns a pointer to the string passed as the
509 \see CopyInto(BString&, int32, int32) const
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.
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
524 \param charCount The number of UTF-8 characters to copy.
526 \see CopyInto(char*, int32, int32) const
528 \return \c false if \a into was \c NULL, \c true otherwise.
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.
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.
559 \fn BString& BString::operator+=(const BString& string)
560 \brief Append the given \a string to the end of the BString
562 \param string The string to append.
564 \return This method always returns \c *this.
566 \sa Append(const BString&, int32)
573 \fn BString& BString::operator+=(const char* str)
574 \brief Append the given string to the end of the BString.
576 \param str A pointer to the NULL-terminated string to append.
578 \return This method always returns \c *this.
580 \sa Append(const char*, int32)
587 \fn BString& BString::operator+=(char c)
588 \brief Append the given character to the end of the BString.
590 \param c The character to append.
592 \return This method always returns \c *this.
594 \sa Append(char, int32)
599 \fn BString& BString::operator+=(const BString& string)
600 \brief Append the given \a string to the end of the BString.
602 \param string The string to append.
604 \return This method always returns \c *this.
606 \sa Append(const BString&, int32)
611 \fn BString& BString::Append(const BString& string)
612 \brief Append the given \a string to the end of the BString.
614 \param string The string to append.
616 \return This method always returns \c *this.
618 \sa Append(const BString&, int32)
625 \fn BString& BString::Append(const char* str)
626 \brief Append the string data to the end of the BString.
628 This method calls operator+=(const char *str).
630 \sa Append(const char*, int32)
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.
640 \param string The BString to append.
641 \param length The maximum number of bytes to append.
643 \return This method always returns \c *this.
645 \sa operator+=(const BString&)
652 \fn BString& BString::Append(const char* str, int32 length)
653 \brief Append a part of the given string to end of the BString.
655 \param str A pointer to the string to append.
656 \param length The maximum number of bytes to append.
658 \return This method always returns \c *this.
660 \sa operator+=(const char*)
667 \fn BString& BString::Append(char c, int32 count)
668 \brief Append the given character repeatedly to the end of the BString.
670 \param c The character to append.
671 \param count The number of times this character should be appended.
673 \return This method always returns \c *this.
675 \sa operator+=(char c)
682 \fn BString& BString::AppendChars(const BString& string, int32 charCount)
683 \brief UTF-8 aware version of Append(const BString&, int32).
685 \param string The \a string to append.
686 \param charCount The maximum number of UTF-8 characters to append.
688 \return This method always returns \c *this.
690 \see Append(const BString&, int32)
697 \fn BString& BString::AppendChars(const char* string, int32 charCount)
698 \brief UTF-8 aware version of Append(const char*, int32).
700 \param string The \a string to append.
701 \param charCount The maximum number of UTF-8 characters to append.
703 \return This method always returns \c *this.
705 \see Append(const char*, int32)
723 \fn BString& BString::Prepend(const char* str)
724 \brief Prepend the given string to the beginning of the BString.
726 \param str The \a string to prepend.
728 \return This method always returns \c *this.
730 \sa Prepend(const char*, int32)
737 \fn BString& BString::Prepend(const BString& string)
738 \brief Prepend the given BString to the beginning of the BString.
740 \param string The \a string to prepend.
742 \return This method always returns \c *this.
744 \sa Prepend(const BString&, int32)
751 \fn BString& BString::Prepend(const char* str, int32 length)
752 \brief Prepend the given string to the beginning of the BString.
754 \param str The \a string to prepend.
755 \param length The maximum number of bytes to prepend.
757 \return This method always returns \c *this.
759 \sa Prepend(const char*)
766 \fn BString& BString::Prepend(const BString& string, int32 length)
767 \brief Prepend the given BString to the beginning of the BString.
769 \param string The \a string to prepend.
770 \param length The maximum number of bytes to prepend.
772 \return This method always returns \c *this.
774 \sa Prepend(const BString&)
781 \fn BString& BString::Prepend(char c, int32 count)
782 \brief Prepend the given character \a count times to the beginning of the
785 \param c The character to prepend.
786 \param count The number of times this character should be prepended.
788 \return This method always returns \c *this.
795 \fn BString& BString::PrependChars(const char* string, int32 charCount)
796 \brief UTF-8 aware version of Prepend(const char*, int32).
798 \param string The \a string to prepend.
799 \param charCount The maximum number of UTF-8 characters to prepend.
801 \return This method always returns \c *this.
803 \see Prepend(const char*, int32)
810 \fn BString& BString::PrependChars(const BString& string, int32 charCount)
811 \brief UTF-8 aware version of Prepend(const BString&, int32).
813 \param string The \a string to prepend.
814 \param charCount The maximum number of UTF-8 characters to prepend.
816 \return This method always returns \c *this.
818 \see Prepend(const BString&, int32)
836 \fn BString& BString::Insert(const char* string, int32 position)
837 \brief Inserts the given string at the given position into the BString
840 \param string The \a string to insert.
841 \param position The offset in bytes where to insert the \a string into
844 \return This method always returns \c *this.
846 \sa Insert(const char*, int32, int32)
847 \sa Insert(const char*, int32, int32, int32)
854 \fn BString& BString::Insert(const char* string, int32 length,
856 \brief Inserts the given string at the given position into the BString
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
864 \return This method always returns \c *this.
866 \sa Insert(const char*, int32)
867 \sa Insert(const char*, int32, int32, int32)
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
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
885 \return This method always returns \c *this.
887 \sa Insert(const char*, int32)
888 \sa Insert(const char*, int32, int32)
895 \fn BString& BString::Insert(const BString& string, int32 position)
896 \brief Inserts the given BString at the given position into the BString
899 \param string The \a string to insert.
900 \param position The offset in bytes into the data of the BString where to
903 \return This method always returns \c *this.
905 \sa Insert(const BString&, int32, int32)
906 \sa Insert(const BString&, int32, int32, int32)
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
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
922 \return This method always returns \c *this.
924 \sa Insert(const BString&, int32)
925 \sa Insert(const BString&, int32, int32, int32)
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
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
943 \return This method always returns \c *this.
945 \sa Insert(const BString&, int32)
946 \sa Insert(const BString&, int32, int32)
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.
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
962 \return This method always returns \c *this.
969 \fn BString& BString::InsertChars(const char* string, int32 charPosition)
970 \brief UTF-8 aware version of Insert(const char*, int32).
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.
976 \return This method always returns \c *this.
978 \see Insert(const char*, int32)
985 \fn BString& BString::InsertChars(const char* string, int32 charCount,
987 \brief UTF-8 aware version of Insert(const char*, int32, int32).
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.
994 \return This method always returns \c *this.
996 \see Insert(const char*, int32, int32)
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).
1007 \param string The \a string to insert.
1008 \param fromCharOffset The offset in UTF-8 characters of the string to be
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.
1014 \return This method always returns \c *this.
1016 \see Insert(const char*, int32, int32, int32)
1023 \fn BString& BString::InsertChars(const BString& string, int32 charPosition)
1024 \brief UTF-8 aware version of Insert(const BString&, int32).
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.
1030 \return This method always returns \c *this.
1032 \see Insert(const BString&, int32)
1039 \fn BString& BString::InsertChars(const BString& string, int32 charCount,
1041 \brief UTF-8 aware version of Insert(const BString&, int32, int32).
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.
1048 \return This method always returns \c *this.
1050 \see Insert(const BString&, int32, int32)
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).
1061 \param string The \a string to insert.
1062 \param fromCharOffset The offset in UTF-8 characters of the string to be
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.
1068 \return This method always returns \c *this.
1070 \see Insert(const BString&, int32, int32, int32)
1088 \fn BString& BString::Trim()
1089 \brief Removes spaces from the beginning and end of the string.
1091 The definition of a space is set by the <tt>isspace()</tt> function.
1093 \return This method always returns \c *this.
1101 \fn BString& BString::Truncate(int32 newLength, bool lazy)
1102 \brief Truncate the string to the new length.
1104 \param newLength The new length of the string in bytes.
1105 \param lazy If true, the memory-optimization is postponed until later.
1107 \return This method always returns \c *this.
1114 \fn BString& BString::TruncateChars(int32 newCharCount, bool lazy)
1115 \brief UTF-8 aware version of Truncate(int32, bool).
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.
1120 \see Truncate(int32, bool)
1127 \fn BString& BString::Remove(int32 from, int32 length)
1128 \brief Remove some bytes, starting at the given offset
1130 \param from The offset in bytes to start removing.
1131 \param length The number of bytes to remove.
1133 \return This function always returns \c *this.
1140 \fn BString& BString::RemoveChars(int32 fromCharOffset, int32 charCount)
1141 \brief UTF-8 aware version of Remove(int32, int32).
1143 \param fromCharOffset The offset in UTF-8 characters to start removing.
1144 \param charCount The number of UTF-8 characters to remove.
1146 \return This function always returns \c *this.
1148 \see Remove(int32, int32)
1155 \fn BString& BString::RemoveFirst(const BString& string)
1156 \brief Remove the first occurrence of the given BString.
1158 \param string The BString to remove.
1160 \return This function always returns \c *this.
1167 \fn BString& BString::RemoveLast(const BString& string)
1168 \brief Remove the last occurrence of the given BString.
1170 \param string The BString to remove.
1172 \return This function always returns \c *this.
1179 \fn BString& BString::RemoveAll(const BString& string)
1180 \brief Remove all occurrences of the given BString.
1182 \param string The BString to remove.
1184 \return This function always returns \c *this.
1191 \fn BString& BString::RemoveFirst(const char* string)
1192 \brief Remove the first occurrence of the given string.
1194 \param string A pointer to the string to remove.
1196 \return This function always returns \c *this.
1203 \fn BString& BString::RemoveLast(const char* string)
1204 \brief Remove the last occurrence of the given string.
1206 \param string A pointer to the string to remove.
1208 \return This function always returns \c *this.
1215 \fn BString& BString::RemoveAll(const char* str)
1216 \brief Remove all occurrences of the given string.
1218 \param str A pointer to the string to remove.
1220 \return This function always returns \c *this.
1227 \fn BString& BString::RemoveSet(const char* setOfCharsToRemove)
1228 \brief Remove all the characters specified.
1230 \param setOfCharsToRemove The set of characters to remove.
1232 \return This function always returns \c *this.
1239 \fn BString& BString::RemoveCharsSet(const char* setOfCharsToRemove)
1240 \brief UTF-8 aware version of RemoveSet(const char*).
1242 \param setOfCharsToRemove The set of characters to remove.
1244 \return This function always returns \c *this.
1246 \see RemoveSet(const char*)
1253 \fn BString& BString::MoveInto(BString& into, int32 from, int32 length)
1254 \brief Move the BString data (or part of it) into another BString.
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.
1260 \return This method always returns \c into.
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.
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.
1279 \fn BString& BString::MoveCharsInto(BString& into, int32 fromCharOffset,
1281 \brief UTF-8 aware version of MoveInto(BString&, int32, int32)
1283 \param into The BString where to move the string into.
1284 \param fromCharOffset The offset (zero-based) in UTF-8 characters where to
1286 \param charCount The number of UTF-8 characters to move.
1288 \see MoveInto(BString&, int32, int32)
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).
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
1303 \param charCount The number of UTF-8 characters to move.
1305 \returns \c false if \a into was \c NULL, \c true otherwise.
1307 \see MoveInto(char*, int32*, int32, int32)
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.
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.
1336 \fn bool BString::operator<(const BString& string) const
1337 \brief Lexicographically compare if this BString is less than the given
1340 \param string The \a string to compare against.
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.
1351 \param string The \a string to compare against.
1358 \fn bool BString::operator==(const BString& string) const
1359 \brief Lexicographically compare if this BString is equal to the given
1362 \param string The \a string to compare against.
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.
1373 \param string The string to compare against.
1380 \fn bool BString::operator>(const BString& string) const
1381 \brief Lexicographically compare if this BString is greater than the given
1384 \param string The string to compare against.
1391 \fn bool BString::operator!=(const BString& string) const
1392 \brief Lexicographically compare if this BString is not equal to the given
1395 \param string The string to compare against.
1402 \fn bool BString::operator<(const char* string) const
1403 \brief Lexicographically compare if this BString is less than the given
1406 \param string The string to compare against.
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.
1417 \param string The \a string to compare against.
1424 \fn bool BString::operator==(const char* string) const
1425 \brief Lexicographically compare if this BString is equal to the given
1428 \param string The \a string to compare against.
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.
1439 \param string The \a string to compare against.
1446 \fn bool BString::operator>(const char* string) const
1447 \brief Lexicographically compare if this string is more than a given string.
1449 \param string The \a string to compare against.
1456 \fn bool BString::operator!=(const char* string) const
1457 \brief Lexicographically compare if this string is not equal to a given
1460 \param string The \a string to compare against.
1467 \fn BString::operator const char*() const
1468 \brief Return an empty string.
1470 \return An empty string.
1477 \fn int BString::Compare(const BString& string) const
1478 \brief Lexicographically compare this BString to another \a string.
1480 \param string The \a string to compare against.
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.
1492 \fn int BString::Compare(const char* string) const
1493 \brief Lexicographically compare this BString to another \a string.
1495 \param string The \a string to compare against.
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.
1502 \sa Compare(const BString&) const
1509 \fn int BString::Compare(const BString& string, int32 length) const
1510 \brief Lexicographically compare \a length characters of this BString to
1513 \param string The \a string to compare against.
1514 \param length The number of bytes to compare.
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.
1526 \fn int BString::Compare(const char* string, int32 length) const
1527 \brief Lexicographically compare \a length characters of this BString to
1530 \param string The \a string to compare against.
1531 \param length The number of bytes to compare.
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.
1538 \sa Compare(const BString&, int32) const
1545 \fn int BString::CompareChars(const BString& string, int32 charCount) const
1546 \brief UTF-8 aware version of Compare(const BString&, int32).
1548 \param string The \a string to compare against.
1549 \param charCount The number of UTF-8 characters to compare.
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.
1556 \see Compare(const BString&, int32)
1563 \fn int BString::CompareChars(const char* string, int32 charCount) const
1564 \brief UTF-8 aware version of Compare(const char*, int32).
1566 \param string The \a string to compare against.
1567 \param charCount The number of UTF-8 characters to compare.
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.
1574 \see Compare(const char*, int32)
1581 \fn int BString::ICompare(const BString& string) const
1582 \brief Lexicographically compare this BString to another \a string
1585 \param string The \a string to compare against.
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.
1592 \sa Compare(const BString&) const
1599 \fn int BString::ICompare(const char* string) const
1600 \brief Lexicographically compare this BString to another \a string
1603 \param string The \a string to compare against.
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.
1610 \sa Compare(const BString&) const
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.
1621 \param string The \a string to compare against.
1622 \param length The number of characters to compare.
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.
1629 \sa Compare(const BString&, int32) const
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.
1640 \param string The \a string to compare against.
1641 \param length The number of characters to compare
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.
1648 \sa Compare(const BString&, int32) const
1666 \fn int32 BString::FindFirst(const BString& string) const
1667 \brief Find the first occurrence of the given \a string.
1669 \param string The \a string to search for.
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.
1674 \sa IFindFirst(const BString&) const
1681 \fn int32 BString::FindFirst(const char* string) const
1682 \brief Find the first occurrence of the given \a string.
1684 \param string The \a string to search for.
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.
1690 \sa IFindFirst(const char*) const
1691 \sa StartsWith(const char*) const
1692 \sa StartsWith(const char*, int32) const
1699 \fn int32 BString::FindFirst(const BString& string, int32 fromOffset) const
1700 \brief Find the first occurrence of the given \a string starting from
1703 \param string The \a string to search for.
1704 \param fromOffset The offset in bytes to start the search.
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.
1710 \sa IFindFirst(const BString&, int32) const
1711 \sa StartsWith(const char*, int32) const
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
1722 \param string The \a string to search for.
1723 \param fromOffset The offset in bytes to start the search.
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.
1729 \sa IFindFirst(const char*, int32) const
1736 \fn int32 BString::FindFirst(char c) const
1737 \brief Find the first occurrence of the given character.
1739 \param c The character to search for.
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.
1749 \fn int32 BString::FindFirst(char c, int32 fromOffset) const
1750 \brief Find the first occurrence of the given character, starting from the
1753 \param c The character to search for.
1754 \param fromOffset The offset where to start the search.
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.
1764 \fn int32 BString::FindFirstChars(const BString& string,
1765 int32 fromCharOffset) const
1766 \brief UTF-8 aware version of FindFirst(const BString&, int32).
1768 \param string The \a string to search for.
1769 \param fromCharOffset The offset in UTF-8 characters to start the search.
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.
1775 \see FindFirst(const BString&, int32)
1782 \fn int32 BString::FindFirstChars(const char* string,
1783 int32 fromCharOffset) const
1784 \brief UTF-8 aware version of FindFirst(const char*, int32).
1786 \param string The \a string to search for.
1787 \param fromCharOffset The offset in UTF-8 characters to start the search.
1789 \see FindChars(const char*, int32)
1796 \fn int32 BString::FindLast(const BString& string) const
1797 \brief Find the last occurrence of the given \a string.
1799 \param string The \a string to search for.
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.
1804 \sa IFindLast(const BString&) const
1805 \sa EndsWith(const BString&) const
1812 \fn int32 BString::FindLast(const char* string) const
1813 \brief Find the last occurrence of the given string.
1815 \param string The string to search for.
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.
1821 \sa IFindLast(const char*) const
1822 \sa EndsWith(const char*) const
1823 \sa EndsWith(const char*, int32) const
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.
1834 \param string The BString to search for.
1835 \param beforeOffset The offset in bytes to start the search.
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.
1840 \sa IFindLast(const BString&, int32) const
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.
1851 \param string The string to search for.
1852 \param beforeOffset The offset in bytes to start the search.
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.
1858 \sa IFindLast(const char*, int32) const
1865 \fn int32 BString::FindLast(char c) const
1866 \brief Find the last occurrence of the given character.
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.
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.
1881 \param c The character to search for.
1882 \param beforeOffset The offset in bytes to start the search.
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.
1892 \fn int32 BString::FindLastChars(const BString& string,
1893 int32 beforeCharOffset) const
1894 \brief UTF-8 aware version of FindLast(const BString&, int32).
1896 \param string The BString to search for.
1897 \param beforeCharOffset The offset in UTF-8 characters to start the search.
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
1903 \see FindLast(const BString&, int32)
1910 \fn int32 BString::FindLastChars(const char* string,
1911 int32 beforeCharOffset) const
1912 \brief UTF-8 aware version of FindLast(const char*, int32).
1914 \param string The string to search for.
1915 \param beforeCharOffset The offset in UTF-8 characters to start the search.
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.
1921 \see FindLast(const char*, int32)
1928 \fn int32 BString::IFindFirst(const BString& string) const
1929 \brief Find the first occurrence of the given \a string case-insensitively.
1931 \copydetails FindFirst(const BString&) const
1936 \fn int32 BString::IFindFirst(const char* string) const
1937 \brief Find the first occurrence of the given \a string case-insensitively.
1939 \param string The \a string to search for.
1941 \copydetails FindFirst(const char*) const
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.
1950 \copydetails FindFirst(const BString&, int32) const
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.
1959 \copydetails FindFirst(const char*, int32) const
1964 \fn int32 BString::IFindLast(const BString& string) const
1965 \brief Find the last occurrence of the given BString case-insensitively.
1967 \copydetails FindLast(const BString&) const
1972 \fn int32 BString::IFindLast(const char* string) const
1973 \brief Find the last occurrence of the given string case-insensitively.
1975 \copydetails FindLast(const char*) const
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.
1984 \copydetails FindLast(const BString&, int32) const
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.
1993 \copydetails FindLast(const char*, int32) const
1998 \fn bool BString::StartsWith(const BString& string) const
1999 \brief Returns whether or not the BString starts with \a string.
2001 \param string The \a string to search for.
2003 \return \c true if the BString started with \a string, \c false otherwise.
2010 \fn bool BString::StartsWith(const char* string) const
2011 \brief Returns whether or not the BString starts with \a string.
2013 \param string The \a string to search for.
2015 \return \c true if the BString started with \a string, \c false otherwise.
2022 \fn bool BString::StartsWith(const char* string, int32 length) const
2023 \brief Returns whether or not the BString starts with \a length characters
2026 \param string The \a string to search for.
2027 \param length The number of characters (bytes) of \a string to search for.
2029 \return \c true if the BString started with \a length characters of
2030 \a string, \c false otherwise.
2037 \fn bool BString::IStartsWith(const BString& string) const
2038 \brief Returns whether or not the BString starts with \a string
2041 \param string The \a string to search for.
2043 \return \c true if the BString started with \a string case-insensitively,
2051 \fn bool BString::IStartsWith(const char* string) const
2052 \brief Returns whether or not the BString starts with \a string
2055 \param string The \a string to search for.
2057 \return \c true if the BString started with \a string case-insensitively,
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.
2069 \param string The \a string to search for.
2070 \param length The number of characters (bytes) of \a string to search for.
2072 \return \c true if the BString started with \a length characters of
2073 \a string case-insensitively, \c false otherwise.
2080 \fn bool BString::EndsWith(const BString& string) const
2081 \brief Returns whether or not the BString ends with \a string.
2083 \param string The \a string to search for.
2085 \return \c true if the BString ended with \a string, \c false otherwise.
2092 \fn bool BString::EndsWith(const char* string) const
2093 \brief Returns whether or not the BString ends with \a string.
2095 \param string The \a string to search for.
2097 \return \c true if the BString ended with \a string, \c false otherwise.
2104 \fn bool BString::EndsWith(const char* string, int32 length) const
2105 \brief Returns whether or not the BString ends with \a length characters
2108 \param string The \a string to search for.
2109 \param length The number of characters (bytes) of \a string to search for.
2111 \return \c true if the BString ended with \a length characters of
2112 \a string, \c false otherwise.
2119 \fn bool BString::IEndsWith(const BString& string) const
2120 \brief Returns whether or not the BString ends with \a string
2123 \param string The \a string to search for.
2125 \return \c true if the BString ended with \a string case-insensitively,
2133 \fn bool BString::IEndsWith(const char* string) const
2134 \brief Returns whether or not the BString ends with \a string
2137 \param string The \a string to search for.
2139 \return \c true if the BString ended with \a string case-insensitively,
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.
2151 \param string The \a string to search for.
2152 \param length The number of characters (bytes) of \a string to search for.
2154 \return \c true if the BString ended with \a length characters of
2155 \a string case-insensitively, \c false otherwise.
2173 \fn BString& BString::ReplaceFirst(char replaceThis, char withThis)
2174 \brief Replace the first occurrence of a character with another character.
2176 \param replaceThis The character to replace.
2177 \param withThis The character to put in its place.
2179 \return This method always returns \c *this.
2181 \sa IReplaceFirst(char, char)
2188 \fn BString& BString::ReplaceLast(char replaceThis, char withThis)
2189 \brief Replace the last occurrence of a character with another character.
2191 \param replaceThis The character to replace.
2192 \param withThis The character to put in its place
2194 \return This method always returns \c *this.
2196 \sa IReplaceLast(char, char)
2203 \fn BString& BString::ReplaceAll(char replaceThis, char withThis,
2205 \brief Replace all occurrences of a character with another character.
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.
2211 \return This method always returns \c *this.
2213 \sa IReplaceAll(char, char, int32)
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
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
2229 \param fromOffset The offset in bytes to start looking for the character
2231 \return This method always returns \c *this.
2233 \sa IReplace(char, char, int32, int32)
2240 \fn BString& BString::ReplaceFirst(const char* replaceThis,
2241 const char* withThis)
2242 \brief Replace the first occurrence of a string with another string.
2244 \param replaceThis The string to replace.
2245 \param withThis The string to put in its place
2247 \return This method always returns \c *this.
2249 \sa IReplaceFirst(const char*, const char*)
2256 \fn BString& BString::ReplaceLast(const char* replaceThis,
2257 const char* withThis)
2258 \brief Replace the last occurrence of a string with another string.
2260 \param replaceThis The string to replace.
2261 \param withThis The string to put in its place
2263 \return This method always returns \c *this.
2265 \sa IReplaceLast(const char*, const char*)
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.
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.
2280 \return This method always returns \c *this.
2282 \sa IReplaceAll(const char*, const char*, int32)
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.
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
2297 \param fromOffset The offset in bytes to start looking for the string.
2299 \return This method always returns \c *this.
2301 \sa IReplace(const char*, const char*, int32, int32)
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).
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
2317 \return This method always returns \c *this.
2319 \see ReplaceAll(const char*, const char*, int32)
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).
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
2335 \param fromCharOffset The offset in UTF-8 characters to start looking for
2338 \return This method always returns \c *this.
2340 \see ReplaceAll(const char*, const char*, int32, int32)
2347 \fn BString& BString::IReplaceFirst(char replaceThis, char withThis)
2348 \brief Replace the first occurrence of a character with another
2349 character case-insensitively.
2351 \param replaceThis The string to replace.
2352 \param withThis The string to put in its place
2354 \sa ReplaceFirst(char, char)
2361 \fn BString& BString::IReplaceLast(char replaceThis, char withThis)
2362 \brief Replace the last occurrence of a character with another
2363 character case-insensitively.
2365 \param replaceThis The string to replace.
2366 \param withThis The string to put in its place
2368 \sa ReplaceLast(char, char)
2375 \fn BString& BString::IReplaceAll(char replaceThis, char withThis,
2377 \brief Replace all occurrences of a character with another character
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
2384 \sa ReplaceAll(char, char, int32)
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.
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
2400 \param fromOffset The offset where to start looking for the string
2402 \sa Replace(char, char, int32, int32)
2409 \fn BString& BString::IReplaceFirst(const char* replaceThis,
2410 const char* withThis)
2411 \brief Replace the first occurrence of a string with another string
2414 \param replaceThis The string to replace.
2415 \param withThis The string to put in its place.
2417 \sa ReplaceFirst(const char*, const char*)
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.
2428 \param replaceThis The string to replace.
2429 \param withThis The string to put in its place.
2431 \sa ReplaceLast(const char*, const char*)
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
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.
2447 \sa ReplaceAll(const char*, const char*, int32)
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
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
2463 \param fromOffset The offset where to start looking for the string
2465 \sa Replace(const char*, const char*, int32, int32)
2472 \fn BString& BString::ReplaceSet(const char* setOfBytes, char with)
2473 \brief Replaces characters that are in a certain set with a chosen
2476 \param setOfBytes The set of characters that need to be replaced.
2477 \param with The character to replace the occurrences with.
2479 \return This method always returns \c *this.
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.
2489 \param setOfBytes The set of chars that need to be replaced.
2490 \param with The string to replace the occurrences with.
2492 \return This method always returns \c *this.
2499 \fn BString& BString::ReplaceCharsSet(const char* setOfChars,
2501 \brief UTF-8 aware version of ReplaceSet(const char*, const char*)
2503 \param setOfChars The set of UTF-8 characters that need to be replaced.
2504 \param with The string to replace the occurrences with.
2506 \return This method always returns \c *this.
2524 \fn char& BString::operator[](int32 index)
2525 \brief Return a reference to the data at the given offset.
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.
2531 \param index The index (zero-based) of the byte to get.
2533 \return Returns a reference to the specified byte.
2535 \sa ByteAt(int32 index) for a safer version.
2542 \fn char BString::operator[](int32 index) const
2543 \brief Returns the character in the string at the given offset.
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
2549 \param index The index (zero-based) of the byte to get.
2551 \return Returns a reference to the specified byte.
2558 \fn char BString::ByteAt(int32 index) const
2559 \brief Returns the character in the string at the given offset.
2561 This function can be used to read a single byte.
2563 \param index The index (zero-based) of the byte to get.
2565 \return A reference to the specified byte, if out of bounds return 0.
2572 \fn const char* BString::CharAt(int32 charIndex, int32* bytes) const
2573 \brief UTF-8 aware version of ByteAt(int32).
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.
2578 \return A reference to the specified UTF-8 character, if out of bounds
2588 \fn bool BString::CharAt(int32 charIndex, char* buffer,
2590 \brief UTF-8 aware version of ByteAt(int32) with a \a buffer parameter.
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
2595 \param bytes An int32 pointer to hold the UTF-8 character.
2597 \see ByteAt(int32, char*, int32*)
2607 \name Low-Level Manipulation
2615 \fn char* BString::LockBuffer(int32 maxLength)
2616 \brief Locks the buffer and return the internal string for manipulation.
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.
2622 Make sure you call UnlockBuffer() when you're done with the manipulation.
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.
2628 \return A pointer to the buffer to manipulate.
2637 \fn BString& BString::UnlockBuffer(int32 length)
2638 \brief Unlocks the buffer after you are done with low-level manipulation.
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.
2644 \return This method always returns \c *this.
2654 \name Case Manipulation
2662 \fn BString& BString::ToLower()
2663 \brief Convert each of the characters in the BString to lowercase.
2665 \return This method always returns \c *this.
2672 \fn BString& BString::ToUpper()
2673 \brief Convert each of the characters in the BString to uppercase.
2675 \return This method always returns \c *this.
2682 \fn BString& BString::Capitalize()
2683 \brief Convert the first character to uppercase, and the rest to lowercase.
2685 \return This method always returns \c *this.
2692 \fn BString& BString::CapitalizeEachWord()
2693 \brief Convert the first character of every word to uppercase, and the rest
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.
2700 \return This method always returns \c *this.
2710 \name Escaping and De-escaping
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.
2724 \fn BString& BString::CharacterEscape(const char* original,
2725 const char* setOfCharsToEscape, char escapeWith)
2726 \brief Escape selected characters on a given string.
2728 This version sets itself to the string supplied in the \c original
2729 parameter, and then escapes the selected characters with a supplied
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.
2736 \return This method always returns \c *this.
2738 \sa CharacterDeescape(char)
2739 \sa CharacterDeescape(const char*, char)
2746 \fn BString& BString::CharacterEscape(const char* setOfCharsToEscape,
2748 \brief Escape selected characters of this string.
2750 \param setOfCharsToEscape The set of characters that need to be escaped.
2751 \param escapeWith The character to escape with.
2753 \return This method always returns \c *this.
2755 \sa CharacterDeescape(char)
2762 \fn BString& BString::CharacterDeescape(const char* original,
2764 \brief Remove the character to escape with from a given string.
2766 This version sets itself to the string supplied in the \c original
2767 parameter, and then removes the escape characters.
2769 \param original The string to be escaped.
2770 \param escapeChar The character that was used to escape with.
2772 \return This method always returns \c *this.
2774 \sa CharacterEscape(const char*, const char*, char)
2781 \fn BString& BString::CharacterDeescape(char escapeChar)
2782 \brief Remove the character to escape with from this string.
2784 \param escapeChar The character that was used to escape with.
2786 \return This method always returns \c *this.
2788 \sa CharacterEscape(const char*, char)
2796 \name sprintf() Replacement Methods
2798 These methods may be slower than <tt>sprintf()</tt>, but they are overflow safe.
2806 \fn BString& BString::operator<<(const char* string)
2807 \brief Append \a string to the BString.
2809 \param string The \a string to append.
2811 \return This method always returns \c *this.
2818 \fn BString& BString::operator<<(const BString& string)
2819 \brief Append \a string to the BString.
2821 \param string The \a string to append.
2823 \return This method always returns \c *this.
2828 \fn BString& BString::operator<<(char c)
2829 \brief Append \a c to the BString.
2831 \param c The character to append.
2833 \return This method always returns \c *this.
2840 \fn BString& BString::operator<<(bool value)
2841 \brief Convert the \c bool \c value to a string and append it.
2843 In case the \a value is true, the string "true" is appended to the string.
2844 Otherwise, the string "false" is appended.
2846 \param value The boolean \c value ("true" of "false") to append.
2848 \return This method always returns \c *this.
2855 \fn BString& BString::operator<<(int value)
2856 \brief Convert the \c int \a value to a string and append it.
2858 \param value The \c int \a value to append.
2860 \return This method always returns \c *this.
2867 \fn BString& BString::operator<<(unsigned int value)
2868 \brief Convert the <tt>unsigned int</tt> \a value to a string and append it.
2870 \param value The <tt>unsigned int</tt> \a value to append.
2872 \return This method always returns \c *this.
2879 \fn BString& BString::operator<<(unsigned long value)
2880 \brief Convert the <tt>unsigned long</tt> \a value to a string and append it.
2882 \param value The <tt>unsigned long</tt> \a value to append.
2884 \return This method always returns \c *this.
2891 \fn BString& BString::operator<<(long value)
2892 \brief Convert the \c long \a value to a string and append it.
2894 \param value The \c long \a value to append.
2896 \return This method always returns \c *this.
2903 \fn BString& BString::operator<<(unsigned long long value)
2904 \brief Convert the <tt>unsigned long long</tt> \a value to a string and
2907 \param value The <tt>unsigned long long</tt> \a value to append.
2909 \return This method always returns \c *this.
2916 \fn BString& BString::operator<<(long long value)
2917 \brief Convert the <tt>long long</tt> \a value to a string and append it.
2919 \param value The <tt>long long</tt> \a value to append.
2921 \return This method always returns \c *this.
2928 \fn BString& BString::operator<<(float value)
2929 \brief Convert the \c float \a value to a string and append it.
2931 Using this operator will append using <tt>%.2f</tt> formatting.
2933 \param value The \c float \a value to append.
2935 \return This method always returns \c *this.
2942 \fn BString& BString::operator<<(double value)
2943 \brief Convert the \c double \a value to a string and append it.
2945 Using this operator will append using <tt>%.2f</tt> formatting.
2947 \param value The \c double \a value to append.
2949 \return This method always returns \c *this.
2958 /************* end of BString class, start of general operators ************/
2960 \addtogroup support_globals
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.
2971 From String.h and in libbe.so.
2973 \param a The first string to compare.
2974 \param b The second string to compare.
2976 \return \c true if \a a is less than \a b, \c false otherwise.
2978 \sa BString::operator<(const char*) const
2985 \fn bool operator<=(const char* a, const BString& b)
2986 \brief Lexicographically compare if \c a is less than or equal to a
2989 From String.h and in libbe.so.
2991 \param a The first string to compare.
2992 \param b The second string to compare.
2994 \return \c true if \a a is less than or equal to \a b,
2997 \sa BString::operator<=(const char*) const
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.
3007 From String.h and in libbe.so.
3009 \param a The first string to compare.
3010 \param b The second string to compare.
3012 \sa BString::operator==(const char*) const
3014 \return \c true if \a a is equal to \a b, \c false otherwise.
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.
3024 From String.h and in libbe.so.
3026 \param a The first string to compare.
3027 \param b The second string to compare.
3029 \sa BString::operator>(const char*) const
3031 \return \c true if \a a is greater than \a b, \c false otherwise.
3038 \fn bool operator>=(const char* a, const BString& b)
3039 \brief Lexicographically compare if \c a is greater than or equal to a
3042 From String.h and in libbe.so.
3044 \param a The first string to compare.
3045 \param b The second string to compare.
3047 \return \c true if \a a is greater than or equal to \a b,
3050 \sa BString::operator>=(const char*) const
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.
3060 From String.h and in libbe.so.
3062 \param a The first string to compare.
3063 \param b The second string to compare.
3065 \return \c true if \a a is NOT equal to \a b, \c false otherwise.
3067 \sa BString::operator!=(const char*) const
3074 \fn int Compare(const BString& a, const BString& b)
3075 \brief Lexicographically compare two strings.
3077 This function is useful if you need a global compare function to feed to
3080 \param a The first string to compare.
3081 \param b The second string to compare.
3083 From String.h and in libbe.so.
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.
3090 \sa BString::Compare(const BString&) const
3097 \fn int ICompare(const BString& a, const BString& b)
3098 \brief Lexicographically compare two strings case-insensitively.
3100 This function is useful if you need a global compare function to feed to
3103 From String.h and in libbe.so.
3105 \param a The first string to compare.
3106 \param b The second string to compare.
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.
3113 \sa BString::Compare(const BString&) const
3120 \fn int Compare(const BString* a, const BString* b)
3121 \brief Lexicographically compare two strings.
3123 This function is useful if you need a global compare function to feed to
3126 From String.h and in libbe.so.
3128 \param a The first string to compare.
3129 \param b The second string to compare.
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.
3136 \sa BString::Compare(const BString&) const
3143 \fn int ICompare(const BString* a, const BString* b)
3144 \brief Lexicographically compare two strings case-insensitively.
3146 This function is useful if you need a global compare function to feed to
3149 From String.h and in libbe.so.
3151 \param a The first string to compare.
3152 \param b The second string to compare.
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.
3159 \sa BString::Compare(const BString&) const