String
The String class represents a 0-terminated array of characters.
Classes:
An internal support class for ToString().
Interning
Interning maps identical strings to unique instances so that equality amounts to simple pointer comparisons.
Note that using interned strings within global destructors is not safe as table destruction runs within this phase as well. Uses o interned strings in global destructors is thus dependent on object file ordering.
Also, interned strings are not reference-counted. Once interned, a string will persist until shutdown. This is to avoid costly concurrent reference counting that would otherwise be necessary.
bool
Return true if this string is interned.
String Utility routines
SpanToString(const char * start, const char * end)
GetTrailingNumber(const char * str, S32 & number)
GetFirstNumber(const char * str, U32 & startPos, U32 & endPos)
Public Types
Mode { Case = 0 NoCase = 1 Left = 0 Right = 2 }
Default mode is case sensitive starting from the left.
SizeType
ValueType
Public Static Attributes
Private Attributes
Public Functions
String()
String(const StringChar * str)
String(const StringChar * str, SizeType size)
Copy from raw data.
~String()
Replace all escape sequences in with their respective character codes.
Replace all characters that need to be escaped for the string to be a valid string literal with their respective escape sequences.
find(StringChar c, SizeType pos, U32 mode)
Get the case-insensitive hash of the string [only calculates the hash as necessary].
Get the case-sensitive hash of the string [only calculates the hash as necessary].
String &
insert(SizeType pos, const StringChar * str)
String &
insert(SizeType pos, const StringChar c)
bool
isEmpty()
Is this an empty string [""]?
bool
Is this not an empty string [""]?
bool
isShared()
Is this string's reference count greater than 1?
bool
operator!=(const String & str)
bool
String &
operator+=(const String & )
String &
bool
operator<=(const String & str)
String &
operator=(const StringChar * )
bool
operator==(const String & str)
bool
bool
operator>=(const String & str)
String &
Replace all occurrences of StringData 's1' with StringData 's2'.
String &
replace(StringChar c1, StringChar c2)
Replace all occurrences of character 'c1' with 'c2'.
bool
startsWith(const char * text)
Return true if the string starts with the given text.
Public Static Functions
Private Functions
String(StringData * str)
Private Static Functions
copy(StringChar * dst, const StringChar * src, U32 size)
Detailed Description
The String class represents a 0-terminated array of characters.
Interning
Interning maps identical strings to unique instances so that equality amounts to simple pointer comparisons.
Note that using interned strings within global destructors is not safe as table destruction runs within this phase as well. Uses o interned strings in global destructors is thus dependent on object file ordering.
Also, interned strings are not reference-counted. Once interned, a string will persist until shutdown. This is to avoid costly concurrent reference counting that would otherwise be necessary.
intern()
Return the interned version of the string.
note:Interning is case-sensitive.
isInterned()
Return true if this string is interned.
String Utility routines
ToString(const char * format, ... )
VToString(const char * format, va_list args)
ToString(bool v)
ToString(U32 v)
ToString(S32 v)
ToString(F32 v)
ToString(F64 v)
SpanToString(const char * start, const char * end)
ToLower(const String & string)
ToUpper(const String & string)
GetTrailingNumber(const char * str, S32 & number)
GetFirstNumber(const char * str, U32 & startPos, U32 & endPos)
Public Types
Mode
Enumerator
- Case = 0
Case sensitive.
- NoCase = 1
Case insensitive.
- Left = 0
Start at left end of string.
- Right = 2
Start at right end of string.
Default mode is case sensitive starting from the left.
typedef U32 SizeType
typedef StringChar ValueType
Public Static Attributes
const String EmptyString
A predefined empty string.
const SizeType NPos
Indicates 'not found' when using find() functions.
Private Attributes
StringData * _string
Public Functions
String()
String(const String & str)
String(const StringChar * str)
String(const StringChar * str, SizeType size)
Copy from raw data.
String(const UTF16 * str)
~String()
c_str()
Return the string as a native type.
clear()
Erases all characters in a string.
collapseEscapes()
Replace all escape sequences in with their respective character codes.
compare(const String & str, SizeType len, U32 mode)
compare(const StringChar * str, SizeType len, U32 mode)
Compare this string with another.
Parameters:
str | The string to compare against. |
len | If len is non-zero, then at most len characters are compared. |
mode | Comparison mode. |
Difference between the first two characters that don't match.
endsWith(const char * text)
Return true if the string ends with the given text.
equal(const String & str, U32 mode)
Compare two strings for equality.
It will use the string hashes to determine inequality. Parameters:
str | The string to compare against. |
mode | Comparison mode - case sensitive or not. |
erase(SizeType pos, SizeType len)
expandEscapes()
Replace all characters that need to be escaped for the string to be a valid string literal with their respective escape sequences.
find(const String & str, SizeType pos, U32 mode)
find(const StringChar * str, SizeType pos, U32 mode)
find(StringChar c, SizeType pos, U32 mode)
getHashCaseInsensitive()
Get the case-insensitive hash of the string [only calculates the hash as necessary].
getHashCaseSensitive()
Get the case-sensitive hash of the string [only calculates the hash as necessary].
insert(SizeType pos, const String & str)
insert(SizeType pos, const StringChar * str)
insert(SizeType pos, const StringChar * str, SizeType len)
Todo: review for error checking
insert(SizeType pos, const StringChar c)
isEmpty()
Is this an empty string [""]?
isNotEmpty()
Is this not an empty string [""]?
isSame(const String & str)
Return true if both strings refer to the same shared data.
isShared()
Is this string's reference count greater than 1?
length()
Returns the length of the string in bytes.
numChars()
Returns the length of the string in characters.
operator const StringChar*()
operator!=(const String & str)
operator!=(StringChar c)
operator+=(const String & )
operator+=(const StringChar * )
operator+=(StringChar )
operator<(const String & str)
operator<=(const String & str)
operator=(const String & )
operator=(const StringChar * )
operator=(StringChar )
operator==(const String & str)
operator==(StringChar c)
operator>(const String & str)
operator>=(const String & str)
operator[](S32 i)
operator[](U32 i)
replace(const String & s1, const String & s2)
Replace all occurrences of StringData 's1' with StringData 's2'.
replace(SizeType pos, SizeType len, const String & str)
replace(SizeType pos, SizeType len, const StringChar * str)
Todo: review for error checking
replace(StringChar c1, StringChar c2)
Replace all occurrences of character 'c1' with 'c2'.
size()
Returns the length of the string in bytes including the NULL terminator.
split(const char * delimiter, Vector< String > & outElements)
Split the string into its components separated by the given delimiter.
startsWith(const char * text)
Return true if the string starts with the given text.
substr(SizeType pos, SizeType len)
trim()
Remove leading and trailing whitespace.
utf16()
utf8()