ScummVM API documentation
Common::BaseString< T > Class Template Reference

Public Types

typedef T value_type
 
typedef T * iterator
 
typedef const T * const_iterator
 

Public Member Functions

constexpr BaseString ()
 
 BaseString (const BaseString &str)
 
 BaseString (BaseString &&str)
 
 BaseString (const value_type *str)
 
 BaseString (const value_type *str, uint32 len)
 
 BaseString (const value_type *beginP, const value_type *endP)
 
bool operator== (const BaseString &x) const
 
bool operator== (const value_type *x) const
 
bool operator!= (const BaseString &x) const
 
bool operator!= (const value_type *x) const
 
bool operator< (const BaseString &x) const
 
bool operator< (const value_type *x) const
 
bool operator<= (const BaseString &x) const
 
bool operator<= (const value_type *x) const
 
bool operator> (const BaseString &x) const
 
bool operator> (const value_type *x) const
 
bool operator>= (const BaseString &x) const
 
bool operator>= (const value_type *x) const
 
bool equals (const BaseString &x) const
 
bool equals (const value_type *x) const
 
bool equalsC (const char *x) const
 
int compareTo (const BaseString &x) const
 
int compareTo (const value_type *x) const
 
int compareToC (const char *x) const
 
void setChar (value_type c, uint32 p)
 
void deleteChar (uint32 p)
 
void deleteLastChar ()
 
void erase (uint32 p, uint32 len=npos)
 
iterator erase (iterator it)
 
void chop (uint32 len=1)
 
void clear ()
 
iterator begin ()
 
iterator end ()
 
const_iterator begin () const
 
const_iterator end () const
 
const value_type * c_str () const
 
uint size () const
 
bool empty () const
 
value_type firstChar () const
 
value_type lastChar () const
 
value_type operator[] (int idx) const
 
bool contains (const BaseString &otherString) const
 
bool contains (value_type x) const
 
void insertChar (value_type c, uint32 p)
 
void insertString (const value_type *s, uint32 p)
 
void insertString (const BaseString &s, uint32 p)
 
uint32 find (value_type x, uint32 pos=0) const
 
size_t find (const value_type *s, uint32 pos=0) const
 
uint32 find (const BaseString &str, uint32 pos=0) const
 
size_t rfind (const value_type *s) const
 
size_t rfind (const BaseString &s) const
 
size_t rfind (value_type c, size_t pos=npos) const
 
size_t findFirstOf (value_type c, size_t pos=0) const
 
size_t findFirstOf (const value_type *chars, size_t pos=0) const
 
size_t findFirstOf (const BaseString &chars, size_t pos=0) const
 
size_t findLastOf (value_type c, size_t pos=npos) const
 
size_t findLastOf (const value_type *chars, size_t pos=npos) const
 
size_t findLastOf (const BaseString &chars, size_t pos=npos) const
 
size_t findFirstNotOf (value_type c, size_t pos=0) const
 
size_t findFirstNotOf (const value_type *chars, size_t pos=0) const
 
size_t findFirstNotOf (const BaseString &chars, size_t pos=0) const
 
size_t findLastNotOf (value_type c) const
 
size_t findLastNotOf (const value_type *chars) const
 
size_t findLastNotOf (const BaseString &chars) const
 
void replace (value_type from, value_type to)
 
void append (const value_type *begin, const value_type *end)
 
void wordWrap (const uint32 maxLength)
 
uint64 asUint64 () const
 
uint64 asUint64Ext () const
 
void toLowercase ()
 
void toUppercase ()
 
void trim ()
 
uint hash () const
 
void replace (uint32 pos, uint32 count, const BaseString &str)
 
void replace (uint32 pos, uint32 count, const value_type *str)
 
void replace (iterator begin, iterator end, const BaseString &str)
 
void replace (iterator begin, iterator end, const value_type *str)
 
void replace (uint32 posOri, uint32 countOri, const BaseString &str, uint32 posDest, uint32 countDest)
 
void replace (uint32 posOri, uint32 countOri, const value_type *str, uint32 posDest, uint32 countDest)
 

Static Public Member Functions

static void releaseMemoryPoolMutex ()
 

Static Public Attributes

static const uint32 npos = 0xFFFFFFFF
 

Protected Member Functions

bool isStorageIntern () const
 
void makeUnique ()
 
void ensureCapacity (uint32 new_size, bool keep_old)
 
void incRefCount () const
 
void decRefCount (int *oldRefCount)
 
void initWithValueTypeStr (const value_type *str, uint32 len)
 
void assignInsert (const value_type *str, uint32 p)
 
void assignInsert (value_type c, uint32 p)
 
void assignInsert (const BaseString &str, uint32 p)
 
void assignAppend (const value_type *str)
 
