zorba::String

The Zorba string class.

Its API is mostly compatible with that of std::string.

#include <zorba/zorba_string.h>

Public Types

std::allocator< value_type >allocator_type
const_pointerconst_iterator
value_type const *const_pointer
value_type const &const_reference
std::reverse_iterator< const_iterator >const_reverse_iterator
allocator_type::difference_typedifference_type
pointeriterator
value_type *pointer
value_type &reference
std::reverse_iterator< iterator >reverse_iterator
allocator_type::size_typesize_type
std::char_traits< value_type >traits_type
charvalue_type

Public Static Attributes

static size_type constnpos
The special value used to denote either (a) the maximum possible number as input or (b) "not found" as a result.

Private Attibutes

string_storage_typestring_storage_

Friend Classes

friend ZORBA_DLL_PUBLIC Stringoperator+String const &  , String const &  )
friend ZORBA_DLL_PUBLIC Stringoperator+String const &  , std::string const &  )
friend ZORBA_DLL_PUBLIC Stringoperator+String const &  , const_pointer  )
friend ZORBA_DLL_PUBLIC Stringoperator+( std::string const &  , String const &  )
friend ZORBA_DLL_PUBLIC Stringoperator+const_pointer  , String const &  )
friend ZORBA_DLL_PUBLIC booloperator<String const &  , String const &  )
friend ZORBA_DLL_PUBLIC booloperator<String const &  , std::string const &  )
friend ZORBA_DLL_PUBLIC booloperator<String const &  , const_pointer  )
friend ZORBA_DLL_PUBLIC booloperator<( std::string const &  , String const &  )
friend ZORBA_DLL_PUBLIC booloperator<const_pointer  , String const &  )
friend ZORBA_DLL_PUBLIC std::ostream &operator<<( std::ostream &  , String const &  )
friend ZORBA_DLL_PUBLIC booloperator<=String const &  , String const &  )
friend ZORBA_DLL_PUBLIC booloperator<=String const &  , std::string const &  )
friend ZORBA_DLL_PUBLIC booloperator<=String const &  , const_pointer  )
friend ZORBA_DLL_PUBLIC booloperator<=( std::string const &  , String const &  )
friend ZORBA_DLL_PUBLIC booloperator<=const_pointer  , String const &  )
friend ZORBA_DLL_PUBLIC booloperator==String const &  , String const &  )
friend ZORBA_DLL_PUBLIC booloperator==String const &  , std::string const &  )
friend ZORBA_DLL_PUBLIC booloperator==String const &  , const_pointer  )
friend classUnmarshaller

Public Functions

