libUTL++
utl::String Class Reference

Character string. More...

#include <String.h>

Inheritance diagram for utl::String:

Public Member Functions

 String (const char *s, bool owner=true, bool duplicate=true, bool caseSensitive=true)
 Constructor. More...
 
 String (size_t size)
 Constructor. More...
 
 String (char c)
 Constructor. More...
 
virtual int compare (const Object &rhs) const
 Compare with another object. More...
 
virtual void copy (const Object &rhs)
 Copy another instance. More...
 
virtual void steal (Object &rhs)
 "Steal" the internal representation from another instance. More...
 
virtual size_t hash (size_t size) const
 Get the hash code for the object. More...
 
virtual void serialize (Stream &stream, uint_t io, uint_t mode=ser_default)
 Serialize to or from a stream. More...
 
virtual size_t innerAllocatedSize () const
 Get the "inner" allocated size. More...
 
virtual String toString () const
 Return a string representation of self. More...
 
Flags
bool isOwner () const
 Get the ownership flag. More...
 
void setOwner (bool owner)
 Set the ownership flag (without doing anything else). More...
 
bool isCaseSensitive () const
 Get the case-sensitive flag. More...
 
void setCaseSensitive (bool caseSensitive)
 Set the case-sensitive flag. More...
 
bool isMarked () const
 Get the marked flag. More...
 
void setMarked (bool marked=true)
 Set the marked flag. More...
 
Comparison
int compareSubstring (size_t begin, const String &rhs, size_t n)
 Compare the given string against a substring of self. More...
 
int compareSubstring (size_t begin, const char *rhs, size_t len)
 Compare the given string against a substring of self. More...
 
int comparePrefix (const String &rhs) const
 Compare the given string against the beginning of self. More...
 
int comparePrefix (const char *rhs) const
 Compare the given string against the beginning of self. More...
 
int compareSuffix (const String &rhs) const
 Compare the given string against the end of self. More...
 
int compareSuffix (const char *rhs) const
 Compare the given string against the end of self. More...
 
int strcmp (const char *lhs, const char *rhs) const
 Compare two strings (case sensitive comparison iff isCaseSensitive()). More...
 
std::function< int(const char *, const char *)> strcmp () const
 Get the string comparison function (strcmp or strcasecmp). More...
 
int strncmp (const char *lhs, const char *rhs, size_t n) const
 Compare (up to) the first n bytes of two strings (case sensitive iff isCaseSensitive()). More...
 
std::function< int(const char *, const char *, size_t)> strncmp () const
 Get the length-limited string comparison function (strncmp or strncasecmp). More...
 
Read-only (const) Operations
String backslashEscaped (const char *specials) const
 Backslash-escape a string. More...
 
String backslashEscaped (const String &specials) const
 Backslash-escape a string. More...
 
String backslashUnescaped () const
 Backslash-unescape a string. More...
 
bool empty () const
 Is the string empty?
 
size_t find (const String &str, size_t begin=0) const
 Find the first instance of the given string in self. More...
 
size_t find (const char *str, size_t begin=0) const
 Find the first instance of the given string in self. More...
 
size_t find (char c, size_t begin=0) const
 Find the first instance of the given character in self. More...
 
size_t findBM (const String &str, size_t begin=0) const
 Use Boyer-Moore algorithm to find the first instance of the given string. More...
 
size_t findBM (const char *str, size_t begin=0) const
 Use Boyer-Moore algorithm to find the first instance of the given string. More...
 
char firstChar () const
 Get the first character in the string (nul if empty). More...
 
char lastChar () const
 Get the last character in the string (nul if empty). More...
 
const char * get () const
 Get const char*. More...
 
size_t length () const
 Get the length of the string. More...
 
void lengthInvalidate () const
 Invalidate the cached length of the string. More...
 
String prefix (size_t n) const
 Get the first n characters of the string. More...
 
size_t size () const
 Get the size of the allocated character array. More...
 
String subString (size_t begin, size_t len=size_t_max) const
 Get a substring. More...
 
String suffix (size_t n) const
 Get the last n characters of the string. More...
 
String reversed () const
 Get a copy of self with the characters in reverse order. More...
 
String nextToken (size_t &idx, char delim=' ', bool processQuotes=false) const
 Return the next token in a delimited string. More...
 
Modification (and non-const)
Stringclear ()
 Reset to empty string. More...
 
