Click
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Related Symbols | List of all members
String Class Reference

A string of characters. More...

Public Types

typedef const char * const_iterator
 
typedef const_iterator iterator
 
typedef int(String::* unspecified_bool_type) () const
 
typedef int64_t intmax_t
 
typedef uint64_t uintmax_t
 
typedef intmax_t int_large_t
 
typedef uintmax_t uint_large_t
 

Public Member Functions

 String ()
 Construct an empty String (with length 0).
 
 String (const String &x)
 Construct a copy of the String x.
 
 String (const char *cstr)
 Construct a String containing the C string cstr.
 
 String (const char *s, int len)
 Construct a String containing the first len characters of string s.
 
 String (const unsigned char *s, int len)
 
 String (const char *first, const char *last)
 Construct a String containing the characters from first to last.
 
 String (const unsigned char *first, const unsigned char *last)
 
 String (bool x)
 Construct a String equal to "true" or "false" depending on the value of x.
 
 String (char c)
 Construct a String containing the single character c.
 
 String (unsigned char c)
 
 String (int x)
 Construct a base-10 string representation of x.
 
 String (unsigned x)
 
 String (long x)
 
 String (unsigned long x)
 
 String (int64_t x)
 
 String (uint64_t x)
 
 String (double x)
 Construct a base-10 string representation of x.
 
 ~String ()
 Destroy a String, freeing memory if necessary.
 
const char * data () const
 Return a pointer to the string's data.
 
int length () const
 Return the string's length.
 
const char * c_str () const
 Null-terminate the string.
 
 operator unspecified_bool_type () const
 Test if the string is nonempty.
 
bool empty () const
 Test if the string is empty.
 
bool operator! () const
 Test if the string is empty.
 
const_iterator begin () const
 Return an iterator for the first character in the string.
 
const_iterator end () const
 Return an iterator for the end of the string.
 
char operator[] (int i) const
 Return the i th character in the string.
 
char at (int i) const
 Return the i th character in the string.
 
char front () const
 Return the first character in the string.
 
char back () const
 Return the last character in the string.
 
uint32_t hashcode () const
 Returns a 32-bit hash function of this string's characters.
 
String substring (const char *begin, const char *end) const
 Return a substring of the current string starting at first and ending before last.
 
String substring (int pos, int len) const
 Return a substring of this string, consisting of the len characters starting at index pos.
 
String substring (int pos) const
 Return the suffix of the current string starting at index pos.
 
String trim () const
 Return a substring with spaces trimmed from both sides.
 
String trim_space () const
 Return a substring with spaces trimmed from the end.
 
String trim_space_left () const
 Return a substring with spaces trimmed from the start.
 
String remove (char c) const
 Return a string with from replaced by to.
 
String replace (char from, char to) const
 Return a string with from replaced by to.
 
String replace (String from, String to) const
 Return a string with from replaced by to.
 
bool equals (const String &x) const
 Test if this string equals x.
 
bool equals (const char *s, int len) const
 Test if this string is equal to the data in s.
 
int compare (const String &x) const
 Compare this string with string x.
 
int compare (const char *s, int len) const
 Compare this string with the data in s.
 
bool starts_with (const String &x) const
 Test if this string begins with prefix x.
 
bool starts_with (const char *s, int len) const
 Return true iff this string begins with the data in s.
 
bool glob_match (const String &pattern) const
 Test whether this string matches the glob pattern.
 
Vector< String > split (char c) const
 Split a string using an input character as a delimiter. The outcome of the split is a vector of tokens.
 
int find_left (char c, int start=0) const
 Search for a character in a string.
 
int find_left (const String &x, int start=0) const
 Search for a substring in a string.
 
int find_right (char c, int start=0x7FFFFFFF) const
 Search for a character in a string.
 
const char * search (String pattern)
 
String lower () const
 Return a lowercased version of this string.
 
String upper () const
 Return an uppercased version of this string.
 
String printable () const
 Return a "printable" version of this string.
 
String quoted_hex () const
 Return a hex-quoted version of the string.
 