String &appendString const & s )
Appends the given string to this string.
String &appendString const & s, size_type s_pos, size_type s_n )
Appends a substring of the given string to this string.
String &append( std::string const & s )
Appends the given string to this string.
String &append( std::string const & s, size_type s_pos, size_type s_n )
Appends a substring of the given string to this string.
String &appendconst_pointer s )
Appends the given C string to this string.
String &appendconst_pointer s, size_type s_n )
Appends the given C string to this string.
String &appendsize_type n, value_type c )
Appends n copies of c to this string.
String &assignString const & s )
Assigns another string to this string.
String &assign( std::string const & s )
Assigns a std::string to this string.
String &assignString const & s, size_type pos, size_type n )
Assigns a substring of a string to this string.
String &assign( std::string const & s, size_type pos, size_type n )
Assigns a substring of a std::string to this string.
String &assignconst_pointer s )
Assigns a C to this string.
String &assignconst_pointer s, size_type n )
Assigns a substring of a C to this string.
String &assignsize_type n, value_type c )
Assigned n copies of a character to this string.
String &assignconst_iterator i, const_iterator j )
Assigns characters from a range of characters [i,j).
referenceatsize_type pos )
References a particular character within the string.
const value_typeatsize_type pos )
References a particular character within the string.
iteratorbegin()
Returns a read/write iterator positioned at the first character of the string.
const const_iteratorbegin()
Returns a read-only iterator positioned at the first character of the string.
const const_pointerc_str()
Gets a pointer to a null-terminated array of characters representing the string's contents.
const size_typecapacity()
Gets the capacity of this string.
voidclear()
Erases the string making it empty.
const intcompareString const & s )
Compares this string against another.
const intcompare( std::string const & s )
Compares this string against another.
const intcompareconst_pointer s )
Compares this string against a C string.
const intcomparesize_type pos, size_type n, String const & s )
Compares a substring of this string against another.
const intcomparesize_type pos, size_type n, std::string const & s )
Compares a substring of this string against another.
const intcomparesize_type pos, size_type n, const_pointer s )
Compares a substring of this string against a C string.
const intcomparesize_type pos, size_type n, String const & s, size_type s_pos, size_type s_n )
Compares a substring of this string against a substring of another.
const intcomparesize_type pos, size_type n, std::string const & s, size_type s_pos, size_type s_n )
Compares a substring of this string against a substring of another.
const intcomparesize_type pos, size_type n, const_pointer s, size_type s_n )
Compares a substring of this string against a C string.
const size_typecopypointer buf, size_type n, size_type pos=0 )
Copies a substring to a C string buffer.
const const_pointerdata()
Gets a pointer to the raw character data comprising the string, not necessarily null-terminated.
const inline boolempty()
Checks whether the string is empty.
iteratorend()
Returns a read/write iterator positioned at one past the last character of the string.
const const_iteratorend()
Returns a read-only iterator positioned at one past the last character of the string.
String &erasesize_type pos=0 , size_type n= )
Erases the given number of characters starting at the given position.
iteratoreraseiterator i )
Erases the character at the given iterator's position.
iteratoreraseiterator i, iterator j )
Erases a range of characters [i,j).
const size_typefindString const & s, size_type pos=0 )
Searches this string for the given string starting at the given position.
const size_typefind( std::string const & s, size_type pos=0 )
Searches this string for the given string starting at the given position.
const size_typefindconst_pointer s, size_type pos=0 )
Searches this string for the given string starting at the given position.
const size_typefindconst_pointer s, size_type pos, size_type s_n )
Searches this string for the given string starting at the given position.
const size_typefindvalue_type c, size_type pos=0 )
Searches this string for the given character staring at the given position.
const size_typefind_first_not_ofString const & s, size_type pos=0 )
Searches this string for any one of the characters not in s starting at the given position.
const size_typefind_first_not_of( std::string const & s, size_type pos=0 )
Searches this string for any one of the characters not in s starting at the given position.
const size_typefind_first_not_ofconst_pointer s, size_type pos=0 )
Searches this string for any one of the characters not in s starting at the given position.
const size_typefind_first_not_ofconst_pointer s, size_type pos, size_type s_n )
Searches this string for any one of the first s_n characters not in s starting at the given position.
const size_typefind_first_not_ofvalue_type c, size_type pos=0 )
Searches this string for any character except the given character starting at the given position.
const size_typefind_first_ofString const & s, size_type pos=0 )
Searches this string for any one of the characters in s starting at the given position.
const size_typefind_first_of( std::string const & s, size_type pos=0 )
Searches this string for any one of the characters in s starting at the given position.
const size_typefind_first_ofconst_pointer s, size_type pos=0 )
Searches this string for any one of the characters in s starting at the given position.
const size_typefind_first_ofconst_pointer s, size_type pos, size_type s_n )
Searches this string for any one of the first s_n characters in s starting at the given position.
const size_typefind_first_ofvalue_type c, size_type pos=0 )
Searches this string for the given character starting at the given position.
const size_typefind_last_not_ofString const & s, size_type pos= )
Searches this string backwards for any one of the characters not in s starting at the given position.
const size_typefind_last_not_of( std::string const & s, size_type pos= )
Searches this string backwards for any one of the characters not in s starting at the given position.
const size_typefind_last_not_ofconst_pointer s, size_type pos= )
Searches this string backwards for any one of the characters not in s starting at the given position.
const size_typefind_last_not_ofconst_pointer s, size_type pos, size_type s_n )
Searches this string backwards for any one of the first s_n characters not in s starting at the given position.
const size_typefind_last_not_ofvalue_type c, size_type pos= )
Searches this string backwards for any character except the given character starting at the given position.
const size_typefind_last_ofString const & s, size_type pos= )
Searches this string backwards for any one of the characters in s starting at the given position.
const size_typefind_last_of( std::string const & s, size_type pos= )
Searches this string backwards for any one of the characters in s starting at the given position.
const size_typefind_last_ofconst_pointer s, size_type pos= )
Searches this string backwards for any one of the characters in s starting at the given position.
const size_typefind_last_ofconst_pointer s, size_type pos, size_type s_n )
Searches this string backwards for any one of the first s_n characters in s starting at the given position.
const size_typefind_last_ofvalue_type c, size_type pos= )
Searches this string backwards for the given character starting at the given position.
String &insertsize_type pos, String const & s )
Inserts the given string into this string at the given position.
String &insertsize_type pos, std::string const & s )
Inserts the given string into this string at the given position.
String &insertsize_type pos, const_pointer s )
Inserts the given string into this string at the given position.
String &insertsize_type pos, String const & s, size_type s_pos, size_type s_n )
Inserts a substring of the given string into this string at the given position.
String &insertsize_type pos, std::string const & s, size_type s_pos, size_type s_n )
Inserts a substring of the given string into this string at the given position.
String &insertsize_type pos, const_pointer s, size_type s_n )
Inserts a substring of the given string into this string at the given position.
String &insertsize_type pos, size_type n, value_type c )
Inserts n copies of c into this string at the given position.
iteratorinsertiterator pos, value_type c )
Inserts the given character into this string at the given position.
voidinsertiterator pos, size_type n, value_type c )
Inserts n copies of c into this string at the given position.
const size_typelength()
Gets the number of characters in this string.
inline String &operator+=String const & s )
Appends the given string to this string.
inline String &operator+=( std::string const & s )
Appends the given std::string to this string.
inline String &operator+=const_pointer s )
Appends the given C string to this string.
inline String &operator+=value_type c )
Appends the given character to this string.
String &operator=String const & s )
Assigns another string to this string.
String &operator=( std::string const & s )
Assigns a std::string to this string.
String &operator=const_pointer s )
Assigns a C string to this string.
String &operator=value_type c )
Assigns a character to this string.
const const_referenceoperator[]size_type pos )
References a particular character within the string.
voidpush_backvalue_type c )
Appends the given character to this string.
reverse_iteratorrbegin()
Returns a read/write reverse iterator positioned at the first character of the reversed string.
const const_reverse_iteratorrbegin()
Returns a read-only reverse iterator positioned at the first character of the reversed string.
reverse_iteratorrend()
Returns a read/write reverse iterator positioned at one past the last character of the reversed string.
const const_reverse_iteratorrend()
Returns a read-only reverse iterator positioned at one past the last character of the reversed string.
String &replacesize_type pos, size_type n, String const & s )
Replaces n characters of this string starting at the given position with the given string.
String &replacesize_type pos, size_type n, std::string const & s )
Replaces n characters of this string starting at the given position with the given string.
String &replacesize_type pos, size_type n, const_pointer s )
Replaces n characters of this string starting at the given position with the given string.
String &replacesize_type pos, size_type n, String const & s, size_type s_pos, size_type s_n )
Replaces n characters of this string starting at the given position with a substring of the given string.
String &replacesize_type pos, size_type n, std::string const & s, size_type s_pos, size_type s_n )
Replaces n characters of this string starting at the given position with a substring of the given string.
String &replacesize_type pos, size_type n, const_pointer s, size_type s_n )
Replaces n characters of this string starting at the given position with a substring of the given string.
String &replacesize_type pos, size_type n, size_type c_n, value_type c )
Replaces n characters of this string starting at the given position with c_n copies of c.
String &replaceiterator i, iterator j, String const & s )
Replaces the range of characters [i,j) of this string with the given string.
String &replaceiterator i, iterator j, std::string const & s )
Replaces the range of characters [i,j) of this string with the given string.
String &replaceiterator i, iterator j, const_pointer s )
Replaces the range of characters [i,j) of this string with the given string.
String &replaceiterator i, iterator j, const_pointer s, size_type s_n )
Replaces the range of characters [i,j) of this string with a substring of the given string.
String &replaceiterator i, iterator j, size_type n, value_type c )
Replaces the range of characters [i,j) of this string with c_n copies of c.
String &replaceiterator i, iterator j, iterator si, iterator sj )
Replaces the range of characters [i,j) of this string with the range of characters [si,sj).
voidreservesize_type n )
Attemts to pre-allocated enough memory to contain the given number of bytes.
voidresizesize_type n, value_type c=() )
Resizes the string to the given number of characters.
const size_typerfindString const & s, size_type pos= )
Searches this backwards string for the given string starting at the given position.
const size_typerfind( std::string const & s, size_type pos= )
Searches this backwards string for the given string starting at the given position.
const size_typerfindconst_pointer s, size_type pos= )
Searches this backwards string for the given string starting at the given position.
const size_typerfindconst_pointer s, size_type pos, size_type s_n )
Searches this string backwards for the given string starting at the given position.
const size_typerfindvalue_type c, size_type pos= )
Searches this string backwards for the given character staring at the given position.
const inline size_typesize()
Gets the number of characters in this string.
const std::stringstr()
Gets a std::string equivalent of this string.
String()
Constructs an empty string.
StringString const & s )
Copy constructs a new string from an existing string.
String( std::string const & s )
Constructs a new string from an existing std::string.
Stringconst_pointer s )
Constructs a string from the given C string.
StringString const & s, size_type pos, size_type n= )
Copy constructs a new string from a substring of an existing string.
String( std::string const & s, size_type pos, size_type n= )
Constructs a new string from a substring of an existing std::string.
Stringconst_pointer s, size_type n )
Constructs a string from the given C string.
Stringsize_type n, value_type c )
Constructs a new string as n copies of c.
Stringconst_iterator i, const_iterator j )
Constructs a string from a range of characters [i,j).
const Stringsubstrsize_type pos=0 , size_type n= )
Creates a new string that is a substring of this string.
voidswapString & s )
Swaps the contents of this string with another.
~String()
Destructs this string.

