nCine 2022.04.r504-20bd01e
A cross-platform 2D game engine
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Attributes | Friends | List of all members
nctl::StaticString< C > Class Template Reference

A basic string class made of chars stored on the stack. More...

#include <StaticString.h>

Public Types

using Iterator = StringIterator< false >
 Iterator type.
 
using ConstIterator = StringIterator< true >
 Constant iterator type.
 
using ReverseIterator = nctl::ReverseIterator< Iterator >
 Reverse iterator type.
 
using ConstReverseIterator = nctl::ReverseIterator< ConstIterator >
 Reverse constant iterator type.
 

Public Member Functions

 StaticString ()
 Default constructor.
 
 StaticString (const char *cString)
 Constructs a string object from a C string.
 
 StaticString (const StaticString &other)
 Copy constructor.
 
template<unsigned int U>
 StaticString (const StaticString< U > &other)
 Conversion constructor from a string of different capacity.
 
StaticStringoperator= (const StaticString &other)
 Assignment operator (it might extend or truncate the original text)
 
template<unsigned int U>
StaticStringoperator= (const StaticString< U > &other)
 Assignment operator (it might extend or truncate the original text)
 
StaticStringoperator= (const char *cString)
 Assigns a constant C string to the string object.
 
Iterator begin ()
 Returns an iterator to the first character.
 
ReverseIterator rBegin ()
 Returns a reverse iterator to the last character.
 
Iterator end ()
 Returns an iterator to the termination character.
 
ReverseIterator rEnd ()
 Returns a reverse iterator to the byte preceding the first character.
 
ConstIterator begin () const
 Returns a constant iterator to the first character.
 
ConstReverseIterator rBegin () const
 Returns a constant reverse iterator to the last character.
 
ConstIterator end () const
 Returns a constant iterator to the termination character.
 
ConstReverseIterator rEnd () const
 Returns a constant reverse iterator to the byte preceding the first character.
 
ConstIterator cBegin () const
 Returns a constant iterator to the first character.
 
ConstReverseIterator crBegin () const
 Returns a constant reverse iterator to the last character.
 
ConstIterator cEnd () const
 Returns a constant iterator to the termination character.
 
ConstReverseIterator crEnd () const
 Returns a constant reverse iterator to the byte preceding the first character.
 
bool isEmpty () const
 Returns true if the string is empty.
 
unsigned int length () const
 Returns the string length.
 
unsigned int capacity () const
 Returns the string capacity.
 
unsigned int setLength (unsigned int newLength)
 Sets the string length.
 
void clear ()
 Clears the string.
 
chardata ()
 Returns a pointer to the internal array.
 
const chardata () const
 Returns a constant pointer to the internal array.
 
unsigned int replace (const StaticString &source, unsigned int srcChar, unsigned int numChar, unsigned int destChar)
 Replaces characters from somewhere in the other string to somewhere in this one (no truncation)
 
template<unsigned int U>
unsigned int replace (const StaticString< U > &source, unsigned int srcChar, unsigned int numChar, unsigned int destChar)
 Replaces characters from somewhere in the other string to somewhere in this one (no truncation)
 
unsigned int replace (const char *source, unsigned int numChar, unsigned int destChar)
 Replaces characters from a C string to somewhere in this one (no truncation)
 
unsigned int assign (const StaticString &source, unsigned int srcChar, unsigned int numChar)
 Copies characters from somewhere in the other string to the beginning of this one.
 
template<unsigned int U>
unsigned int assign (const StaticString< U > &source, unsigned int srcChar, unsigned int numChar)
 Copies characters from somewhere in the other string to the beginning of this one.
 
unsigned int assign (const StaticString &source)
 Copies all characters from the other string to the beginning of this one.
 
template<unsigned int U>
unsigned int assign (const StaticString< U > &source)
 Copies all characters from the other string to the beginning of this one.
 
unsigned int assign (const char *source, unsigned int numChar)
 Copies characters from a C string to the beginning of this one.
 
unsigned int copy (char *dest, unsigned int srcChar, unsigned int numChar) const
 Copies characters from somewhere in this string to a C string.
 
unsigned int copy (char *dest) const
 Copies all characters from this string to a C string.
 
unsigned int append (const StaticString &other)
 Appends all the characters from the other string to the end of this one.
 
template<unsigned int U>
unsigned int append (const StaticString< U > &other)
 Appends all the characters from the other string to the end of this one.
 
unsigned int append (const char *cString)
 Appends all the characters from the C string to the end of this one.
 
int compare (const StaticString &other) const
 Compares the string with another one in lexicographical order.
 
template<unsigned int U>
int compare (const StaticString< U > &other) const
 Compares the string with another one in lexicographical order.
 
int compare (const char *cString) const
 Compares the string with a constant C string in lexicographical order.
 
int findFirstChar (char c) const
 Finds the first occurrence of a character.
 
int findLastChar (char c) const
 Finds the last occurrence of a character.
 
int findFirstCharAfterIndex (char c, unsigned int index) const
 Finds the first occurrence of a character after the character at the index.
 
int find (const StaticString &other) const
 Finds the first occurrence of the given string.
 
template<unsigned int U>
int find (const StaticString< U > &other) const
 Finds the first occurrence of the given string.
 
int find (const char *cString) const
 Finds the first occurrence of the given constant C string.
 
StaticStringformat (const char *fmt,...)
 Replaces the string with the formatted result.
 
StaticStringformatAppend (const char *fmt,...)
 Append the formatted result to the string.
 
StaticStringoperator+= (const StaticString &other)
 Appends another string to this one.
 
