String

Engine/source/core/util/str.h

The String class represents a 0-terminated array of characters.

More...

Classes:

class

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.

Return the interned version of the string.

bool

Return true if this string is interned.

String Utility routines

ToString(const char * format, ... )
VToString(const char * format, va_list args)
ToString(bool v)
SpanToString(const char * start, const char * end)
GetTrailingNumber(const char * str, S32 & number)
GetFirstNumber(const char * str, U32 & startPos, U32 & endPos)

Public Types

enum
Mode {
  Case = 0
  NoCase = 1
  Left = 0
  Right = 2
}

Default mode is case sensitive starting from the left.

SizeType 
ValueType 

Public Static Attributes

A predefined empty string.

Indicates 'not found' when using find() functions.

Private Attributes

Public Functions

Copy from raw data.

Return the string as a native type.

Erases all characters in a string.

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.

bool
endsWith(const char * text)

Return true if the string ends with the given text.

bool
equal(const String & str, U32 mode)

Compare two strings for equality.

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)

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].

bool

Is this an empty string [""]?

bool

Is this not an empty string [""]?

bool

Return true if both strings refer to the same shared data.

bool

Is this string's reference count greater than 1?

Returns the length of the string in bytes.

Returns the length of the string in characters.

bool
bool
bool
bool
bool
bool

Replace all occurrences of StringData 's1' with StringData 's2'.

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.

bool
startsWith(const char * text)

Return true if the string starts with the given text.

trim()

Remove leading and trailing whitespace.

Public Static Functions

compare(const char * str1, const char * str2)
compare(const UTF16 * str1, const UTF16 * str2)
bool
isEmpty(const char * )

Private Functions

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.

return:

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()

Public Static Functions

compare(const char * str1, const char * str2)

compare(const UTF16 * str1, const UTF16 * str2)

isEmpty(const char * )

Public Friends

Private Functions

String(StringData * str)

operator const bool()

Private Static Functions

copy(StringChar * dst, const StringChar * src, U32 size)