Private Functions

String &operator=( zstring_ptr  )
String( zstring_ptr  )

Private Static Functions

static voidsize_check()

Public Types

allocator_type

std::allocator< value_type > allocator_type

const_iterator

const_pointer const_iterator

const_pointer

value_type const * const_pointer

const_reference

value_type const & const_reference

const_reverse_iterator

std::reverse_iterator< const_iterator > const_reverse_iterator

difference_type

allocator_type::difference_type difference_type

iterator

pointer iterator

pointer

value_type * pointer

reference

value_type & reference

reverse_iterator

std::reverse_iterator< iterator > reverse_iterator

size_type

allocator_type::size_type size_type

traits_type

std::char_traits< value_type > traits_type

value_type

char value_type

Public Static Attributes

npos

static size_type const npos

The special value used to denote either (a) the maximum possible number as input or (b) "not found" as a result.

Private Attibutes

string_storage_

string_storage_type string_storage_

Friend Classes

operator+

friend ZORBA_DLL_PUBLIC String operator+(
    String const &  ,
    String const & 
)

operator+

friend ZORBA_DLL_PUBLIC String operator+(
    String const &  ,
    std::string const & 
)

operator+

friend ZORBA_DLL_PUBLIC String operator+(
    String const &  ,
    const_pointer 
)

operator+

friend ZORBA_DLL_PUBLIC String operator+(
    std::string const &  ,
    String const & 
)

operator+

friend ZORBA_DLL_PUBLIC String operator+(
    const_pointer  ,
    String const & 
)

operator<

friend ZORBA_DLL_PUBLIC bool operator<(
    String const &  ,
    String const & 
)

operator<

friend ZORBA_DLL_PUBLIC bool operator<(
    String const &  ,
    std::string const & 
)

operator<

friend ZORBA_DLL_PUBLIC bool operator<(
    String const &  ,
    const_pointer 
)

operator<

friend ZORBA_DLL_PUBLIC bool operator<(
    std::string const &  ,
    String const & 
)

operator<

friend ZORBA_DLL_PUBLIC bool operator<(
    const_pointer  ,
    String const & 
)

operator<<

friend ZORBA_DLL_PUBLIC std::ostream & operator<<(
    std::ostream &  ,
    String const & 
)

operator<=

friend ZORBA_DLL_PUBLIC bool operator<=(
    String const &  ,
    String const & 
)

operator<=

friend ZORBA_DLL_PUBLIC bool operator<=(
    String const &  ,
    std::string const & 
)

operator<=