void assignAppend (value_type c)
 
void assignAppend (const BaseString &str)
 
void assign (const BaseString &str)
 
void assign (BaseString &&str)
 
void assign (value_type c)
 
void assign (const value_type *str)
 
bool pointerInOwnBuffer (const value_type *str) const
 
uint getUnsignedValue (uint pos) const
 
void toCase (int(*caseChangeFunc)(int))
 

Static Protected Member Functions

static uint32 cStrLen (const value_type *str)
 
static const value_type * cMemChr (const value_type *ptr, value_type c, size_t count)
 
static value_type * cMemChr (value_type *ptr, value_type c, size_t count)
 
static int cMemCmp (const value_type *ptr1, const value_type *ptr2, size_t count)
 

Protected Attributes

uint32 _size
 
value_type * _str
 
union {
   value_type   _storage [_builtinCapacity]
 
   struct {
      int *   _refCount
 
      uint32   _capacity
 
   }   _extern
 
}; 
 

Static Protected Attributes

static const uint32 _builtinCapacity = 32 - (sizeof(uint32) + sizeof(char *)) / sizeof(value_type)
 

Constructor & Destructor Documentation

◆ BaseString() [1/6]

template<class T>
constexpr Common::BaseString< T >::BaseString ( )
inline

Construct a new empty string.

◆ BaseString() [2/6]

template<class T>
Common::BaseString< T >::BaseString ( const BaseString< T > &  str)

Construct a copy of the given string.

◆ BaseString() [3/6]

template<class T>
Common::BaseString< T >::BaseString ( BaseString< T > &&  str)

Construct a string by moving an existing string.

◆ BaseString() [4/6]

template<class T>
Common::BaseString< T >::BaseString ( const value_type *  str)
explicit

Construct a new string from the given NULL-terminated C string.

◆ BaseString() [5/6]

template<class T>
Common::BaseString< T >::BaseString ( const value_type *  str,
uint32  len 
)

Construct a new string containing exactly len characters read from address str.

◆ BaseString() [6/6]

template<class T>
Common::BaseString< T >::BaseString ( const value_type *  beginP,
const value_type *  endP 
)

Construct a new string containing the characters between beginP (including) and endP (excluding).

Member Function Documentation

◆ equals()

template<class T>
bool Common::BaseString< T >::equals ( const BaseString< T > &  x) const

Compares whether two BaseString are the same based on memory comparison. This does not do comparison based on canonical equivalence.

◆ setChar()

template<class T>
void Common::BaseString< T >::setChar ( value_type  c,
uint32  p 
)

Set character c at position p, replacing the previous character there.

◆ deleteChar()

template<class T>
void Common::BaseString< T >::deleteChar ( uint32  p)

Removes the value at position p from the string. Using this on decomposed characters will not remove the whole character!

◆ deleteLastChar()

template<class T>
void Common::BaseString< T >::deleteLastChar ( )
inline

Remove the last character from the string.

◆ erase() [1/2]

template<class T>
void Common::BaseString< T >::erase ( uint32  p,
uint32  len = npos 
)

Remove all characters from position p to the p + len. If len = String::npos, removes all characters to the end

◆ erase() [2/2]

template<class T>
iterator Common::BaseString< T >::erase ( iterator  it)

Erases the character at the given iterator location

◆ chop()

template<class T>
void Common::BaseString< T >::chop ( uint32  len = 1)

Removes characters from the end of the string

◆ clear()

template<class T>
void Common::BaseString< T >::clear ( )

Clears the string, making it empty.

◆ contains()

template<class T>
bool Common::BaseString< T >::contains ( const BaseString< T > &  otherString) const

Checks if a given string is present in the internal string or not.

◆ insertChar()

template<class T>
void Common::BaseString< T >::insertChar ( value_type  c,
uint32  p 
)

Insert character c before position p.

◆ find() [1/2]

template<class T>
uint32 Common::BaseString< T >::find ( value_type  x,
uint32  pos = 0 
) const

Finds the index of a character in the string

◆ find() [2/2]

template<class T>
size_t Common::BaseString< T >::find ( const value_type *  s,
uint32  pos = 0 
) const

Does a find for the passed string

◆ rfind() [1/2]

template<class T>
size_t Common::BaseString< T >::rfind ( const value_type *  s) const

Does a reverse find for the passed string

◆ rfind() [2/2]

template<class T>
size_t Common::BaseString< T >::rfind ( value_type  c,
size_t  pos = npos 
) const

Does a reverse find for a passed character

◆ findFirstOf() [1/2]

template<class T>
size_t Common::BaseString< T >::findFirstOf ( value_type  c,
size_t  pos = 0 
) const

Find first character in the string matching the passed character

◆ findFirstOf() [2/2]