template<unsigned int U>
StaticStringoperator+= (const StaticString< U > &other)
 Appends another string to this one.
 
StaticStringoperator+= (const char *cString)
 Appends a constant C string to the string object.
 
StaticString operator+ (const StaticString &other) const
 Concatenate two strings together to create a third one.
 
template<unsigned int U>
StaticString operator+ (const StaticString< U > &other) const
 Concatenate two strings together to create a third one.
 
StaticString operator+ (const char *cString) const
 Concatenates a string with a constant C string to create a third one.
 
bool operator== (const StaticString &other) const
 
bool operator!= (const StaticString &other) const
 
bool operator> (const StaticString &other) const
 
bool operator< (const StaticString &other) const
 
bool operator>= (const StaticString &other) const
 
bool operator<= (const StaticString &other) const
 
template<unsigned int U>
bool operator== (const StaticString< U > &other) const
 
template<unsigned int U>
bool operator!= (const StaticString< U > &other) const
 
template<unsigned int U>
bool operator> (const StaticString< U > &other) const
 
template<unsigned int U>
bool operator< (const StaticString< U > &other) const
 
template<unsigned int U>
bool operator>= (const StaticString< U > &other) const
 
template<unsigned int U>
bool operator<= (const StaticString< U > &other) const
 
bool operator== (const char *cString) const
 
bool operator!= (const char *cString) const
 
bool operator> (const char *cString) const
 
bool operator< (const char *cString) const
 
bool operator>= (const char *cString) const
 
bool operator<= (const char *cString) const
 
const charat (unsigned int index) const
 Read-only access to the specified element (with bounds checking)
 
charat (unsigned int index)
 Access to the specified element (with bounds checking)
 
const charoperator[] (unsigned int index) const
 Read-only subscript operator.
 
charoperator[] (unsigned int index)
 Subscript operator.
 
int utf8ToCodePoint (unsigned int position, unsigned int &codePoint, unsigned int *codeUnits) const
 Retrieves the Unicode code point and the UTF-8 code units from the UTF-8 substring starting at the specified position.
 
int utf8ToCodePoint (unsigned int position, unsigned int &codePoint) const
 Retrieves the Unicode code point from the UTF-8 substring starting at the specified position.
 
template<unsigned int U>
StaticString< C > & operator= (const StaticString< U > &other)
 
template<unsigned int U>
StaticString< C > & operator+= (const StaticString< U > &other)
 
template<unsigned int U>
StaticString< C > operator+ (const StaticString< U > &other) const
 

Static Public Attributes

static const unsigned int MaxCStringLength = 512 - 1
 Maximum length when creating an object from C-style strings.
 

Friends

template<unsigned int U>
StaticString< U > operator+ (const char *cString, const StaticString< U > &string)
 Friend operator to concatenate a constant C string with a string to create a third one.
 
bool operator== (const char *cString, StaticString string)
 
bool operator!= (const char *cString, StaticString string)
 
bool operator> (const char *cString, StaticString string)
 
bool operator< (const char *cString, StaticString string)
 
bool operator>= (const char *cString, StaticString string)
 
bool operator<= (const char *cString, StaticString string)
 

Detailed Description

template<unsigned int C>
class nctl::StaticString< C >

A basic string class made of chars stored on the stack.

Member Function Documentation

◆ clear()

template<unsigned int C>
void nctl::StaticString< C >::clear ( )

Clears the string.

Length will be reset to zero but capacity remains unmodified.

◆ operator=() [1/2]

template<unsigned int C>
StaticString< C > & nctl::StaticString< C >::operator= ( const StaticString< C > &  other)

Assignment operator (it might extend or truncate the original text)

Note
Not implemented with the copy-and-swap idiom because it has to copy data.

◆ operator=() [2/2]

template<unsigned int C>
template<unsigned int U>
StaticString< C > & nctl::StaticString< C >::operator= ( const StaticString< U > &  other)
Note
Not implemented with the copy-and-swap idiom because it has to copy data.

◆ replace() [1/2]

template<unsigned int C>
unsigned int nctl::StaticString< C >::replace ( const StaticString< C > &  source,
unsigned int  srcChar,
unsigned int  numChar,
unsigned int  destChar 
)

Replaces characters from somewhere in the other string to somewhere in this one (no truncation)

The method returns the number of characters copied, to allow truncation.

◆ replace() [2/2]

template<unsigned int C>
template<unsigned int U>
unsigned int nctl::StaticString< C >::replace ( const StaticString< U > &  source,
unsigned int  srcChar,
unsigned int  numChar,
unsigned int  destChar 
)

Replaces characters from somewhere in the other string to somewhere in this one (no truncation)

The method returns the number of characters copied, to allow truncation.

◆ setLength()

template<unsigned int C>
unsigned int nctl::StaticString< C >::setLength ( unsigned int  newLength)

Sets the string length.

The method is useful to update the string length after writing into it through the data() pointer.

◆ utf8ToCodePoint() [1/2]

template<unsigned int C>
int nctl::StaticString< C >::utf8ToCodePoint ( unsigned int  position,
unsigned int codePoint 
) const

Retrieves the Unicode code point from the UTF-8 substring starting at the specified position.

Returns
The number of code units used by UTF-8 to encode the Unicode code point

◆ utf8ToCodePoint() [2/2]

template<unsigned int C>
int nctl::StaticString< C >::utf8ToCodePoint ( unsigned int  position,
unsigned int codePoint,
unsigned int codeUnits 
) const

Retrieves the Unicode code point and the UTF-8 code units from the UTF-8 substring starting at the specified position.

Returns
The number of code units used by UTF-8 to encode the Unicode code point

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