friend ZORBA_DLL_PUBLIC bool operator<=(
    String const &  ,
    const_pointer 
)

operator<=

friend ZORBA_DLL_PUBLIC bool operator<=(
    std::string const &  ,
    String const & 
)

operator<=

friend ZORBA_DLL_PUBLIC bool operator<=(
    const_pointer  ,
    String const & 
)

operator==

friend ZORBA_DLL_PUBLIC bool operator==(
    String const &  ,
    String const & 
)

operator==

friend ZORBA_DLL_PUBLIC bool operator==(
    String const &  ,
    std::string const & 
)

operator==

friend ZORBA_DLL_PUBLIC bool operator==(
    String const &  ,
    const_pointer 
)

Unmarshaller

friend class Unmarshaller

Public Functions

append

String & append(
    String const & s
)

Appends the given string to this string.

Parameters

s

The string to append.

Returns

this string.

append

String & append(
    String const & s,
    size_type s_pos,
    size_type s_n
)

Appends a substring of the given string to this string.

Parameters

s

The string to append.

s_pos

The starting position is s.

s_n

The number of characters of s to append.

Returns

this string.

append

String & append(
    std::string const & s
)

Appends the given string to this string.

Parameters

s

The string to append.

Returns

this string.

append

String & append(
    std::string const & s,
    size_type s_pos,
    size_type s_n
)

Appends a substring of the given string to this string.

Parameters

s

The string to append.

s_pos

The starting position is s.

s_n

The number of characters of s to append.

Returns

this string.

append

String & append(
    const_pointer s
)

Appends the given C string to this string.

Parameters

s

The null-terminated C string to append.

Returns

this string.

append

String & append(
    const_pointer s,
    size_type s_n
)

Appends the given C string to this string.

Parameters

s

The C string to append.

s_n

The number of characters of s to append.

Returns

this string.

append

String & append(
    size_type n,
    value_type c
)

Appends n copies of c to this string.

Parameters

n

The numer of copies of c to append.

c

The character to append.

Returns

this string.

assign

String & assign(
    String const & s
)

Assigns another string to this string.

Parameters

s

The string to assign from.

Returns

this string.

assign

String & assign(
    std::string const & s
)

Assigns a std::string to this string.

Parameters

s

The string to assign from.

Returns

this string.

assign

String & assign(
    String const & s,
    size_type pos,
    size_type n
)

Assigns a substring of a string to this string.

Parameters

s

The string to assign from.

pos

The starting position withing s.

n

The number of characters to assign.

Returns

this string.

assign

String & assign(
    std::string const & s,
    size_type pos,
    size_type n
)

Assigns a substring of a std::string to this string.

Parameters

s

The string to assign from.

pos

The starting position withing s.

n

The number of characters to assign.

Returns

this string.

assign

String & assign(
    const_pointer s
)

Assigns a C to this string.

Parameters

s

The null-terminated C string to assign from.

Returns

this string.

assign

String & assign(
    const_pointer s,
    size_type n
)

Assigns a substring of a C to this string.

Parameters

s

The C string to assign from.

n

The number of characters to assign.

Returns

this string.

assign

String & assign(
    size_type n,
    value_type c
)

Assigned n copies of a character to this string.

Parameters

n

The number of copies of the character.

c

The character.

Returns

this string.

assign

String & assign(
    const_iterator i,
    const_iterator j
)

Assigns characters from a range of characters [i,j).

Parameters

i

The iterator marking the first character of the range.

j

The iterator marking one past the last character of the range.

at

reference at(
    size_type pos
)

References a particular character within the string.

Parameters

pos

The index of the character. The index is bounds-checked.

Returns

said character as an l-value.

Parameters

std::out_of_range

if pos >= .

at

const value_type at(
    size_type pos
)

References a particular character within the string.

Parameters

pos

The index of the character. The index is bounds-checked.

Returns

said character as an r-value.

begin

iterator begin()

Returns a read/write iterator positioned at the first character of the string.

Returns

said iterator.

begin

const const_iterator begin()

Returns a read-only iterator positioned at the first character of the string.

Returns

said iterator.

c_str

const const_pointer c_str()

Gets a pointer to a null-terminated array of characters representing the string's contents.

Returns

said pointer.

Returns

data()

capacity

const size_type capacity()

Gets the capacity of this string.

Returns

said capacity.

clear

void clear()

Erases the string making it empty.

compare

const int compare(
    String const & s
)

Compares this string against another.

Parameters

s

The string to compare to.

Returns

-1 only if this string < s, 0 only if this string == s, or +1 only if this string > s.

compare

const int compare(
    std::string const & s
)

Compares this string against another.

Parameters

s

The string to compare to.

Returns

-1 only if this string < s, 0 only if this string == s, or +1 only if this string > s.

compare

const int compare(
    const_pointer s
)

Compares this string against a C string.

Parameters

s

The null-terminated C string to compare to.

Returns

-1 only if this string < s, 0 only if this string == s, or +1 only if this string > s.

compare

const int compare(
    size_type pos,
    size_type n,
    String const & s
)

Compares a substring of this string against another.

Parameters

pos

The starting position within this string.

n

The number of characters to compare.

s

The string to compare to.

Returns

-1 only if this string < s, 0 only if this string == s, or +1 only if this string > s.

compare

const int compare(
    size_type pos,
    size_type n,
    std::string const & s
)

Compares a substring of this string against another.

Parameters

pos

The starting position within this string.

n

The number of characters to compare.

s

The string to compare to.

Returns

-1 only if this string < s, 0 only if this string == s, or +1 only if this string > s.

compare

const int compare(
    size_type pos,
    size_type n,
    const_pointer s
)

Compares a substring of this string against a C string.

Parameters

pos

The starting position within this string.

n

The number of characters to compare.

s

The null-terminated C string to compare to.

Returns

-1 only if this string < s, 0 only if this string == s, or +1 only if this string > s.

compare

const int compare(
    size_type pos,
    size_type n,
    String const & s,
    size_type s_pos,
    size_type s_n
)

Compares a substring of this string against a substring of another.

Parameters

pos

The starting position within this string.

n

The number of characters to compare.

s

The string to compare to.

s_pos

The starting position within s.

s_n

The number of characters of s to compare.

Returns

-1 only if this string < s, 0 only if this string == s, or +1 only if this string > s.

compare

const int compare(
    size_type pos,
    size_type n,
    std::string const & s,
    size_type s_pos,
    size_type s_n
)

Compares a substring of this string against a substring of another.

Parameters

pos

The starting position within this string.

n

The number of characters to compare.

s

The string to compare to.

s_pos

The starting position within s.

s_n

The number of characters of s to compare.

Returns

-1 only if this string < s, 0 only if this string == s, or +1 only if this string > s.

compare

const int compare(
    size_type pos,
    size_type n,
    const_pointer s,
    size_type s_n
)

Compares a substring of this string against a C string.

Parameters

pos

The starting position within this string.

n

The number of characters to compare.

s

The C string to compare to.

s_n

The number of characters of s to compare.

Returns

-1 only if this string < s, 0 only if this string == s, or +1 only if this string > s.

copy

const size_type copy(
    pointer buf,
    size_type n,
    size_type pos=0
)

Copies a substring to a C string buffer.

Parameters

buf

The buffer to copy into.

n

The number of characters to copy. It's the caller's responsibility to ensure that the size of buf <= n.

pos

The position of the first character to copy.

Returns

the number of characters actually copied.

Parameters

std::out_of_range

if pos >= size().

data

const const_pointer data()

Gets a pointer to the raw character data comprising the string, not necessarily null-terminated.

Returns

said pointer.

Returns

c_str()

empty

const inline bool empty()

Checks whether the string is empty.

Returns

True only if it is.

end

iterator end()

Returns a read/write iterator positioned at one past the last character of the string.

Returns

said iterator.

end

const const_iterator end()

Returns a read-only iterator positioned at one past the last character of the string.

Returns

said iterator.

erase

String & erase(
    size_type pos=0 ,
    size_type n=
)

Erases the given number of characters starting at the given position.

Parameters

pos

The position of the first character to erase.

n

The number of characters to erase.

Returns

a reference to this string.

Parameters

std::out_of_range

if pos is beyond the end of the string.

erase

iterator erase(
    iterator i
)

Erases the character at the given iterator's position.

Parameters

i

The iterator marking the position of the character to erase.

Returns

a new iterator marking the same position (i.e., what becomes the next character).

erase

iterator erase(
    iterator i,
    iterator j
)

Erases a range of characters [i,j).

Parameters

i

The iterator marking the first character of the range.

j

The iterator marking one past the last character of the range.

Returns

a new iterator marking the same position as i.

find

const size_type find(
    String const & s,
    size_type pos=0
)

Searches this string for the given string starting at the given position.

Parameters

s

The string to search for.

pos

The starting position within this string.

Returns

the offset of s or npos if not found.

find

const size_type find(
    std::string const & s,
    size_type pos=0
)

Searches this string for the given string starting at the given position.

Parameters

s

The string to search for.

pos

The starting position within this string.

Returns

the offset of s or npos if not found.

find

const size_type find(
    const_pointer s,
    size_type pos=0
)

Searches this string for the given string starting at the given position.

Parameters

s

The null-terminated C string to search for.

pos

The starting position within this string.

Returns

the offset of s or npos if not found.

find

const size_type find(
    const_pointer s,
    size_type pos,
    size_type s_n
)

Searches this string for the given string starting at the given position.

Parameters

s

The C string to search for.

pos

The starting position within this string.

s_n

The number of characters to compare.

Returns

the offset of s or npos if not found.

find

const size_type find(
    value_type c,
    size_type pos=0
)

Searches this string for the given character staring at the given position.

Parameters

c

The character to search for.

pos

The starting position within this string.

Returns

the offset of c or npos if not found.

find_first_not_of

const size_type find_first_not_of(
    String const & s,
    size_type pos=0
)

Searches this string for any one of the characters not in s starting at the given position.

Parameters

s

The set of characters not to search for.

pos

The starting position within this string.

Returns

the offset of a non-matching character or npos if not found.

find_first_not_of

const size_type find_first_not_of(
    std::string const & s,
    size_type pos=0
)

Searches this string for any one of the characters not in s starting at the given position.

Parameters

s

The set of characters not to search for.

pos

The starting position within this string.

Returns

the offset of a non-matching character or npos if not found.

find_first_not_of

const size_type find_first_not_of(
    const_pointer s,
    size_type pos=0
)

Searches this string for any one of the characters not in s starting at the given position.

Parameters

s

The set of characters not to search for.

pos

The starting position within this string.

Returns

the offset of a non-matching character or npos if not found.

find_first_not_of

const size_type find_first_not_of(
    const_pointer s,
    size_type pos,
    size_type s_n
)

Searches this string for any one of the first s_n characters not in s starting at the given position.

Parameters

s

The set of characters not to search for.

pos

The starting position within this string.

s_n

The number of characters of s to consider.

Returns

the offset of a non-matching character or npos if not found.

find_first_not_of

const size_type find_first_not_of(
    value_type c,
    size_type pos=0
)

Searches this string for any character except the given character starting at the given position.

Parameters

c

The character not to search for.

pos

The starting position within this string.

Returns

the offset of any character except c or npos if not found.

find_first_of

const size_type find_first_of(
    String const & s,
    size_type pos=0
)

Searches this string for any one of the characters in s starting at the given position.

Parameters

s

The set of characters to search for.

pos

The starting position within this string.

Returns

the offset of a matching character or npos if not found.

find_first_of

const size_type find_first_of(
    std::string const & s,
    size_type pos=0
)

Searches this string for any one of the characters in s starting at the given position.

Parameters

s

The set of characters to search for.

pos

The starting position within this string.

Returns

the offset of a matching character or npos if not found.

find_first_of

const size_type find_first_of(
    const_pointer s,
    size_type pos=0
)

Searches this string for any one of the characters in s starting at the given position.

Parameters

s

The set of characters to search for.

pos

The starting position within this string.

Returns

the offset of a matching character or npos if not found.

find_first_of

const size_type find_first_of(
    const_pointer s,
    size_type pos,
    size_type s_n
)

Searches this string for any one of the first s_n characters in s starting at the given position.

Parameters

s

The set of characters to search for.

pos

The starting position within this string.

s_n

The number of characters of s to consider.

Returns

the offset of a matching character or npos if not found.

find_first_of

const size_type find_first_of(
    value_type c,
    size_type pos=0
)

Searches this string for the given character starting at the given position.

Parameters

c

The character to search for.

pos

The starting position within this string.

Returns

the offset of c or npos if not found.

find_last_not_of

const size_type find_last_not_of(
    String const & s,
    size_type pos=
)

Searches this string backwards for any one of the characters not in s starting at the given position.

Parameters

s

The set of characters to not search for.

pos

The starting position within this string.

Returns

the offset of a matching character or npos if not found.

find_last_not_of

const size_type find_last_not_of(
    std::string const & s,
    size_type pos=
)

Searches this string backwards for any one of the characters not in s starting at the given position.

Parameters

s

The set of characters to not search for.

pos

The starting position within this string.

Returns

the offset of a matching character or npos if not found.

find_last_not_of

const size_type find_last_not_of(
    const_pointer s,
    size_type pos=
)

Searches this string backwards for any one of the characters not in s starting at the given position.

Parameters

s

The set of characters to not search for.

pos

The starting position within this string.

Returns

the offset of a matching character or npos if not found.

find_last_not_of

const size_type find_last_not_of(
    const_pointer s,
    size_type pos,
    size_type s_n
)

Searches this string backwards for any one of the first s_n characters not in s starting at the given position.

Parameters

s

The set of characters to not search for.

pos

The starting position within this string.

s_n

The number of characters of s to consider.

Returns

the offset of a matching character or npos if not found.

find_last_not_of

const size_type find_last_not_of(
    value_type c,
    size_type pos=
)

Searches this string backwards for any character except the given character starting at the given position.

Parameters

c

The character to search for.

pos

The starting position within this string.

Returns

the offset of any character except c or npos if not found.

find_last_of

const size_type find_last_of(
    String const & s,
    size_type pos=
)

Searches this string backwards for any one of the characters in s starting at the given position.

Parameters

s

The set of characters to search for.

pos

The starting position within this string.

Returns

the offset of a matching character or npos if not found.

find_last_of

const size_type find_last_of(
    std::string const & s,
    size_type pos=
)

Searches this string backwards for any one of the characters in s starting at the given position.

Parameters

s

The set of characters to search for.

pos

The starting position within this string.

Returns

the offset of a matching character or npos if not found.

find_last_of

const size_type find_last_of(
    const_pointer s,
    size_type pos=
)

Searches this string backwards for any one of the characters in s starting at the given position.

Parameters

s

The set of characters to search for.

pos

The starting position within this string.

Returns

the offset of a matching character or npos if not found.

find_last_of

const size_type find_last_of(
    const_pointer s,
    size_type pos,
    size_type s_n
)

Searches this string backwards for any one of the first s_n characters in s starting at the given position.

Parameters

s

The set of characters to search for.

pos

The starting position within this string.

s_n

The number of characters of s to consider.

Returns

the offset of a matching character or npos if not found.

find_last_of

const size_type find_last_of(
    value_type c,
    size_type pos=
)

Searches this string backwards for the given character starting at the given position.

Parameters

c

The character to search for.

pos

The starting position within this string.

Returns

the offset of c or npos if not found.

insert

String & insert(
    size_type pos,
    String const & s
)

Inserts the given string into this string at the given position.

Parameters

pos

The position within this string to insert at.

s

The string to insert.

Returns

this string.

insert

String & insert(
    size_type pos,
    std::string const & s
)

Inserts the given string into this string at the given position.

Parameters

pos

The position within this string to insert at.

s

The string to insert.

Returns

this string.

insert

String & insert(
    size_type pos,
    const_pointer s
)

Inserts the given string into this string at the given position.

Parameters

pos

The position within this string to insert at.

s

The null-terminated string to insert.

Returns

this string.

insert

String & insert(
    size_type pos,
    String const & s,
    size_type s_pos,
    size_type s_n
)

Inserts a substring of the given string into this string at the given position.

Parameters

pos

The position within this string to insert at.

s

The null-terminated C string to insert.

s_pos

The starting position within s.

s_n

The numer of characters of s to insert.

Returns

this string.

insert

String & insert(
    size_type pos,
    std::string const & s,
    size_type s_pos,
    size_type s_n
)

Inserts a substring of the given string into this string at the given position.

Parameters

pos

The position within this string to insert at.

s

The null-terminated C string to insert.

s_pos

The starting position within s.

s_n