String encode_json () const
 Return this string's contents encoded for JSON.
 
String & operator= (const String &x)
 Assign this string to x.
 
String & operator= (const char *cstr)
 Assign this string to the C string cstr.
 
void swap (String &x)
 Swap the values of this string and x.
 
void append (const String &x)
 Append x to this string.
 
void append (const char *cstr)
 Append the null-terminated C string cstr to this string.
 
void append (const char *s, int len)
 Append the first len characters of s to this string.
 
void append (const char *first, const char *last)
 Appends the data from first to last to this string.
 
void append (char c)
 Append the character c to this string.
 
void append_fill (int c, int len)
 Append len copies of character c to this string.
 
char * append_uninitialized (int len)
 Append len unknown characters to this string.
 
char * append_garbage (int len)
 
String & operator+= (const String &x)
 Append x to this string.
 
String & operator+= (const char *cstr)
 Append the null-terminated C string cstr to this string.
 
String & operator+= (char c)
 Append the character c to this string.
 
bool is_shared () const
 Test if the String's data is shared or immutable.
 
bool is_stable () const
 Test if the String's data is immutable.
 
String unique () const
 Return an unshared version of this String.
 
String unshared () const
 Return an unshared version of this String.
 
String compact () const
 Return a compact version of this String.
 
char * mutable_data ()
 Ensure the string's data is unshared and return a mutable pointer to it.
 
char * mutable_c_str ()
 Null-terminate the string and return a mutable pointer to its data.
 
bool out_of_memory () const
 Test if this is an out-of-memory string.
 

Static Public Member Functions

static const String & make_empty ()
 Return a const reference to an empty String.
 
static String make_uninitialized (int len)
 Return a String containing len unknown characters.
 
static String make_garbage (int len)
 
static String make_stable (const char *cstr)
 Return a String that directly references the C string cstr.
 
static String make_stable (const char *s, int len)
 Return a String that directly references the first len characters of s.
 
static String make_stable (const char *first, const char *last)
 Return a String that directly references the character data in [first, last).
 
static String make_numeric (intmax_t x, int base=10, bool uppercase=true)
 Create and return a string representation of x.
 
static String make_numeric (uintmax_t x, int base=10, bool uppercase=true)
 
static uint32_t hashcode (const char *begin, const char *end)
 Return a 32-bit hash function of the characters in [first, last).
 
static uint32_t hashcode (const unsigned char *begin, const unsigned char *end)
 
static int compare (const String &a, const String &b)
 Compare two strings.
 
static const String & make_out_of_memory ()
 Return a const reference to a canonical out-of-memory String.
 
static const char * out_of_memory_data ()
 Return the data pointer used for out-of-memory strings.
 
static int out_of_memory_length ()
 Return the length of canonical out-of-memory strings.
 
static const char * empty_data ()
 Return the data pointer used for canonical empty strings.
 
static const char * skip_utf8_char (const char *first, const char *last)
 Return a pointer to the next character in UTF-8 encoding.
 
static const unsigned char * skip_utf8_char (const unsigned char *first, const unsigned char *last)
 Return a pointer to the next character in UTF-8 encoding.
 

Static Public Attributes

static const char bool_data [11] = "false\0true"
 

Related Symbols

(Note that these are not member symbols.)

bool operator== (const String &a, const String &b)
 Compares two strings for equality.
 
bool operator== (const char *a, const String &b)
 
bool operator== (const String &a, const char *b)
 
bool operator!= (const String &a, const String &b)
 Compare two Strings for inequality.
 
bool operator!= (const char *a, const String &b)
 
bool operator!= (const String &a, const char *b)
 
bool operator< (const String &a, const String &b)
 Compare two Strings.
 
bool operator<= (const String &a, const String &b)
 Compare two Strings.
 
bool operator> (const String &a, const String &b)
 Compare two Strings.
 
bool operator>= (const String &a, const String &b)
 Compare two Strings.
 
String operator+ (String a, const String &b)
 Concatenate the operands and return the result.
 