template<class T>
size_t Common::BaseString< T >::findFirstOf ( const value_type *  chars,
size_t  pos = 0 
) const

Find first character in the string that's any character of the passed string

◆ findLastOf() [1/2]

template<class T>
size_t Common::BaseString< T >::findLastOf ( value_type  c,
size_t  pos = npos 
) const

Find the last character in the string that's the specified character

◆ findLastOf() [2/2]

template<class T>
size_t Common::BaseString< T >::findLastOf ( const value_type *  chars,
size_t  pos = npos 
) const

Find the last character in the string that's in any of the passed characters

◆ findFirstNotOf() [1/2]

template<class T>
size_t Common::BaseString< T >::findFirstNotOf ( value_type  c,
size_t  pos = 0 
) const

Find first character in the string that's not the specified character

◆ findFirstNotOf() [2/2]

template<class T>
size_t Common::BaseString< T >::findFirstNotOf ( const value_type *  chars,
size_t  pos = 0 
) const

Find first character in the string that's not any character of the passed string

◆ findLastNotOf() [1/2]

template<class T>
size_t Common::BaseString< T >::findLastNotOf ( value_type  c) const

Find the last character in the string that's not the specified character

◆ findLastNotOf() [2/2]

template<class T>
size_t Common::BaseString< T >::findLastNotOf ( const value_type *  chars) const

Find the last character in the string that's not in any of the passed characters

◆ replace() [1/2]

template<class T>
void Common::BaseString< T >::replace ( uint32  pos,
uint32  count,
const BaseString< T > &  str 
)

Functions to replace some amount of chars with chars from some other string.

Note
The implementation follows that of the STL's std::string: http://www.cplusplus.com/reference/string/string/replace/
Parameters
posStarting position for the replace in the original string.
countNumber of chars to replace from the original string.
strSource of the new chars.
posOriSame as pos
countOriSame as count
posDestInitial position to read str from.
countDestNumber of chars to read from str. npos by default.

◆ replace() [2/2]

template<class T>
void Common::BaseString< T >::replace ( value_type  from,
value_type  to 
)

Replace all from characters in object by to character

Parameters
fromthe character to look for
toThe replacement character

◆ append()

template<class T>
void Common::BaseString< T >::append ( const value_type *  begin,
const value_type *  end 
)

Appends a string containing the characters between beginP (including) and endP (excluding).

◆ wordWrap()

template<class T>
void Common::BaseString< T >::wordWrap ( const uint32  maxLength)

Wraps the text in the string to the given line maximum. Lines will be broken at any whitespace character. New lines are assumed to be represented using '
'.

This is a very basic line wrap which does not perform tab stop calculation, consecutive whitespace collapsing, auto-hyphenation, or line balancing.

◆ asUint64()

template<class T>
uint64 Common::BaseString< T >::asUint64 ( ) const

Return uint64 corrensponding to String's contents.

◆ asUint64Ext()

template<class T>
uint64 Common::BaseString< T >::asUint64Ext ( ) const

Return uint64 corrensponding to String's contents. This variant recognizes 0 (oct) and 0x (hex) prefixes.

◆ toLowercase()

template<class T>
void Common::BaseString< T >::toLowercase ( )

Convert all characters in the string to lowercase.

Be aware that this only affects the case of ASCII characters. All other characters will not be touched at all.

◆ toUppercase()

template<class T>
void Common::BaseString< T >::toUppercase ( )

Convert all characters in the string to uppercase.

Be aware that this only affects the case of ASCII characters. All other characters will not be touched at all.

◆ trim()

template<class T>
void Common::BaseString< T >::trim ( )

Removes trailing and leading whitespaces. Uses isspace() to decide what is whitespace and what not.

Member Data Documentation

◆ _builtinCapacity

template<class T>
const uint32 Common::BaseString< T >::_builtinCapacity = 32 - (sizeof(uint32) + sizeof(char *)) / sizeof(value_type)
staticprotected

The size of the internal storage. Increasing this means less heap allocations are needed, at the cost of more stack memory usage, and of course lots of wasted memory.

◆ _size

template<class T>
uint32 Common::BaseString< T >::_size
protected

Length of the string. Stored to avoid having to call strlen a lot. Yes, we limit ourselves to strings shorter than 4GB – on purpose :-).

◆ _str

template<class T>
value_type* Common::BaseString< T >::_str
protected

Pointer to the actual string storage. Either points to _storage, or to a block allocated on the heap via malloc.

◆ _storage

template<class T>
value_type Common::BaseString< T >::_storage[_builtinCapacity]

Internal string storage.

◆ _extern

struct { ... } Common::BaseString< T >::_extern

External string storage data – the refcounter, and the capacity of the string _str points to.


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