The numer of characters of s to insert.

Returns

this string.

insert

String & insert(
    size_type pos,
    const_pointer s,
    size_type s_n
)

Inserts a substring of the given string into this string at the given position.

Parameters

pos

The position within this string to insert at.

s

The C string to insert.

s_n

The numer of characters of s to insert.

Returns

this string.

insert

String & insert(
    size_type pos,
    size_type n,
    value_type c
)

Inserts n copies of c into this string at the given position.

Parameters

pos

The position within this string to insert at.

n

The number of copies of c to insert.

c

The character to insert.

Returns

this string.

insert

iterator insert(
    iterator pos,
    value_type c
)

Inserts the given character into this string at the given position.

Parameters

pos

The iterator marking the position within this string to insert at.

c

The character to insert.

Returns

Returns an iterator positioned at the newly inserted character.

insert

void insert(
    iterator pos,
    size_type n,
    value_type c
)

Inserts n copies of c into this string at the given position.

Parameters

pos

The iterator marking the position within this string to insert at.

n

The number of copies of c to insert.

c

The character to insert.

length

const size_type length()

Gets the number of characters in this string.

Returns

The number of UTF-8 characters.

operator+=

inline String & operator+=(
    String const & s
)

Appends the given string to this string.

Parameters

s

The string to append.

Returns

this string.

operator+=

inline String & operator+=(
    std::string const & s
)

Appends the given std::string to this string.

Parameters

s

The string to append.

Returns

this string.

operator+=

inline String & operator+=(
    const_pointer s
)

Appends the given C string to this string.

Parameters

s

The null-terminated C string to append.

Returns

this string.

operator+=

inline String & operator+=(
    value_type c
)

Appends the given character to this string.

Parameters

c

The character to append.

Returns

this string.

operator=

String & operator=(
    String const & s
)

Assigns another string to this string.

Parameters

s

The string to assign from.

Returns

this string.

operator=

String & operator=(
    std::string const & s
)

Assigns a std::string to this string.

Parameters

s

The string to assign from.

Returns

this string.

operator=

String & operator=(
    const_pointer s
)

Assigns a C string to this string.

Parameters

s

The null-terminated C string to assign from.

Returns

this string.

operator=

String & operator=(
    value_type c
)

Assigns a character to this string.

Parameters

c

The character to assign.

Returns

this string.

operator[]

const const_reference operator[](
    size_type pos
)

References a particular character within the string.

Parameters

pos

The index of the character. The index is not bounds-checked.

Returns

said character as an r-value.

push_back

void push_back(
    value_type c
)

Appends the given character to this string.

Parameters

c

The character to append.

rbegin

Returns a read/write reverse iterator positioned at the first character of the reversed string.

Returns

said iterator.

rbegin

const const_reverse_iterator rbegin()

Returns a read-only reverse iterator positioned at the first character of the reversed string.

Returns

said iterator.

rend

Returns a read/write reverse iterator positioned at one past the last character of the reversed string.

Returns

said iterator.

rend

Returns a read-only reverse iterator positioned at one past the last character of the reversed string.

Returns

said iterator.

replace

String & replace(
    size_type pos,
    size_type n,
    String const & s
)

Replaces n characters of this string starting at the given position with the given string.

Parameters

pos

The position within this string to replace at.

n

The number of characters to replace.

s

The replacement string.

Returns

this string.

replace

String & replace(
    size_type pos,
    size_type n,
    std::string const & s
)

Replaces n characters of this string starting at the given position with the given string.

Parameters

pos

The position within this string to replace at.

n

The number of characters to replace.

s

The replacement string.

Returns

this string.

replace

String & replace(
    size_type pos,
    size_type n,
    const_pointer s
)

Replaces n characters of this string starting at the given position with the given string.

Parameters

pos

The position within this string to replace at.

n

The number of characters to replace.

s

The null-terminated replacement C string.

Returns

this string.

replace

String & replace(
    size_type pos,
    size_type n,
    String const & s,
    size_type s_pos,
    size_type s_n
)

Replaces n characters of this string starting at the given position with a substring of the given string.

Parameters

pos

The position within this string to replace at.

n

The number of characters to replace.

s

The replacement string.

s_pos

The starting position is s.

s_n

The number of characters of s to use.

Returns

this string.

replace

String & replace(
    size_type pos,
    size_type n,
    std::string const & s,
    size_type s_pos,
    size_type s_n
)

Replaces n characters of this string starting at the given position with a substring of the given string.

Parameters

pos

The position within this string to replace at.

n

The number of characters to replace.

s

The replacement string.

s_pos

The starting position is s.

s_n

The number of characters of s to use.

Returns

this string.

replace

String & replace(
    size_type pos,
    size_type n,
    const_pointer s,
    size_type s_n
)

Replaces n characters of this string starting at the given position with a substring of the given string.

Parameters

pos

The position within this string to replace at.

n

The number of characters to replace.

s

The replacement C string.

s_n

The number of characters of s to use.

Returns

this string.

replace

String & replace(
    size_type pos,
    size_type n,
    size_type c_n,
    value_type c
)

Replaces n characters of this string starting at the given position with c_n copies of c.

Parameters

pos

The position within this string to replace at.

n

The number of characters to replace.

c_n

The number of copies of to replace with.

c

The character to replace with.

Returns

this string.

replace

String & replace(
    iterator i,
    iterator j,
    String const & s
)

Replaces the range of characters [i,j) of this string with the given string.

Parameters

i

The iterator marking the first character of the range.

j

The iterator marking one past the last character of the range.

s

The replacement string.

Returns

this string.

replace

String & replace(
    iterator i,
    iterator j,
    std::string const & s
)