String operator+ (String a, const char *b)
 
String operator+ (const char *a, const String &b)
 
String operator+ (String a, char b)
 Concatenate the operands and return the result.
 

Detailed Description

A string of characters.

The String class represents a string of characters. Strings may be constructed from C strings, characters, numbers, and so forth. They may also be added together. The underlying character arrays are dynamically allocated; String operations allocate and free memory as needed. A String and its substrings generally share memory. Accessing a character by index takes O(1) time; so does creating a substring.

Out-of-memory strings

When there is not enough memory to create a particular string, a special "out-of-memory" string is returned instead. Out-of-memory strings are contagious: the result of any concatenation operation involving an out-of-memory string is another out-of-memory string. Thus, the final result of a series of String operations will be an out-of-memory string, even if the out-of-memory condition occurs in the middle.

The canonical out-of-memory string is 14 bytes long, and equals the UTF-8 encoding of "\U0001F4A3ENOMEM\U0001F4A3" (that is, U+1F4A3 BOMB + "ENOMEM" + U+1F4A3 BOMB). This sequence is unlikely to show up in normal text, compares high relative to most other textual strings, and is valid UTF-8.

All canonical out-of-memory strings are equal and share the same data(), which is different from the data() of any other string. See String::out_of_memory_data(). The String::make_out_of_memory() function returns a canonical out-of-memory string.

Other strings may also be out-of-memory strings. For example, String::make_stable(String::out_of_memory_data()) == String::make_out_of_memory(), and some (but not all) substrings of out-of-memory strings are also out-of-memory strings.

Constructor & Destructor Documentation

◆ String() [1/17]

String::String ( )
inline

Construct an empty String (with length 0).

◆ String() [2/17]

String::String ( const String &  x)
inline

Construct a copy of the String x.

◆ String() [3/17]

String::String ( const char *  cstr)
inline

Construct a String containing the C string cstr.

Parameters
cstra null-terminated C string
Returns
A String containing the characters of cstr, up to but not including the terminating null character.

◆ String() [4/17]

String::String ( const char *  s,
int  len 
)
inline

Construct a String containing the first len characters of string s.

Parameters
sa string
lennumber of characters to take from s. If len < 0, then takes strlen(s) characters.
Returns
A String containing len characters of s.

◆ String() [5/17]