Stringexcise ()
 Like clear(), but de-allocate the array instead of writing a nul character at position 0.
 
char * get ()
 Get char*. More...
 
char get (size_t i) const
 Get the specified character. More...
 
StringassertOwner ()
 Make sure self has its own copy of the string. More...
 
void assertOwner (size_t size, size_t increment=8)
 Make sure self has its own copy of the string. More...
 
void economize ()
 Make sure no extra space is allocated. More...
 
void reserve (size_t size, size_t increment=8)
 Grow to the specified size. More...
 
Stringappend (char c)
 Append the given character. More...
 
Stringappend (const String &s)
 Append the given string. More...
 
Stringappend (const char *s)
 Append the given string. More...
 
Stringappend (const char *s, size_t len)
 Append the given string. More...
 
String chop (size_t begin, size_t len=size_t_max)
 Chop out and return a sub-string. More...
 
void remove (size_t begin, size_t len=size_t_max)
 Remove a sub-string (like chop(), but doesn't return the removed sub-string). More...
 
Stringreplace (const String &lhs, const String &rhs)
 Replace all instances of lhs with rhs. More...
 
Stringreplace (const char *lhs, const char *rhs)
 Replace all instances of lhs with rhs. More...
 
Stringreplace (const char *lhs, const String &rhs)
 Replace all instances of lhs with rhs. More...
 
Stringreplace (const String &lhs, const char *rhs)
 Replace all instances of lhs with rhs. More...
 
Stringreplace (size_t begin, size_t len, const String &str)
 Replace a substring with a given string. More...
 
Stringreverse ()
 Reverse the ordering of the characters. More...
 
void set (const char *s, bool owner=true, bool duplicate=true, size_t length=size_t_max)
 Set a new string. More...
 
StringtoLower (size_t begin=0, size_t len=size_t_max)
 Convert characters to lowercase. More...
 
StringtoUpper (size_t begin=0, size_t len=size_t_max)
 Convert characters to uppercase. More...
 
StringpadBegin (size_t len, char c=' ')
 Pad with spaces (or another character) at the beginning. More...
 
StringpadEnd (size_t len, char c=' ')
 Pad with spaces (or another character) at the end. More...
 
Stringtrim ()
 Trim whitespace from the beginning and end. More...
 
StringtrimBegin ()
 Trim whitespace from the beginning. More...
 
StringtrimEnd ()
 Trim whitespace from the end. More...
 
Operators
String operator+ (char c) const
 Get a copy of self with the given character appended. More...
 
String operator+ (const char *str) const
 Get a copy of self with the given string appended. More...
 
String operator+ (const String &rhs) const
 Get a copy of self with the given string appended. More...
 
Stringoperator+= (char c)
 Append the given character to self. More...
 
Stringoperator+= (const char *rhs)
 Append the given string to self. More...
 
Stringoperator+= (const String &rhs)
 Append the given string to self. More...
 
Stringoperator= (const char *str)
 Make self equal to a copy of the given character array. More...
 
Stringoperator= (char c)
 Make self equal to the given character. More...
 
char & operator[] (size_t i)
 Array access operator. More...
 
const char & operator[] (size_t i) const
 Array access operator. More...
 
 operator char * ()
 Conversion to char*. More...
 
 operator const char * ()
 Conversion to const char*. More...
 
 operator const char * () const
 Conversion to const char*. More...
 
 operator void * ()
 Conversion to void*. More...
 
 operator const void * ()
 Conversion to const void*. More...
 
 operator const void * () const
 Conversion to const void*. More...
 
bool operator< (const Object &rhs) const
 
bool operator<= (const Object &rhs) const
 
bool operator> (const Object &rhs) const
 
bool operator>= (const Object &rhs) const
 
bool operator== (const Object &rhs) const
 
bool operator!= (const Object &rhs) const
 
bool operator< (const String &rhs) const
 
bool operator<= (const String &rhs) const
 
bool operator> (const String &rhs) const
 
bool operator>= (const String &rhs) const
 
bool operator== (const String &rhs) const
 
bool operator!= (const String &rhs) const
 
- Public Member Functions inherited from utl::Object
void clear ()
 Revert to initial state. More...
 
virtual void vclone (const Object &rhs)
 Make an exact copy of another instance. More...
 
virtual void dump (Stream &os, uint_t level=uint_t_max) const
 Dump a human-readable representation of self to the given output stream. More...
 
void dumpWithClassName (Stream &os, uint_t indent=4, uint_t level=uint_t_max) const
 Front-end for dump() that prints the object's class name. More...
 
virtual const ObjectgetKey () const
 Get the key for this object. More...
 
bool hasKey () const
 Determine whether or not the object has a key. More...
 
virtual const ObjectgetProxiedObject () const
 Get the proxied object (= self if none). More...
 
virtual ObjectgetProxiedObject ()
 Get the proxied object (= self if none). More...
 
bool _isA (const RunTimeClass *runTimeClass) const
 Determine whether self's class is a descendent of the given class. More...
 
 operator String () const
 Conversion to String. More...
 
size_t allocatedSize () const
 Get the total allocated size of this object. More...
 
virtual void addOwnedIt (const class FwdIt *it) const
 Notify self that it owns the given iterator. More...
 
virtual void removeOwnedIt (const class FwdIt *it) const
 Notify self that the given owned iterator has been destroyed. More...
 
bool operator< (const Object &rhs) const
 Less-than operator. More...
 
bool operator<= (const Object &rhs) const
 Less-than-or-equal-to operator. More...
 
bool operator> (const Object &rhs) const
 Greater-than operator. More...
 
bool operator>= (const Object &rhs) const
 Greater-than-or-equal-to operator. More...
 
bool operator== (const Object &rhs) const
 Equal-to operator. More...
 
bool operator!= (const Object &rhs) const
 Unequal-to operator. More...
 
void serializeIn (Stream &is, uint_t mode=ser_default)
 Serialize from an input stream. More...
 
void serializeOut (Stream &os, uint_t mode=ser_default) const
 Serialize to an output stream. More...
 
void serializeOutBoxed (Stream &os, uint_t mode=ser_default) const
 Serialize a boxed object to an output stream. More...
 
- Public Member Functions inherited from utl::FlagsMI
 FlagsMI ()
 Constructor. More...
 
virtual ~FlagsMI ()
 Destructor. More...
 
void copyFlags (const FlagsMI &rhs)
 Copy the given flags. More...
 
void copyFlags (const FlagsMI &rhs, uint_t lsb, uint_t msb)
 Copy (some of) the given flags. More...
 
void copyFlags (uint64_t flags, uint_t lsb, uint_t msb)
 Copy (some of) the given flags. More...
 
bool getFlag (uint_t flagNum) const
 Get a user-defined flag. More...
 
void setFlag (uint_t flagNum, bool val)
 Set a user-defined flag. More...
 
uint64_t getFlagsNumber (uint64_t mask, uint64_t shift=0)
 Get a multi-bit value in the flags data (which is stored as one 64-bit integer). More...
 
void setFlagsNumber (uint64_t mask, uint64_t shift, uint64_t num)
 Set a multi-bit value in the flags data (which is stored as one 64-bit integer). More...
 
uint64_t getFlags () const
 Get the flags. More...
 
void setFlags (uint64_t flags)
 Set the flags. More...
 

Static Public Member Functions

Static Methods
static String repeat (char c, size_t num)
 Return a string consisting of a repeated character. More...
 
static String spaces (size_t num)
 Return a string consisting of the given number of spaces. More...
 
- Static Public Member Functions inherited from utl::Object
static ObjectserializeInNullable (Stream &is, uint_t mode=ser_default)
 Serialize a nullptr-able object from an input stream. More...
 
static void serializeOutNullable (const Object *object, Stream &os, uint_t mode=ser_default)
 Serialize a nullptr-able object to an output stream. More...
 
static void serializeNullable (Object *&object, Stream &stream, uint_t io, uint_t mode=ser_default)
 Serialize a nullptr-able object to or from a stream. More...
 
static ObjectserializeInBoxed (Stream &is, uint_t mode=ser_default)
 Serialize a boxed object from an input stream. More...
 
static void serializeBoxed (Object *&object, Stream &stream, uint_t io, uint_t mode=ser_default)
 Serialize a boxed object to or from a stream. More...
 

Detailed Description

Character string.

A string is a nul-terminated array of characters.

Attributes

  • owner flag : True iff self owns the underlying string.
  • case-sensitive flag : When two strings are compared, the comparison will be case-sensitive iff both strings have the case-sensitive flag asserted.
Author
Adam McKee

Definition at line 31 of file String.h.

Constructor & Destructor Documentation

◆ String() [1/3]

utl::String::String ( const char *  s,
bool  owner = true,
bool  duplicate = true,
bool  caseSensitive = true 
)

Constructor.

Parameters
scharacter array
owner(optional : true) ownership flag
duplicate(optional : true) make a copy? (implies ownership)
caseSensitive(optional : true) case sensitivity flag

◆ String() [2/3]

utl::String::String ( size_t  size)

Constructor.

Parameters
sizeinitial size of character array

◆ String() [3/3]

utl::String::String ( char  c)
inline

Constructor.

Parameters
ccharacter

Definition at line 55 of file String.h.

References utl::compare(), utl::copy(), utl::ser_default, utl::serialize(), utl::size_t_max, and utl::toString().

Member Function Documentation

◆ compare()

virtual int utl::String::compare ( const Object rhs) const
virtual

Compare with another object.

If no overridden version succeeds in doing the comparison, then an attempt will be made to re-start the comparison process using one or both of the objects' keys. Usually, an override of compare() should call the superclass's compare() if it doesn't know how to compare itself with the rhs object.

See also
getKey
Returns
< 0 if self < rhs, 0 if self = rhs, > 0 if self > rhs
Parameters
rhsobject to compare with

Reimplemented from utl::Object.

Reimplemented in utl::Regex, utl::FileSpec, and utl::Token.

◆ copy()

virtual void utl::String::copy ( const Object rhs)
virtual

Copy another instance.

When you override copy(), you should usually call the superclass's copy().

Parameters
rhsobject to copy

Reimplemented from utl::Object.

Reimplemented in utl::Regex, utl::FileSpec, and utl::Token.

◆ steal()

virtual void utl::String::steal ( Object rhs)
virtual

"Steal" the internal representation from another instance.

The default implementation just calls vclone(), so you have to override this if you want a "move" capability.

Reimplemented from utl::Object.

Reimplemented in utl::Regex, utl::FileSpec, and utl::Token.

◆ hash()

virtual size_t utl::String::hash ( size_t  size) const
virtual

Get the hash code for the object.

The default implementation will return the hash code of the object's key, or abort if the object has none.

Returns
the hash code
Parameters
sizehash table size

Reimplemented from utl::Object.

◆ serialize()

virtual void utl::String::serialize ( Stream stream,
uint_t  io,
uint_t  mode = ser_default 
)
virtual

Serialize to or from a stream.

This is the only virtual method for serialization. You must override this in any class that has data to be serialized, and ensure that the superclass's serialize() gets called.

Parameters
streamstream to serialize from/to
iosee utl::io_t
modesee utl::serialize_t

Reimplemented from utl::Object.

Reimplemented in utl::FileSpec.

◆ innerAllocatedSize()

virtual size_t utl::String::innerAllocatedSize ( ) const
virtual

Get the "inner" allocated size.

Reimplemented from utl::Object.

◆ toString()

virtual String utl::String::toString ( ) const
virtual

Return a string representation of self.

Reimplemented from utl::Object.

Referenced by utl::TCollection< Vertex >::toString(), and utl::ObjectSpan< Time, Duration >::toString().

◆ isOwner()

bool utl::String::isOwner ( ) const
inline

Get the ownership flag.

Definition at line 82 of file String.h.

◆ setOwner()

void utl::String::setOwner ( bool  owner)
inline

Set the ownership flag (without doing anything else).

Definition at line 89 of file String.h.

◆ isCaseSensitive()

bool utl::String::isCaseSensitive ( ) const
inline

Get the case-sensitive flag.

Definition at line 103 of file String.h.

Referenced by operator const void *().

◆ setCaseSensitive()

void utl::String::setCaseSensitive ( bool  caseSensitive)
inline

Set the case-sensitive flag.

Definition at line 110 of file String.h.

◆ isMarked()

bool utl::String::isMarked ( ) const
inline

Get the marked flag.

Definition at line 117 of file String.h.

◆ setMarked()

void utl::String::setMarked ( bool  marked = true)
inline

Set the marked flag.

Definition at line 124 of file String.h.

◆ compareSubstring() [1/2]

int utl::String::compareSubstring ( size_t  begin,
const String rhs,
size_t  n 
)

Compare the given string against a substring of self.

◆ compareSubstring() [2/2]

int utl::String::compareSubstring ( size_t  begin,
const char *  rhs,
size_t  len 
)
inline

Compare the given string against a substring of self.

Definition at line 137 of file String.h.

◆ comparePrefix() [1/2]

int utl::String::comparePrefix ( const String rhs) const

Compare the given string against the beginning of self.

◆ comparePrefix() [2/2]

int utl::String::comparePrefix ( const char *  rhs) const
inline

Compare the given string against the beginning of self.

Definition at line 147 of file String.h.

◆ compareSuffix() [1/2]

int utl::String::compareSuffix ( const String rhs) const

Compare the given string against the end of self.

◆ compareSuffix() [2/2]

int utl::String::compareSuffix ( const char *  rhs) const
inline

Compare the given string against the end of self.

Definition at line 157 of file String.h.

◆ strcmp() [1/2]

int utl::String::strcmp ( const char *  lhs,
const char *  rhs 
) const
inline

Compare two strings (case sensitive comparison iff isCaseSensitive()).

Definition at line 164 of file String.h.

Referenced by operator const void *().

◆ strcmp() [2/2]

std::function<int(const char*, const char*)> utl::String::strcmp ( ) const
inline

Get the string comparison function (strcmp or strcasecmp).

Definition at line 182 of file String.h.

◆ strncmp() [1/2]

int utl::String::strncmp ( const char *  lhs,
const char *  rhs,
size_t  n 
) const
inline

Compare (up to) the first n bytes of two strings (case sensitive iff isCaseSensitive()).

Definition at line 189 of file String.h.

◆ strncmp() [2/2]

std::function<int(const char*, const char*, size_t)> utl::String::strncmp ( ) const
inline

Get the length-limited string comparison function (strncmp or strncasecmp).

Definition at line 196 of file String.h.

◆ backslashEscaped() [1/2]

String utl::String::backslashEscaped ( const char *  specials) const
inline

Backslash-escape a string.

Definition at line 206 of file String.h.

◆ backslashEscaped() [2/2]

String utl::String::backslashEscaped ( const String specials) const

Backslash-escape a string.

◆ backslashUnescaped()

String utl::String::backslashUnescaped ( ) const

Backslash-unescape a string.

◆ find() [1/3]

size_t utl::String::find ( const String str,
size_t  begin = 0 
) const

Find the first instance of the given string in self.

Returns
index of match (size_t_max if no match)
Parameters
strsearch string
beginsearch start index

◆ find() [2/3]

size_t utl::String::find ( const char *  str,
size_t  begin = 0 
) const
inline

Find the first instance of the given string in self.

Returns
index of match (size_t_max if no match)
Parameters
strsearch string
beginsearch start index

Definition at line 239 of file String.h.

◆ find() [3/3]

size_t utl::String::find ( char  c,
size_t  begin = 0 
) const

Find the first instance of the given character in self.

Returns
index of match (size_t_max if no match)
Parameters
csearch character
beginsearch start index

◆ findBM() [1/2]

size_t utl::String::findBM ( const String str,
size_t  begin = 0 
) const

Use Boyer-Moore algorithm to find the first instance of the given string.

Returns
index of match (size_t_max if no match)
See also
BoyerMooreSearch

◆ findBM() [2/2]

size_t utl::String::findBM ( const char *  str,
size_t  begin = 0 
) const
inline

Use Boyer-Moore algorithm to find the first instance of the given string.

Returns
index of match (size_t_max if no match)
See also
BoyerMooreSearch

Definition at line 265 of file String.h.

◆ firstChar()

char utl::String::firstChar ( ) const
inline

Get the first character in the string (nul if empty).

Definition at line 272 of file String.h.

◆ lastChar()

char utl::String::lastChar ( ) const
inline

Get the last character in the string (nul if empty).

Definition at line 279 of file String.h.

◆ get() [1/3]

const char* utl::String::get ( ) const
inline

Get const char*.

Definition at line 288 of file String.h.

Referenced by operator const void *().

◆ length()

size_t utl::String::length ( ) const
inline

Get the length of the string.

Definition at line 295 of file String.h.

References ASSERTD, and utl::size_t_max.

Referenced by append(), operator const void *(), and operator+().

◆ lengthInvalidate()

void utl::String::lengthInvalidate ( ) const
inline

Invalidate the cached length of the string.

Definition at line 304 of file String.h.

References utl::size_t_max.

◆ prefix()

String utl::String::prefix ( size_t  n) const
inline

Get the first n characters of the string.

Returns
prefix string

Definition at line 314 of file String.h.

◆ size()

size_t utl::String::size ( ) const
inline

Get the size of the allocated character array.

Definition at line 321 of file String.h.

References utl::size_t_max.

◆ subString()

String utl::String::subString ( size_t  begin,
size_t  len = size_t_max 
) const

Get a substring.

Returns
specified substring
Parameters
beginfirst character of substring
lenlength of substring

◆ suffix()

String utl::String::suffix ( size_t  n) const
inline

Get the last n characters of the string.

Returns
suffix string

Definition at line 339 of file String.h.

◆ reversed()

String utl::String::reversed ( ) const

Get a copy of self with the characters in reverse order.

◆ nextToken()

String utl::String::nextToken ( size_t &  idx,
char  delim = ' ',
bool  processQuotes = false 
) const

Return the next token in a delimited string.

Parameters
idxstarting position
delimdelimiter
processQuotes(optional : false) process quoted strings?

◆ clear()

String& utl::String::clear ( )
inline

Reset to empty string.

Definition at line 362 of file String.h.

◆ get() [2/3]

char* utl::String::get ( )
inline

Get char*.

Definition at line 379 of file String.h.

◆ get() [3/3]

char utl::String::get ( size_t  i) const
inline

Get the specified character.

Definition at line 386 of file String.h.

References ASSERTD.

◆ assertOwner() [1/2]

String& utl::String::assertOwner ( )
inline

Make sure self has its own copy of the string.

Definition at line 394 of file String.h.

◆ assertOwner() [2/2]

void utl::String::assertOwner ( size_t  size,
size_t  increment = 8 
)
inline

Make sure self has its own copy of the string.

Parameters
sizethe required minimum size
incrementgrowth increment (if increment = size_t_max, make size a power of 2)

Definition at line 406 of file String.h.

◆ economize()

void utl::String::economize ( )

Make sure no extra space is allocated.

◆ reserve()

void utl::String::reserve ( size_t  size,
size_t  increment = 8 
)
inline

Grow to the specified size.

Parameters
sizethe required minimum size
incrementgrowth increment (if increment = size_t_max, make size a power of 2)

Definition at line 420 of file String.h.

◆ append() [1/4]

String& utl::String::append ( char  c)

Append the given character.

Referenced by operator const void *(), and operator+().

◆ append() [2/4]

String& utl::String::append ( const String s)
inline

Append the given string.

Definition at line 430 of file String.h.

References length().

◆ append() [3/4]

String& utl::String::append ( const char *  s)
inline

Append the given string.

Definition at line 437 of file String.h.

References ASSERTD, and utl::size_t_max.

◆ append() [4/4]

String& utl::String::append ( const char *  s,
size_t  len 
)

Append the given string.

Parameters
saddress of first character to append
lennumber of characters to append

◆ chop()

String utl::String::chop ( size_t  begin,
size_t  len = size_t_max 
)

Chop out and return a sub-string.

Returns
chopped out portion of self
Parameters
beginindex of first character to chop out
lennumber of characters to chop out

◆ remove()

void utl::String::remove ( size_t  begin,
size_t  len = size_t_max 
)

Remove a sub-string (like chop(), but doesn't return the removed sub-string).

Parameters
beginindex of first character to chop out
lennumber of characters to chop out

◆ replace() [1/5]

String& utl::String::replace ( const String lhs,
const String rhs 
)

Replace all instances of lhs with rhs.

◆ replace() [2/5]

String& utl::String::replace ( const char *  lhs,
const char *  rhs 
)
inline

Replace all instances of lhs with rhs.

Definition at line 470 of file String.h.

◆ replace() [3/5]

String& utl::String::replace ( const char *  lhs,
const String rhs 
)
inline

Replace all instances of lhs with rhs.

Definition at line 477 of file String.h.

◆ replace() [4/5]

String& utl::String::replace ( const String lhs,
const char *  rhs 
)
inline

Replace all instances of lhs with rhs.

Definition at line 484 of file String.h.

References utl::reverse(), and utl::size_t_max.

◆ replace() [5/5]

String& utl::String::replace ( size_t  begin,
size_t  len,
const String str 
)

Replace a substring with a given string.

Returns
reference to self
Parameters
beginfirst character of substring to replace
lenlength of substring to replace
strstring that will replace specified substring

◆ reverse()

String& utl::String::reverse ( )

Reverse the ordering of the characters.

◆ set()

void utl::String::set ( const char *  s,
bool  owner = true,
bool  duplicate = true,
size_t  length = size_t_max 
)

Set a new string.

Parameters
scharacter array
owner(optional : true) ownership flag
duplicate(optional : true) make a copy? (implies ownership)
length(optional) provide length of string

◆ toLower()

String& utl::String::toLower ( size_t  begin = 0,
size_t  len = size_t_max 
)

Convert characters to lowercase.

Returns
reference to self
Parameters
begincharacter to convert
lenlength of substring to convert

◆ toUpper()

String& utl::String::toUpper ( size_t  begin = 0,
size_t  len = size_t_max 
)

Convert characters to uppercase.

Returns
reference to self
Parameters
begincharacter to convert
lenlength of substring to convert

◆ padBegin()

String& utl::String::padBegin ( size_t  len,
char  c = ' ' 
)

Pad with spaces (or another character) at the beginning.

Returns
reference to self
Parameters
lenpadding length
cpadding character

◆ padEnd()

String& utl::String::padEnd ( size_t  len,
char  c = ' ' 
)

Pad with spaces (or another character) at the end.

Returns
reference to self
Parameters
lenpadding length
cpadding character

◆ trim()

String& utl::String::trim ( )

Trim whitespace from the beginning and end.

◆ trimBegin()

String& utl::String::trimBegin ( )

Trim whitespace from the beginning.

◆ trimEnd()

String& utl::String::trimEnd ( )

Trim whitespace from the end.

◆ repeat()

static String utl::String::repeat ( char  c,
size_t  num 
)
static

Return a string consisting of a repeated character.

Returns
character c repeated num times
Parameters
ccharacter to repeat
numnumber of repetitions

◆ spaces()

static String utl::String::spaces ( size_t  num)
static

Return a string consisting of the given number of spaces.

◆ operator+() [1/3]

String utl::String::operator+ ( char  c) const
inline

Get a copy of self with the given character appended.

Definition at line 569 of file String.h.

References append().

◆ operator+() [2/3]

String utl::String::operator+ ( const char *  str) const
inline

Get a copy of self with the given string appended.

Definition at line 578 of file String.h.

References ASSERTD.

◆ operator+() [3/3]

String utl::String::operator+ ( const String rhs) const
inline

Get a copy of self with the given string appended.

Definition at line 585 of file String.h.

References length().

◆ operator+=() [1/3]

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

Append the given character to self.

Definition at line 594 of file String.h.

◆ operator+=() [2/3]

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

Append the given string to self.

Definition at line 600 of file String.h.

◆ operator+=() [3/3]

String& utl::String::operator+= ( const String rhs)
inline

Append the given string to self.

Definition at line 606 of file String.h.

◆ operator=() [1/2]

String& utl::String::operator= ( const char *  str)
inline

Make self equal to a copy of the given character array.

Definition at line 612 of file String.h.

◆ operator=() [2/2]

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

Make self equal to the given character.

Definition at line 619 of file String.h.

◆ operator[]() [1/2]

char& utl::String::operator[] ( size_t  i)
inline

Array access operator.

Definition at line 627 of file String.h.

References ASSERTD.

◆ operator[]() [2/2]

const char& utl::String::operator[] ( size_t  i) const
inline

Array access operator.

Definition at line 634 of file String.h.

References ASSERTD.

◆ operator char *()

utl::String::operator char * ( )
inline

Conversion to char*.

Definition at line 641 of file String.h.

◆ operator const char *() [1/2]

utl::String::operator const char * ( )
inline

Conversion to const char*.

Definition at line 647 of file String.h.

◆ operator const char *() [2/2]

utl::String::operator const char * ( ) const
inline

Conversion to const char*.

Definition at line 653 of file String.h.

◆ operator void *()

utl::String::operator void * ( )
inline

Conversion to void*.

Definition at line 659 of file String.h.

◆ operator const void *() [1/2]

utl::String::operator const void * ( )
inline

Conversion to const void*.

Definition at line 665 of file String.h.

◆ operator const void *() [2/2]

utl::String::operator const void * ( ) const
inline

Conversion to const void*.

Definition at line 671 of file String.h.

References append(), ASSERT, ASSERTD, utl::compare(), utl::deInit(), utl::emptyString, get(), utl::init(), isCaseSensitive(), length(), utl::size_t_max, and strcmp().


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