Replaces the range of characters [i,j) of this string with the given string.

Parameters

i

The iterator marking the first character of the range.

j

The iterator marking one past the last character of the range.

s

The replacement string.

Returns

this string.

replace

String & replace(
    iterator i,
    iterator j,
    const_pointer s
)

Replaces the range of characters [i,j) of this string with the given string.

Parameters

i

The iterator marking the first character of the range.

j

The iterator marking one past the last character of the range.

s

The null-terminated replacement C string.

Returns

this string.

replace

String & replace(
    iterator i,
    iterator j,
    const_pointer s,
    size_type s_n
)

Replaces the range of characters [i,j) of this string with a substring of the given string.

Parameters

i

The iterator marking the first character of the range.

j

The iterator marking one past the last character of the range.

s

The replacement C string.

s_n

The number of characters of s to use.

Returns

this string.

replace

String & replace(
    iterator i,
    iterator j,
    size_type n,
    value_type c
)

Replaces the range of characters [i,j) of this string with c_n copies of c.

Parameters

i

The iterator marking the first character of the range.

j

The iterator marking one past the last character of the range.

n

The number of copies of to replace with.

c

The character to replace with.

Returns

Returns this string.

replace

String & replace(
    iterator i,
    iterator j,
    iterator si,
    iterator sj
)

Replaces the range of characters [i,j) of this string with the range of characters [si,sj).

Parameters

i

The iterator marking the first character of the range.

j

The iterator marking one past the last character of the range.

si

The iterator marking the first character of the range.

sj

The iterator marking one past the last character of the range.

Returns

this string.

reserve

void reserve(
    size_type n
)

Attemts to pre-allocated enough memory to contain the given number of bytes.

Parameters

n

The number of bytes.

resize

void resize(
    size_type n,
    value_type c=()
)

Resizes the string to the given number of characters.

If the number < size(), the string will be truncated; if the number > size(), the string will be extended and the new elements will be set to c.

Parameters

n

The number of characters.

c

Characters to fill any new positions.

rfind

const size_type rfind(
    String const & s,
    size_type pos=
)

Searches this backwards string for the given string starting at the given position.

Parameters

s

The string to search for.

pos

The starting position within this string.

Returns

the offset of s or npos if not found.

rfind

const size_type rfind(
    std::string const & s,
    size_type pos=
)

Searches this backwards string for the given string starting at the given position.

Parameters

s

The string to search for.

pos

The starting position within this string.

Returns

the offset of s or npos if not found.

rfind

const size_type rfind(
    const_pointer s,
    size_type pos=
)

Searches this backwards string for the given string starting at the given position.

Parameters

s

The string to search for.

pos

The starting position within this string.

Returns

the offset of s or npos if not found.

rfind

const size_type rfind(
    const_pointer s,
    size_type pos,
    size_type s_n
)

Searches this string backwards for the given string starting at the given position.

Parameters

s

The C string to search for.

pos

The starting position within this string.

s_n

The number of characters to compare.

Returns

the offset of s or npos if not found.

rfind

const size_type rfind(
    value_type c,
    size_type pos=
)

Searches this string backwards for the given character staring at the given position.

Parameters

c

The character to search for.

pos

The starting position within this string.

Returns

the offset of c or npos if not found.

size

const inline size_type size()

Gets the number of characters in this string.

(This is a synonym for length().)

Returns

The number of UTF-8 characters.

str

const std::string str()

Gets a std::string equivalent of this string.

(There intentionally is no operator std::string() const since its convenient use would mask the expense of creating a new std::string.) This function is an extension to the std::string API.

Returns

said std::string.

String

 String()

Constructs an empty string.

String

 String(
    String const & s
)

Copy constructs a new string from an existing string.

Parameters

s

The string to copy from.

String

 String(
    std::string const & s
)

Constructs a new string from an existing std::string.

Parameters

s

The string to copy from.

String

 String(
    const_pointer s
)

Constructs a string from the given C string.

Parameters

s

The null-terminated C string.

String

 String(
    String const & s,
    size_type pos,
    size_type n=
)

Copy constructs a new string from a substring of an existing string.

Parameters

s

The string to copy from.

pos

The position of the first character to copy.

n

The number of characters to copy.

String

 String(
    std::string const & s,
    size_type pos,
    size_type n=
)

Constructs a new string from a substring of an existing std::string.

Parameters

s

The string to copy from.

pos

The starting position of the substring.

n

The number of characters of the substring.

String

 String(
    const_pointer s,
    size_type n
)

Constructs a string from the given C string.

Parameters

s

The C string.

n

The number of characters to copy.

String

 String(
    size_type n,
    value_type c
)

Constructs a new string as n copies of c.

Parameters

n

The number of times to repeat the character.

c

The character to repeat.

String

 String(
    const_iterator i,
    const_iterator j
)

Constructs a string from a range of characters [i,j).

Parameters

i

The iterator marking the first character of the range.

j

The iterator marking one past the last character of the range.

substr

const String substr(
    size_type pos=0 ,
    size_type n=
)

Creates a new string that is a substring of this string.

Parameters

pos

The position in this string for first character of the new string.

n

The number of characters to extract.

Returns

the new string.

Parameters

std::out_of_range

if pos >= size().

swap

void swap(
    String & s
)

Swaps the contents of this string with another.

This is an O(1) operation.

Parameters

s

The string to swap with.

~String

 ~String()

Destructs this string.

Private Functions

operator=

String & operator=(
    zstring_ptr 
)

String

 String(
    zstring_ptr 
)

Private Static Functions

size_check

static void size_check()
blog comments powered by Disqus