This class represents a UTF-8 string. It includes a variety of common string operations as methods (in fact as way too many methods); additional less common operations are available in the StringUtils.h header.
SString uses copy-on-write for its internal data buffer, so it is efficient to copy (and usually to convert back and forth with SValue, which shares the same copy-on-write mechanism).
|
Appending |
Adding to the end of the string.
|
SString & | Append (char, int32_t count) |
SString & | Append (const char *, int32_t length) |
SString & | Append (const SString &, int32_t length) |
SString & | Append (const char *) |
SString & | Append (const SString &) |
SString & | operator+= (char) |
SString & | operator+= (const char *) |
SString & | operator+= (const SString &) |
UTF-8 Utility Functions |
Conveniences for working with the string UTF-8 data as distinct Unicode characters.
|
SString & | AppendChar (wchar32_t unicode) |
| Appends the unicode character (unicode scalar value) to the string.
|
wchar32_t | CharAt (int32_t index) const |
| Returns the unicode value for the character that starts at index.
|
int32_t | CharLength (int32_t index) const |
| Returns the length of the utf-8 character with its first byte at the given index.
|
int32_t | CountChars () const |
| Returns number of utf-8 characters in string.
|
int32_t | FirstForChar (int32_t index) const |
| Returns the index of the first byte of the utf-8 character that includes the byte at the index given.
|
int32_t | NextChar (int32_t index) const |
| Returns the index of the first byte of the utf-8 character after the one that starts at the index given.
|
int32_t | NextCharFor (int32_t index) const |
| Returns the index of the first byte of the utf-8 character after the one that includes the byte at the index given.
|
Fast Low-level Manipulation |
Direct access to the string buffer for efficient implementation of more custom string algorithms.
|
void | BeginBuffering () |
| Start buffering mode on the string data.
|
void | EndBuffering () |
| Stop BeginBuffering() mode.
|
char * | LockBuffer (int32_t maxLength) |
| Retrieve raw string buffer for editing.
|
void | Pool () |
| Make sure string is in the SSharedBuffer pool.
|
const SSharedBuffer * | SharedBuffer () const |
| Get the SSharedBuffer that the SString is using.
|
SString & | UnlockBuffer (int32_t length=-1) |
| Finish using SString as C-string, adjusting length.
|
Access |
Retrieving the string and information about it.
|
char | ByteAt (int32_t index) const |
| Checked (safely bounded) character access.
|
bool | IsNumber (int32_t base=10) const |
| Checks the string for a valid representation of a number in the base.
|
int32_t | Length () const |
| Retrieve string length (does not require a strlen()).
|
void | MakeEmpty () |
| Remove all data from string.
|
| operator const char * () const |
| Automagic cast to a C string.
|
char | operator[] (size_t index) const |
| Unchecked character access.
|
const char * | String () const |
| Return null-terminated C string.
|
static const SString & | EmptyString () |
| Retrieve empty SString constant.
|
Case Conversions |
Lowercase to uppercase, or uppercase to lowercase.
|
SString & | Capitalize () |
| Converts first character to upper-case, rest to lower-case.
|
SString & | CapitalizeEachWord () |
| Converts first character in each white-space-separated word to upper-case, rest to lower-case.
|
SString & | ToLower (int32_t first, int32_t length) |
| Convert the supplied range.
|
SString & | ToLower () |
| Convert the whole string.
|
SString & | ToUpper (int32_t first, int32_t length) |
| Convert the supplied range.
|
SString & | ToUpper () |
| Convert the whole string.
|
Escaping and Descaping |
Adding and removing escape sequences to protect special characters.
|
SString & | CharacterDeescape (char escapeChar) |
SString & | CharacterDeescape (const char *original, char escapeChar) |
SString & | CharacterEscape (const char *setOfCharsToEscape, char escapeWith) |
SString & | CharacterEscape (const char *original, const char *setOfCharsToEscape, char escapeWith) |
Removing |
Deleting characters from the string.
|
SString & | Compact (const char *setOfCharsToCompact, char *replacementChar) |
SString & | Compact (const char *setOfCharsToCompact) |
void | MoveInto (char *into, int32_t from, int32_t length) |
| Caller must guarantee that into is large enough.
|
SString & | MoveInto (SString &into, int32_t from, int32_t length) |
SString & | Remove (int32_t from, int32_t length) |
SString & | RemoveAll (const char *) |
SString & | RemoveAll (const SString &) |
SString & | RemoveFirst (const char *) |
SString & | RemoveFirst (const SString &) |
SString & | RemoveLast (const char *) |
SString & | RemoveLast (const SString &) |
SString & | RemoveSet (const char *setOfCharsToRemove) |
SString & | Truncate (int32_t newLength) |
strcmp()-Style Comparison |
Comparison methods with strcmp()-like results.
|
int | Compare (const char *, int32_t n) const |
int | Compare (const SString &, int32_t n) const |
int | Compare (const char *) const |
int | Compare (const SString &) const |
int | ICompare (const char *, int32_t n) const |
int | ICompare (const SString &, int32_t n) const |
int | ICompare (const char *) const |
int | ICompare (const SString &) const |
Substring Copying |
Copying a portion of the string to somewhere else.
|
void | CopyInto (char *into, int32_t fromOffset, int32_t length) const |
| Caller guarantees that into is large enough.
|
SString & | CopyInto (SString &into, int32_t fromOffset, int32_t length) const |
| Returns into ref as it's result.
|
Searching |
Finding characters inside the string.
|
int32_t | FindFirst (char, int32_t fromOffset) const |
int32_t | FindFirst (char) const |
int32_t | FindFirst (const char *, int32_t fromOffset) const |
int32_t | FindFirst (const SString &, int32_t fromOffset) const |
int32_t | FindFirst (const char *) const |
int32_t | FindFirst (const SString &) const |
int32_t | FindLast (char, int32_t fromOffset) const |
int32_t | FindLast (char) const |
int32_t | FindLast (const char *, int32_t beforeOffset) const |
int32_t | FindLast (const SString &, int32_t beforeOffset) const |
int32_t | FindLast (const char *) const |
int32_t | FindLast (const SString &) const |
int32_t | FindSetFirst (const char *setOfChars, int32_t fromOffset) |
int32_t | FindSetFirst (const char *setOfChars) |
int32_t | FindSetLast (const char *setOfChars, int32_t beforeOffset) |
int32_t | FindSetLast (const char *setOfChars) |
int32_t | IFindFirst (const char *, int32_t fromOffset) const |
int32_t | IFindFirst (const SString &, int32_t fromOffset) const |
int32_t | IFindFirst (const char *) const |
int32_t | IFindFirst (const SString &) const |
int32_t | IFindLast (const char *, int32_t beforeOffset) const |
int32_t | IFindLast (const SString &, int32_t beforeOffset) const |
int32_t | IFindLast (const char *) const |
int32_t | IFindLast (const SString &) const |
Inserting |
Adding to the middle of the string.
|
SString & | Insert (char, int32_t count, int32_t pos) |
SString & | Insert (const SString &, int32_t fromOffset, int32_t length, int32_t pos) |
SString & | Insert (const SString &, int32_t length, int32_t pos) |
SString & | Insert (const SString &, int32_t pos) |
SString & | Insert (const char *, int32_t fromOffset, int32_t length, int32_t pos) |
SString & | Insert (const char *, int32_t length, int32_t pos) |
SString & | Insert (const char *, int32_t pos) |
Replacing |
Changing characters inside the string.
|
SString & | IReplace (const char *replaceThis, const char *withThis, int32_t maxReplaceCount, int32_t fromOffset=0) |
SString & | IReplace (char replaceThis, char withThis, int32_t maxReplaceCount, int32_t fromOffset=0) |
SString & | IReplaceAll (const char *replaceThis, const char *withThis, int32_t fromOffset=0) |
SString & | IReplaceAll (char replaceThis, char withThis, int32_t fromOffset=0) |
SString & | IReplaceFirst (const char *replaceThis, const char *withThis) |
SString & | IReplaceFirst (char replaceThis, char withThis) |
SString & | IReplaceLast (const char *replaceThis, const char *withThis) |
SString & | IReplaceLast (char replaceThis, char withThis) |
SString & | Replace (const char *replaceThis, const char *withThis, int32_t maxReplaceCount, int32_t fromOffset=0) |
SString & | Replace (char replaceThis, char withThis, int32_t maxReplaceCount, int32_t fromOffset=0) |
SString & | ReplaceAll (const char *replaceThis, const char *withThis, int32_t fromOffset=0) |
SString & | ReplaceAll (char replaceThis, char withThis, int32_t fromOffset=0) |
SString & | ReplaceFirst (const char *replaceThis, const char *withThis) |
SString & | ReplaceFirst (char replaceThis, char withThis) |
SString & | ReplaceLast (const char *replaceThis, const char *withThis) |
SString & | ReplaceLast (char replaceThis, char withThis) |
SString & | ReplaceSet (const char *setOfChars, const char *with) |
SString & | ReplaceSet (const char *setOfChars, char with) |
Handling Whitespace |
Commmon whitespace-related operations.
|
bool | IsOnlyWhitespace () const |
| Anything but whitespace in the string?
|
SString & | Mush () |
| Get rid of redundant whitespace.
|
SString & | StripWhitespace () |
| Removes all whitespace.
|
SString & | Trim () |
| Remove all leading and trailing whitespace.
|
Comparison |
Standard C++ comparion operators.
|
bool | operator!= (const char *) const |
bool | operator!= (const SString &) const |
bool | operator< (const char *) const |
bool | operator< (const SString &) const |
bool | operator<= (const char *) const |
bool | operator<= (const SString &) const |
bool | operator== (const char *) const |
bool | operator== (const SString &) const |
bool | operator> (const char *) const |
bool | operator> (const SString &) const |
bool | operator>= (const char *) const |
bool | operator>= (const SString &) const |
SPrintf Replacements |
Slower than sprintf but type and overflow safe.
|
SString & | operator<< (float) |
| Float output hardcodes %.2f style formatting.
|
SString & | operator<< (int64_t) |
| Float output hardcodes %.2f style formatting.
|
SString & | operator<< (uint64_t) |
| Float output hardcodes %.2f style formatting.
|
SString & | operator<< (long) |
| Float output hardcodes %.2f style formatting.
|
SString & | operator<< (unsigned long) |
| Float output hardcodes %.2f style formatting.
|
SString & | operator<< (unsigned int) |
| Float output hardcodes %.2f style formatting.
|
SString & | operator<< (int) |
| Float output hardcodes %.2f style formatting.
|
SString & | operator<< (char) |
| Float output hardcodes %.2f style formatting.
|
SString & | operator<< (const SString &) |
| Float output hardcodes %.2f style formatting.
|
SString & | operator<< (const char *) |
| Float output hardcodes %.2f style formatting.
|
Assignment |
Replacing the string with something entirely different.
|
SString & | operator= (const char *) |
SString & | operator= (const SString &) |
SString & | Printf (const char *fmt,...) |
| Set string using a printf-style format.
|
SString & | SetTo (char, int32_t count) |
SString & | SetTo (const SString &, int32_t length) |
SString & | SetTo (const SString &from) |
SString & | SetTo (const char *, int32_t length) |
SString & | SetTo (const char *) |
void | Swap (SString &with) |
Path Handling |
Manipulating string as a filename path.
|
status_t | PathAppend (const char *leaf, bool normalize=false) |
| Append a path to the current path string.
|
status_t | PathAppend (const SString &leaf, bool normalize=false) |
| Append a path to the current path string.
|
status_t | PathGetParent (SString *parentPath) const |
| Return the parent portion of the path.
|
status_t | PathGetRoot (SString *root) const |
| Retrieve the root part of the path and place it in root.
|
const char * | PathLeaf (void) const |
| Append a path to the current path string.
|
status_t | PathNormalize () |
| Return the end of the string representing the leaf node in the path.
|
status_t | PathRemoveRoot (SString *root) |
| Remove root part of path and place it in root.
|
status_t | PathSetTo (const char *dir, const char *leaf=NULL, bool normalize=false) |
| Set string to a path.
|
status_t | PathSetTo (const SString &dir, const SString &leaf=B_EMPTY_STRING, bool normalize=false) |
| Set string to a path.
|
static const char * | PathDelimiter () |
| The character that is used to separate path segments.
|
Prepending |
Adding to the front of the string.
|
SString & | Prepend (char, int32_t count) |
SString & | Prepend (const SString &, int32_t) |
SString & | Prepend (const char *, int32_t) |
SString & | Prepend (const SString &) |
SString & | Prepend (const char *) |
Bookkeeping |
Creation, destruction.
|
| SString (const SSharedBuffer *buf) |
| SString (const char *, int32_t maxLength) |
| SString (const SString &) |
| SString (int32_t) |
| SString (const char *) |
| SString () |
| ~SString () |
static status_t | SelfQC () |
| Run internal QC tests. Only available on debug builds.
|
Protected Attributes |
const char * | _privateData |