String::String ( const unsigned char *  s,
int  len 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ String() [6/17]

String::String ( const char *  first,
const char *  last 
)
inline

Construct a String containing the characters from first to last.

Parameters
firstfirst character in string (begin iterator)
lastpointer one past last character in string (end iterator)
Returns
A String containing the characters from first to last.

Constructs an empty string if first >= last.

◆ String() [7/17]

String::String ( const unsigned char *  first,
const unsigned char *  last 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ String() [8/17]

String::String ( bool  x)
inlineexplicit

Construct a String equal to "true" or "false" depending on the value of x.

◆ String() [9/17]

String::String ( char  c)
inlineexplicit

Construct a String containing the single character c.

◆ String() [10/17]

String::String ( unsigned char  c)
inlineexplicit

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ String() [11/17]

String::String ( int  x)
explicit

Construct a base-10 string representation of x.

never

◆ String() [12/17]

String::String ( unsigned  x)
explicit

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ String() [13/17]

String::String ( long  x)
explicit

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ String() [14/17]

String::String ( unsigned long  x)
explicit

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ String() [15/17]

String::String ( int64_t  x)
explicit

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ String() [16/17]

String::String ( uint64_t  x)
explicit

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ String() [17/17]

String::String ( double  x)
explicit

Construct a base-10 string representation of x.

Note
This function is only available at user level.

◆ ~String()

String::~String ( )
inline

Destroy a String, freeing memory if necessary.

Member Function Documentation

◆ make_empty()

const String & String::make_empty ( )
inlinestatic

Return a const reference to an empty String.

May be quicker than String::String().

◆ make_uninitialized()

String String::make_uninitialized ( int  len)
inlinestatic

Return a String containing len unknown characters.

◆ make_stable() [1/3]

String String::make_stable ( const char *  cstr)
inlinestatic

Return a String that directly references the C string cstr.

never

The make_stable() functions are suitable for static constant strings whose data is known to stay around forever, such as C string constants.

Warning
The String implementation may access cstr's terminating null character.

◆ make_stable() [2/3]

String String::make_stable ( const char *  s,
int  len 
)
inlinestatic

Return a String that directly references the first len characters of s.

If len < 0, treats s as a null-terminated C string.

Warning
The String implementation may access s[len], which should remain constant even though it's not part of the String.

◆ make_stable() [3/3]

String String::make_stable ( const char *  first,
const char *  last 
)
inlinestatic

Return a String that directly references the character data in [first, last).

Parameters
firstpointer to the first character in the character data
lastpointer one beyond the last character in the character data (but see the warning)

This function is suitable for static constant strings whose data is known to stay around forever, such as C string constants. Returns an empty string if first >= last.

Warning
The String implementation may access *last, which should remain constant even though it's not part of the String.

◆ make_numeric() [1/2]

String String::make_numeric ( intmax_t  num,
int  base = 10,
bool  uppercase = true 
)
static

Create and return a string representation of x.

Parameters
xnumber
basebase; must be 8, 10, or 16, defaults to 10
uppercaseif true, then use uppercase letters in base 16

◆ make_numeric() [2/2]

String String::make_numeric ( uintmax_t  num,
int  base = 10,
bool  uppercase = true 
)
static

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ data()

const char * String::data ( ) const
inline

Return a pointer to the string's data.

Only the first length() characters are valid, and the string might not be null-terminated.

◆ length()

int String::length ( ) const
inline

Return the string's length.

◆ c_str()

const char * String::c_str ( ) const
inline

Null-terminate the string.

The terminating null character isn't considered part of the string, so this->length() doesn't change. Returns a corresponding C string pointer. The returned pointer is semi-temporary; it will persist until the string is destroyed or appended to.

◆ operator unspecified_bool_type()

String::operator unspecified_bool_type ( ) const
inline

Test if the string is nonempty.

◆ empty()

bool String::empty ( ) const
inline

Test if the string is empty.

◆ operator!()

bool String::operator! ( ) const
inline

Test if the string is empty.

◆ begin()

String::const_iterator String::begin ( ) const
inline

Return an iterator for the first character in the string.

String iterators are simply pointers into string data, so they are quite efficient.

See also
String::data

◆ end()

String::const_iterator String::end ( ) const
inline

Return an iterator for the end of the string.

The return value points one character beyond the last character in the string.

◆ operator[]()

char String::operator[] ( int  i) const
inline

Return the i th character in the string.

Does not check bounds.

See also
String::at

◆ at()

char String::at ( int  i) const
inline

Return the i th character in the string.

Checks bounds: an assertion will fail if i is less than 0 or not less than length().

See also
String::operator[]

◆ front()

char String::front ( ) const
inline

Return the first character in the string.

Does not check bounds. Same as (*this)[0].

◆ back()

char String::back ( ) const
inline

Return the last character in the string.

Does not check bounds. Same as (*this)[length() - 1].

◆ hashcode() [1/3]

uint32_t String::hashcode ( const char *  first,
const char *  last 
)
static

Return a 32-bit hash function of the characters in [first, last).

Uses Paul Hsieh's "SuperFastHash" algorithm, described at http://www.azillionmonkeys.com/qed/hash.html This hash function uses all characters in the string.

Invariant
If last1 - first1 == last2 - first2 and memcmp(first1, first2, last1 - first1) == 0, then hashcode(first1, last1) == hashcode(first2, last2).

◆ hashcode() [2/3]

uint32_t String::hashcode ( const unsigned char *  first,
const unsigned char *  last 
)
inlinestatic

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ hashcode() [3/3]

uint32_t String::hashcode ( ) const
inline

Returns a 32-bit hash function of this string's characters.

Equivalent to String::hashcode(begin(), end()). Uses Paul Hsieh's "SuperFastHash."

Invariant
If s1 == s2, then s1.hashcode() == s2.hashcode().

◆ substring() [1/3]

String String::substring ( const char *  first,
const char *  last 
) const
inline

Return a substring of the current string starting at first and ending before last.

Parameters
firstpointer to the first substring character
lastpointer one beyond the last substring character

Returns an empty string if first >= last. Also returns an empty string if first or last is out of range (i.e., either less than this->begin() or greater than this->end()), but this should be considered a programming error; a future version may generate a warning for this case.

◆ substring() [2/3]

String String::substring ( int  pos,
int  len 
) const

Return a substring of this string, consisting of the len characters starting at index pos.

Parameters
possubstring's first position relative to the string
lenlength of substring

If pos is negative, starts that far from the end of the string. If len is negative, leaves that many characters off the end of the string. If pos and len specify a substring that is partly outside the string, only the part within the string is returned. If the substring is beyond either end of the string, returns an empty string (but this should be considered a programming error; a future version may generate a warning for this case).

Note
String::substring() is intended to behave like Perl's substr().

◆ substring() [3/3]

String String::substring ( int  pos) const
inline

Return the suffix of the current string starting at index pos.

If pos is negative, starts that far from the end of the string. If pos is so negative that the suffix starts outside the string, then the entire string is returned. If the substring is beyond the end of the string (pos > length()), returns an empty string (but this should be considered a programming error; a future version may generate a warning for this case).

Note
String::substring() is intended to behave like Perl's substr().

◆ trim()

String String::trim ( ) const

Return a substring with spaces trimmed from both sides.

◆ trim_space()

String String::trim_space ( ) const

Return a substring with spaces trimmed from the end.

◆ trim_space_left()

String String::trim_space_left ( ) const

Return a substring with spaces trimmed from the start.

◆ remove()

String String::remove ( char  c) const

Return a string with from replaced by to.

◆ replace() [1/2]

String String::replace ( char  from,
char  to 
) const

Return a string with from replaced by to.

◆ replace() [2/2]

String String::replace ( String  from,
String  to 
) const

Return a string with from replaced by to.

◆ equals() [1/2]

bool String::equals ( const String &  x) const
inline

Test if this string equals x.

◆ equals() [2/2]

bool String::equals ( const char *  s,
int  len 
) const
inline

Test if this string is equal to the data in s.

Parameters
sstring data to compare to
lenlength of s

Same as String::compare(*this, String(s, len)) == 0. If len < 0, then treats s as a null-terminated C string.

See also
String::compare(const String &a, const String &b)

◆ compare() [1/3]

int String::compare ( const String &  a,
const String &  b 
)
inlinestatic

Compare two strings.

Parameters
afirst string to compare
bsecond string to compare

Returns 0 if a == b, negative if a < b in lexicographic order, and positive if a > b in lexicographic order. The lexicographic order treats all characters as unsigned.

◆ compare() [2/3]

int String::compare ( const String &  x) const
inline

Compare this string with string x.

Same as String::compare(*this, x).

See also
String::compare(const String &a, const String &b)

◆ compare() [3/3]

int String::compare ( const char *  s,
int  len 
) const

Compare this string with the data in s.

Parameters
sstring data to compare to
lenlength of s

Same as String::compare(*this, String(s, len)). If len < 0, then treats s as a null-terminated C string.

See also
String::compare(const String &a, const String &b)

◆ starts_with() [1/2]

bool String::starts_with ( const String &  x) const
inline

Test if this string begins with prefix x.

Same as String::starts_with(x.data(), x.length()).

◆ starts_with() [2/2]

bool String::starts_with ( const char *  s,
int  len 
) const

Return true iff this string begins with the data in s.

Parameters
sstring data to compare to
lenlength of s

If len < 0, then treats s as a null-terminated C string.

See also
String::compare(const String &a, const String &b)

◆ glob_match()

bool String::glob_match ( const String &  pattern) const

Test whether this string matches the glob pattern.

Parameters
patternglob pattern
Returns
True iff this string matches pattern.

A glob pattern is a pattern that may contain wildcard characters. * in the pattern matches zero or more arbitrary characters in str; ? matches exactly one arbitrary character in str; [...] matches any of the characters in brackets; and [^...] matches any character not in the brackets. A backslash \ escapes a wildcard character so that it matches only itself.

◆ split()

Vector< String > String::split ( char  c) const

Split a string using an input character as a delimiter. The outcome of the split is a vector of tokens.

Parameters
ccharacter to use as a delimiter

Return a vector of tokens or an empty vector if no such delimiter exists.

◆ find_left() [1/2]

int String::find_left ( char  c,
int  start = 0 
) const

Search for a character in a string.

Parameters
ccharacter to search for
startinitial search position

Return the index of the leftmost occurence of c, starting at index start and working up to the end of the string. Returns -1 if c is not found.

◆ find_left() [2/2]

int String::find_left ( const String &  x,
int  start = 0 
) const

Search for a substring in a string.

Parameters
xsubstring to search for
startinitial search position

Return the index of the leftmost occurence of the substring str, starting at index start and working up to the end of the string. Returns -1 if str is not found.

◆ find_right()

int String::find_right ( char  c,
int  start = 0x7FFFFFFF 
) const

Search for a character in a string.

Parameters
ccharacter to search for
startinitial search position

Return the index of the rightmost occurence of the character c, starting at index start and working back to the beginning of the string. Returns -1 if c is not found. start may start beyond the end of the string.

◆ search()

const char * String::search ( String  pattern)
inline

Search for the non-empty pattern in this string

◆ lower()

String String::lower ( ) const

Return a lowercased version of this string.

Translates the ASCII characters 'A' through 'Z' into their lowercase equivalents.

◆ upper()

String String::upper ( ) const

Return an uppercased version of this string.

Translates the ASCII characters 'a' through 'z' into their uppercase equivalents.

◆ printable()

String String::printable ( ) const

Return a "printable" version of this string.

Translates control characters 0-31 into "control" sequences, such as "^@" for the null character, and characters 127-255 into octal escape sequences, such as "\377" for 255.

◆ quoted_hex()

String String::quoted_hex ( ) const

Return a hex-quoted version of the string.

For example, the string "Abcd" would convert to "\<41626364>".

◆ encode_json()

String String::encode_json ( ) const

Return this string's contents encoded for JSON.

Precondition
*this is encoded in UTF-8.

For instance, String("a\"").encode_json() == "a\\\"". Note that the double-quote characters that usually surround a JSON string are not included.

◆ operator=() [1/2]

String & String::operator= ( const String &  x)
inline

Assign this string to x.

◆ operator=() [2/2]

String & String::operator= ( const char *  cstr)
inline

Assign this string to the C string cstr.

◆ swap()

void String::swap ( String &  x)
inline

Swap the values of this string and x.

◆ append() [1/5]

void String::append ( const String &  x)
inline

Append x to this string.

◆ append() [2/5]

void String::append ( const char *  cstr)
inline

Append the null-terminated C string cstr to this string.

Parameters
cstrdata to append

◆ append() [3/5]

void String::append ( const char *  s,
int  len 
)
inline

Append the first len characters of s to this string.

Parameters
sdata to append
lenlength of data
Precondition
len >= 0

◆ append() [4/5]

void String::append ( const char *  first,
const char *  last 
)
inline

Appends the data from first to last to this string.

Does nothing if first >= last.

◆ append() [5/5]

void String::append ( char  c)
inline

Append the character c to this string.

◆ append_fill()

void String::append_fill ( int  c,
int  len 
)

Append len copies of character c to this string.

◆ append_uninitialized()

char * String::append_uninitialized ( int  len)

Append len unknown characters to this string.

Returns
Modifiable pointer to the appended characters.

The caller may safely modify the returned memory. Null is returned if the string becomes out-of-memory.

◆ operator+=() [1/3]

String & String::operator+= ( const String &  x)
inline

Append x to this string.

never

Returns
*this

◆ operator+=() [2/3]

String & String::operator+= ( const char *  cstr)
inline

Append the null-terminated C string cstr to this string.

Returns
*this

◆ operator+=() [3/3]

String & String::operator+= ( char  c)
inline

Append the character c to this string.

Returns
*this

◆ is_shared()

bool String::is_shared ( ) const
inline

Test if the String's data is shared or immutable.

◆ is_stable()

bool String::is_stable ( ) const
inline

Test if the String's data is immutable.

◆ unique()

String String::unique ( ) const
inline

Return an unshared version of this String.

Deprecated:
Use String::unshared() instead.

The return value shares no data with any other non-stable String.

◆ unshared()

String String::unshared ( ) const
inline

Return an unshared version of this String.

The return value shares no data with any other non-stable String.

◆ compact()

String String::compact ( ) const
inline

Return a compact version of this String.

The return value shares no more than 256 bytes of data with any other non-stable String.

◆ mutable_data()

char * String::mutable_data ( )

Ensure the string's data is unshared and return a mutable pointer to it.

◆ mutable_c_str()

char * String::mutable_c_str ( )

Null-terminate the string and return a mutable pointer to its data.

See also
String::c_str

◆ make_out_of_memory()

const String & String::make_out_of_memory ( )
inlinestatic

Return a const reference to a canonical out-of-memory String.

◆ out_of_memory()

bool String::out_of_memory ( ) const
inline

Test if this is an out-of-memory string.

◆ out_of_memory_data()

const char * String::out_of_memory_data ( )
inlinestatic

Return the data pointer used for out-of-memory strings.

◆ out_of_memory_length()

int String::out_of_memory_length ( )
inlinestatic

Return the length of canonical out-of-memory strings.

◆ empty_data()

const char * String::empty_data ( )
inlinestatic

Return the data pointer used for canonical empty strings.

The returned value may be dereferenced; it points to a null character.

◆ skip_utf8_char() [1/2]

const char * String::skip_utf8_char ( const char *  first,
const char *  last 
)
inlinestatic

Return a pointer to the next character in UTF-8 encoding.

Precondition
first < last

If first doesn't point at a valid UTF-8 character, returns first.

◆ skip_utf8_char() [2/2]

const unsigned char * String::skip_utf8_char ( const unsigned char *  first,
const unsigned char *  last 
)
static

Return a pointer to the next character in UTF-8 encoding.

Precondition
first < last

If first doesn't point at a valid UTF-8 character, returns first.

Friends And Related Symbol Documentation

◆ operator==()

bool operator== ( const String &  a,
const String &  b 
)
related

Compares two strings for equality.

Returns true iff the two operands have the same lengths and the same characters in the same order. At most one of the operands can be a null-terminated C string.

See also
String::compare

◆ operator!=()

bool operator!= ( const String &  a,
const String &  b 
)
related

Compare two Strings for inequality.

Returns true iff !(a == b). At most one of the operands can be a null-terminated C string.

◆ operator<()

bool operator< ( const String &  a,
const String &  b 
)
related

Compare two Strings.

Returns true iff a < b in lexicographic order.

See also
String::compare

◆ operator<=()

bool operator<= ( const String &  a,
const String &  b 
)
related

Compare two Strings.

Returns true iff a <= b in lexicographic order.

See also
String::compare

◆ operator>()

bool operator> ( const String &  a,
const String &  b 
)
related

Compare two Strings.

Returns true iff a > b in lexicographic order.

See also
String::compare

◆ operator>=()

bool operator>= ( const String &  a,
const String &  b 
)
related

Compare two Strings.

Returns true iff a >= b in lexicographic order.

See also
String::compare

◆ operator+() [1/2]

String operator+ ( String  a,
const String &  b 
)
related

Concatenate the operands and return the result.

At most one of the two operands can be a null-terminated C string.

◆ operator+() [2/2]

String operator+ ( String  a,
char  b 
)
related

Concatenate the operands and return the result.

The second operand is a single character.


The documentation for this class was generated from the following files: