CoreComponents 3.0.0
A Modern C++ Toolkit
Loading...
Searching...
No Matches
String Class Reference

String of characters More...

#include <cc/String>

Inheritance diagram for String:

Public Types

using Item = char
 Item type.
 
- Public Types inherited from Array< uint8_t >
using Item
 Item type.
 
using value_type
 Item value type.
 
using size_type
 Type of the container capacity.
 
using iterator
 Value iterator.
 
using const_iterator
 Readonly value iterator.
 
using reverse_iterator
 Reverse value iterator.
 
using const_reverse_iterator
 Readonly reverse value iterator.
 

Standard Iterators

using value_type = Item
 Item value type.
 
using size_type = long
 Type of the container capacity.
 
using iterator = ArrayIterator<String, 1>
 Value iterator.
 
using const_iterator = ArrayIterator<const String, 1>
 Readonly value iterator.
 
using reverse_iterator = ArrayIterator<String, -1>
 Reverse value iterator.
 
using const_reverse_iterator = ArrayIterator<const String, -1>
 Readonly reverse value iterator.
 
iterator begin ()
 Return iterator pointing to the first item (if any)
 
iterator end ()
 Return iterator pointing behind the last item
 
const_iterator begin () const
 Return readonly iterator pointing to the first item (if any)
 
const_iterator cbegin () const
 Return readonly iterator pointing to the first item (if any)
 
const_iterator end () const
 Return readonly iterator pointing behind the last item
 
const_iterator cend () const
 Return readonly iterator pointing behind the last item
 
reverse_iterator rbegin ()
 Return reverse iterator pointing to the last item (if any)
 
reverse_iterator rend ()
 Return reverse iterator pointing before the first item
 
const_reverse_iterator rbegin () const
 Return readonly reverse iterator pointing to the last item (if any)
 
const_reverse_iterator crbegin () const
 Return readonly reverse iterator pointing to the last item (if any)
 
const_reverse_iterator rend () const
 Return reverse iterator pointing before the first item
 
const_reverse_iterator crend () const
 Return reverse iterator pointing before the first item
 

Construction and Assignment

 String ()=default
 Create an empty string.
 
 String (const char *b)
 Construct a copy of string literal b.
 
 String (const char *b, long n)
 Construct a copy of of the first n characters of b.
 
 String (const Bytes &b, long i0, long i1)
 Construct a deep copy of the sub-string [i0, i1) of b.
 
template<class Part >
 String (const List< Part > &parts)
 Join a list of strings.
 
template<class Part >
 String (const List< Part > &parts, const String &sep)
 Join a list of strings using sep as interposing separator.
 
template<class Part >
 String (const List< Part > &parts, char sep)
 Join a list of strings using sep as interposing separator.
 
template<class Part >
 String (const List< Part > &parts, const char *sep)
 Join a list of strings using sep as interposing separator.
 
template<class Part >
 String (const List< Part > &parts, const char *sep, long sepCount)
 Join a list of strings using sep as interposing separator.
 
static String allocate (long n, char b)
 Create a string of n characters initialized with b.
 
static String allocate (long n)
 Create an uninitialized string of n characters.
 

Item Access

long count () const
 Get the length of the string in number of characters.
 
 operator bool () const
 Check if this string is non-empty.
 
long operator+ () const
 Get the length of the string in number of characters.
 
bool has (long i) const
 Check if i is a valid index.
 
char & at (long i)
 Get a reference to the character at i.
 
const char & at (long i) const
 Get a constant reference to the character at i.
 
char & operator[] (long i)
 Get a reference to the character at i.
 
const char & operator[] (long i) const
 Get a constant reference to the character at i.
 
char & operator[] (int i)
 Help the C++ compiler to not fall back to operator char*() for index access.
 
const char & operator[] (int i) const
 Help the C++ compiler to not fall back to operator char*() for index access.
 
char operator() (long i, char fallback='\0') const
 Get value at i if 0 <= i && i < count(), otherwise return fallback.
 
bool startsWith (char b) const
 Check if the first character of this string equals b.
 
bool startsWith (const char *b, long bn=-1) const
 Check if this string starts with sub-string b.
 
bool startsWith (const String &b) const
 Check if this string starts with sub-string b.
 
bool endsWith (char b) const
 Check if the last character of this string equals b.
 
bool endsWith (const char *b, long bn=-1) const
 Check if this tring ends with sub-string b.
 
bool endsWith (const String &b) const
 Check if this tring ends with sub-string b.
 

Global Operations

String copy () const
 Create a deep copy of this string.
 
String copy (long i0, long i1) const
 Create a deep copy of range [i0, i1)
 
String copy (Range range) const
 Create a deep copy of range.
 
void resize (long n)
 Resize this string to n characters preserving the contents (new characters preset with '\0')
 
void truncate (long n)
 Reduce the length of this string to n characters without freeing memory.
 
String select (long i0, long i1)
 Return a selection of range [i0, i1)
 
String select (Range range)
 Return a selection of range
 
String selectHead (long n)
 Select the first n characters or less (if n > count())
 
String selectTail (long n)
 Select the last n characters or less (if n > count())
 
StringselectAs (long i0, long i1, Out< String > target)
 Return a selection of range [i0, i1) in target
 
StringselectAs (Range range, Out< String > target)
 Return a selection of range in target
 
String alignedLeft (int w, char blank=' ') const
 Align text to the left.
 
String alignedRight (int w, char blank=' ') const
 Align text to the right.
 
String parent ()
 Get parent string if this string is a sub-string selection.
 
long count (char b) const
 Count the number of occurences of character b.
 
bool find (char b, InOut< long > i0=None{}) const
 Find character b.
 
bool find (const char *b, long bn=-1, InOut< long > i0=None{}) const
 Find sub-string b in this string.
 
bool find (const String &b, InOut< long > i0=None{}) const
 Find sub-string b in this string.
 
bool contains (char b) const
 Check if this string contains character b
 
bool contains (const char *b) const
 Check if this string contains sub-string b
 
bool contains (const String &b) const
 Check if this string contains sub-string b
 
void replace (char a, char b)
 Replace all occurance of a in this string by b.
 
void replace (const char *b, const char *s)
 Replace all occurance of b in this string by s.
 
void replace (const char *b, const String &s)
 Replace all occurance of b in this string by s.
 
void replace (const String &b, const char *s)
 Replace all occurance of b in this string by s.
 
void replace (const String &b, const String &s)
 Replace all occurance of b in this string by s.
 
String replaced (const char *b, const char *s) const
 Obtain a copy of this string where all occurances of b are replaced by s.
 
String replaced (const char *b, const String &s) const
 Obtain a copy of this string where all occurances of b are replaced by s.
 
String replaced (const String &b, const char *s) const
 Obtain a copy of this string where all occurances of b are replaced by s.
 
String replaced (const String &b, const String &s) const
 Obtain a copy of this string where all occurances of b are replaced by s.
 
List< Stringsplit (char sep) const
 Create a string list by splitting this string into pieces.
 
List< Stringsplit (const char *sep) const
 Create a string list by splitting this string into pieces.
 
List< Stringsplit (const String &sep) const
 Create a string list by splitting this string into pieces.
 
List< StringbreakUp (long m) const
 Breakup this string into equal sized pieces of m characters.
 
Stringoperator+= (char b)
 Append b to this string.
 
Stringoperator+= (const char *b)
 Append b to this string.
 
Stringoperator+= (const String &b)
 Append b to this string.
 
String times (long n) const
 Return a string which comprises of n times this string concatenated together
 
String operator* (long n) const
 Return a string which comprises of n times this string concatenated together
 
String paste (long i0, long i1, const String &text) const
 Create an edited version of this string by replacing a sub-string.
 
void downcase ()
 Convert all upper-case characters in this string to the corresponding lower-case characters.
 
void upcase ()
 Convert all lower-case characters in this string to the corresponding uppser-case characters.
 
String downcased () const
 Return a copy of this string with all upper-case characters converted to the corresponding lower-case characters
 
String upcased () const
 Return a copy of this string with all lower-case characters converted to the corresponding upper-case characters
 
void trim (const char *ls=" \t\n\r", const char *ts=nullptr)
 Remove leading and trailing whitespace.
 
void trim (const String &ls, const String &ts)
 Remove leading and trailing whitespace.
 
void trimBom ()
 Remove a UTF-8 encoded Byte Order Mark (BOM) if present.
 
String trimmed (const char *ls=" \t\n\r", const char *ts=nullptr) const
 Obtain a copy of this string with leading and trailing whitespace removed.
 
String trimmed (const String &ls, const String &ts) const
 Obtain a copy of this string with leading and trailing whitespace removed.
 
void trimLeading (const char *ws=" \t\n\r")
 Remove leading whitespace.
 
void trimLeading (const String &ws)
 Remove leading whitespace.
 
String leadingTrimmed (const char *ws=" \t\n\r") const
 Obtain a copy of this string with leading whitespace removed.
 
String leadingTrimmed (const String &ws) const
 Obtain a copy of this string with leading whitespace removed.
 
void trimTrailing (const char *ws=" \t\n\r")
 Remove trailing whitespace.
 
void trimTrailing (const String &ws)
 Remove trailing whitespace.
 
String trailingTrimmed (const char *ws=" \t\n\r") const
 Obtain a copy of this string with trailing whitespace removed.
 
String trailingTrimmed (const String &ws) const
 Obtain a copy of this string with trailing whitespace removed.
 
void simplify (const char *ws=" \t\n\r")
 Replace multi-character whitespace sequences within this string by single space characters.
 
void simplify (const String &ws)
 Replace multi-character whitespace sequences within this string by single space characters.
 
String simplified (const char *ws=" \t\n\r") const
 Replace multi-character whitespace sequences within this string by single space characters.
 
String simplified (const String &ws) const
 Replace multi-character whitespace sequences within this string by single space characters.
 
void escape ()
 Replace all non-printable and non-ASCII characters by escape sequences.
 
String escaped () const
 Replace all non-printable and non-ASCII characters by escape sequences.
 
void expand ()
 Replace escape sequences by their character value or multi-byte representation.
 
String expanded ()
 Replace escape sequences by their character value or multi-byte representation.
 
String indented (const String &prefix)
 Insert prefix at the beginning of each line of text.
 
bool toBool (Out< bool > ok=None{}) const
 Read this string as a boolean value.
 
int toInt (Out< bool > ok=None{}) const
 Read this string as an integer number.
 
long toLong (Out< bool > ok=None{}) const
 Read this string as an long integer number.
 
double toDouble (Out< bool > ok=None{}) const
 Read this string as an floating point number.
 
template<class T >
bool read (Out< T > value) const
 Read this string as a value ot type T.
 
template<class T , int base = -1>
bool readNumber (Out< T > value) const
 Read this string as a number of type T.
 
template<class T , int base = -1>
bool readNumberInRange (long i0, long i1, Out< T > value) const
 Read the sub-string in range [i0, i1) as a number of type T.
 

File Paths

bool isRootPath () const
 Check if this path points to the root directory.
 
bool isAbsolutePath () const
 Check if this path is an absolute path.
 
bool isRelativePath () const
 Check if this path is a relative path.
 
bool isHerePath () const
 Check if this is a here path (e.g.
 
String absolutePathRelativeTo (const String &currentDir) const
 Convert to an absolute path.
 
String fileName () const
 Return the file name component of this path
 
String baseName () const
 Return the file name of this path without the file type suffix
 
String fileSuffix () const
 Return the file type suffix of this path
 
String longBaseName () const
 Return the file name of this path up to the last '.
 
String shortFileSuffix () const
 Return the short file type suffix of this path
 
String sansFileSuffix () const
 Return the same file path without the file name's suffix
 
String operator/ (const String &relativePath) const
 Extend this path by relativePath.
 
String cd (const String &target) const
 Navigate from this path to target path.
 
String cdUp () const
 Convenience method, equivalent to cd("..")
 
String canonicalPath () const
 Remove redundant and ambigous components from this path.
 

Comparism operators

bool operator== (const String &other) const
 Equality operator.
 
std::strong_ordering operator<=> (const String &other) const
 Ordering operator.
 
std::strong_ordering operator<=> (const char *other) const
 Ordering operator.
 

Type Compatibility

bool isCString () const
 Check if this string is zero-terminated.
 
String cString () const
 Return a zero-terminated version of this string
 
const BytesasBytes () const
 Return this string as byte array
 
 operator char * ()
 Automatic conversion to low-level C-string.
 
 operator const char * () const
 Automatic conversion to low-level C-string.
 
 operator void * ()
 Automatic conversion to low-level data pointer.
 
 operator const void * () const
 Automatic conversion to constant low-level data pointer.
 

Additional Inherited Members

- Public Member Functions inherited from Array< uint8_t >
iterator begin ()
 Return iterator pointing to the first item (if any)
 
const_iterator begin () const
 Return readonly iterator pointing to the first item (if any)
 
iterator end ()
 Return iterator pointing behind the last item
 
const_iterator end () const
 Return readonly iterator pointing behind the last item
 
const_iterator cbegin () const
 Return readonly iterator pointing to the first item (if any)
 
const_iterator cend () const
 Return readonly iterator pointing behind the last item
 
reverse_iterator rbegin ()
 Return reverse iterator pointing to the last item (if any)
 
const_reverse_iterator rbegin () const
 Return readonly reverse iterator pointing to the last item (if any)
 
reverse_iterator rend ()
 Return reverse iterator pointing before the first item
 
const_reverse_iterator rend () const
 Return reverse iterator pointing before the first item
 
const_reverse_iterator crbegin () const
 Return readonly reverse iterator pointing to the last item (if any)
 
const_reverse_iterator crend () const
 Return reverse iterator pointing before the first item
 
 Array ()
 Create an empty array.
 
 Array (Dim< 1 > dim)
 Create a array of dim[0] items.
 
 Array (const Array &other)=default
 Construct a copy of other.
 
 Array (Array &&b)
 Construct from right-side b.
 
 Array (std::initializer_list< uint8_t > items)
 Construct with initial items.
 
 Array (std::initializer_list< Array > arrays)
 Concatenate arrays into a single new array.
 
 Array (const Item *src, long count)
 Create a copy of the low-level array src of count items.
 
 Array (const List< Array > &parts)
 Join several arrays into one.
 
 Array (const List< Array > &parts, Item sep)
 Join several arrays into one using sep as interposing separator.
 
Arrayoperator= (const Array &)=default
 Default assignment operator.
 
Arrayoperator= (Array &&b)
 Assign right-side b.
 
const Itemitems () const
 Get pointer to internal memory buffer.
 
Itemitems ()
 Get pointer to internal memory buffer.
 
const char * chars () const
 Low-level access to the underlying characters.
 
char * chars ()
 Low-level access to the underlying characters.
 
const uint8_tbytes () const
 Low-level access to the underlying bytes.
 
uint8_tbytes ()
 Low-level access to the underlying bytes.
 
const uint32_twords () const
 Low-level access to the underlying memory words.
 
uint32_twords ()
 Low-level access to the underlying memory words.
 
 operator OtherItem * ()
 Explicit conversion to low-level pointer.
 
 operator const OtherItem * () const
 Explicit conversion to constant low-level pointer.
 
 operator void * ()
 Implicit conversion to low-level data pointer.
 
 operator const void * () const
 Implicit conversion to constant low-level data pointer.
 
void wrapAround (void *data, long count)
 Wrap this array around the low-level memory vector data of count items.
 
long count () const
 Size of this array in number of items.
 
long size () const
 Size of this array in number of items.
 
bool has (long i) const
 Check if i is a valid index.
 
 operator bool () const
 Check if this array is non-empty.
 
long operator+ () const
 Size of this array in number of items.
 
Itemat (long i)
 Get a reference to the item at i.
 
const Itemat (long i) const
 Get a constant reference to the item at i.
 
long itemCount () const
 Get number of items of type U.
 
U & item (long j)
 Return a reference to an object of type U at object index j
 
const U & item (long j) const
 Return a constant reference to an object of type U at object index j
 
std::uint8_t & byteAt (long j)
 Convenience function for item<std::uint8_t>()
 
const std::uint8_t & byteAt (long j) const
 Convenience function for item<std::uint8_t>()
 
std::uint32_t & wordAt (long j)
 Convenience function for item<std::uint32_t>()
 
const std::uint32_t & wordAt (long j) const
 Convenience function for item<std::uint32_t>()
 
Itemoperator[] (long i)
 Get a reference to the item at i.
 
const Itemoperator[] (long i) const
 Get a constant reference to the item at i.
 
Item operator() (long i) const
 Get value at index if 0 <= i && i < count(), otherwise return fallback.
 
Arrayoperator() (long i, const uint8_t &value)
 Set value at index if 0 <= i && i < count(), otherwise do nothing.
 
const Itemfirst () const
 Get constant reference to first item.
 
const Itemlast () const
 Get constant reference to last item.
 
bool startsWith (const Array &head) const
 Check if head equals the start of this array.
 
bool endsWith (const Array &tail) const
 Check if tail equals the end of this array.
 
long count (const Item &b) const
 Count the number of occurences of item b.
 
bool find (const Item &b, InOut< long > i0=None{}) const
 Find item b.
 
void replace (const Item &b, const Item &s)
 Replace all occurance of b by s.
 
Array copy () const
 Create a deep copy of this array.
 
Array copy (long i0, long i1) const
 Create a copy of range [i0, i1)
 
void copyRangeTo (long i0, long i1, Out< Array > dst) const
 Copy the items in range [i0, i1] to array dst.
 
void copyRangeToOffset (long i0, long i1, Out< Array > dst, long j0) const
 Copy the items in range [i0, i1] to array dst starting at item dst[j0].
 
void copyTo (Out< Array > dst) const
 Copy contents of this array to array dst.
 
void copyToOffset (Out< Array > dst, long j0) const
 Copy contents of this array to array dst starting at item dst[j0].
 
void copyToRange (Out< Array > dst, long j0, long j1) const
 Copy contents of this array to array dst in the range dst[j0]..dst[j1-1].
 
void applyTo (InOut< Array > dst) const
 Apply the contents of this array to array dst.
 
void fill (const Item &b)
 Set all items to b
 
void resize (long n)
 Resize this array to n items preserving the contents (new items are uninitialized)
 
void truncate (long n)
 Reduce the length of this array to n items without freeing memory.
 
void deplete ()
 Truncate to zero length and free all previously stored items.
 
Array select (long i0, long i1)
 Return a selection of range [i0, i1)
 
ArrayselectAs (long i0, long i1, Out< Array > target)
 Return a selection of range [i0, i1) in target
 
Array selectHead (long n)
 Select the first n items or less (if n > count())
 
Array selectTail (long n)
 Select the last n items or less (if n > count())
 
long offset () const
 Offset of this array within its parent array if this array is a selection (0 otherwise)
 
Array parent ()
 Get parent array if this array is a selection.
 
void shift (long n)
 Truncate |n| items from the front (n > 0) or from the back (n < 0)
 
void reverse ()
 Reverse the order of items in this array.
 
Array reversed () const
 Get a copy of this array with order of items reversed.
 
bool operator== (const Array &other) const
 Equality operator.
 
std::strong_ordering operator<=> (const Array &other) const
 Ordering operator.
 
- Static Public Member Functions inherited from Array< uint8_t >
static Array allocate (long n)
 Create a array of n items.
 
static Array wrap (void *data, long count)
 Create a new array wrapped around data containing count items.
 

Detailed Description

String of characters

Member Typedef Documentation

◆ Item

using Item = char

Item type.

◆ value_type

using value_type = Item

Item value type.

◆ size_type

using size_type = long

Type of the container capacity.

◆ iterator

Value iterator.

◆ const_iterator

using const_iterator = ArrayIterator<const String, 1>

Readonly value iterator.

◆ reverse_iterator

Reverse value iterator.

◆ const_reverse_iterator

Readonly reverse value iterator.

Constructor & Destructor Documentation

◆ String() [1/9]

String ( )
default

Create an empty string.

◆ String() [2/9]

String ( const char * b)

Construct a copy of string literal b.

◆ String() [3/9]

String ( const char * b,
long n )

Construct a copy of of the first n characters of b.

◆ String() [4/9]

String ( const Bytes & b,
long i0,
long i1 )

Construct a deep copy of the sub-string [i0, i1) of b.

◆ String() [5/9]

template<class Part >
String ( const List< Part > & parts)

Join a list of strings.

◆ String() [6/9]

template<class Part >
String ( const List< Part > & parts,
const String & sep )
explicit

Join a list of strings using sep as interposing separator.

Template Parameters
PartType of the parts to join together: either String or Bytes

◆ String() [7/9]

template<class Part >
String ( const List< Part > & parts,
char sep )
explicit

Join a list of strings using sep as interposing separator.

Template Parameters
PartType of the parts to join together: either String or Bytes

◆ String() [8/9]

template<class Part >
String ( const List< Part > & parts,
const char * sep )
explicit

Join a list of strings using sep as interposing separator.

◆ String() [9/9]

template<class Part >
String ( const List< Part > & parts,
const char * sep,
long sepCount )
explicit

Join a list of strings using sep as interposing separator.

Template Parameters
PartType of the parts to join together: either String or Bytes

Member Function Documentation

◆ allocate() [1/2]

static String allocate ( long n,
char b )
static

Create a string of n characters initialized with b.

◆ allocate() [2/2]

static String allocate ( long n)
static

Create an uninitialized string of n characters.

◆ count() [1/2]

long count ( ) const

Get the length of the string in number of characters.

◆ operator bool()

operator bool ( ) const
explicit

Check if this string is non-empty.

◆ operator+()

long operator+ ( ) const

Get the length of the string in number of characters.

◆ has()

bool has ( long i) const

Check if i is a valid index.

◆ at() [1/2]

char & at ( long i)

Get a reference to the character at i.

◆ at() [2/2]

const char & at ( long i) const

Get a constant reference to the character at i.

◆ operator[]() [1/4]

char & operator[] ( long i)

Get a reference to the character at i.

◆ operator[]() [2/4]

const char & operator[] ( long i) const

Get a constant reference to the character at i.

◆ operator[]() [3/4]

char & operator[] ( int i)

Help the C++ compiler to not fall back to operator char*() for index access.

◆ operator[]() [4/4]

const char & operator[] ( int i) const

Help the C++ compiler to not fall back to operator char*() for index access.

◆ operator()()

char operator() ( long i,
char fallback = '\0' ) const

Get value at i if 0 <= i && i < count(), otherwise return fallback.

◆ startsWith() [1/3]

bool startsWith ( char b) const

Check if the first character of this string equals b.

◆ startsWith() [2/3]

bool startsWith ( const char * b,
long bn = -1 ) const

Check if this string starts with sub-string b.

◆ startsWith() [3/3]

bool startsWith ( const String & b) const

Check if this string starts with sub-string b.

◆ endsWith() [1/3]

bool endsWith ( char b) const

Check if the last character of this string equals b.

◆ endsWith() [2/3]

bool endsWith ( const char * b,
long bn = -1 ) const

Check if this tring ends with sub-string b.

◆ endsWith() [3/3]

bool endsWith ( const String & b) const

Check if this tring ends with sub-string b.

◆ copy() [1/3]

String copy ( ) const

Create a deep copy of this string.

◆ copy() [2/3]

String copy ( long i0,
long i1 ) const

Create a deep copy of range [i0, i1)

◆ copy() [3/3]

String copy ( Range range) const

Create a deep copy of range.

◆ resize()

void resize ( long n)

Resize this string to n characters preserving the contents (new characters preset with '\0')

◆ truncate()

void truncate ( long n)

Reduce the length of this string to n characters without freeing memory.

◆ select() [1/2]

String select ( long i0,
long i1 )

Return a selection of range [i0, i1)

◆ select() [2/2]

String select ( Range range)

Return a selection of range

◆ selectHead()

String selectHead ( long n)

Select the first n characters or less (if n > count())

◆ selectTail()

String selectTail ( long n)

Select the last n characters or less (if n > count())

◆ selectAs() [1/2]

String & selectAs ( long i0,
long i1,
Out< String > target )

Return a selection of range [i0, i1) in target

Returns
Reference to this string

◆ selectAs() [2/2]

String & selectAs ( Range range,
Out< String > target )

Return a selection of range in target

Returns
Reference to this string

◆ alignedLeft()

String alignedLeft ( int w,
char blank = ' ' ) const

Align text to the left.

Parameters
wWidth of display field
blankFill character
Returns
Left aligned text

◆ alignedRight()

String alignedRight ( int w,
char blank = ' ' ) const

Align text to the right.

Parameters
wWidth of display field
blankFill character
Returns
Right aligned text

◆ parent()

String parent ( )

Get parent string if this string is a sub-string selection.

◆ count() [2/2]

long count ( char b) const

Count the number of occurences of character b.

◆ find() [1/3]

bool find ( char b,
InOut< long > i0 = None{} ) const

Find character b.

Parameters
bThe character to search for
i0Provides the starting position and returns the final position
Returns
True if character b was found, false otherwise

◆ find() [2/3]

bool find ( const char * b,
long bn = -1,
InOut< long > i0 = None{} ) const

Find sub-string b in this string.

◆ find() [3/3]

bool find ( const String & b,
InOut< long > i0 = None{} ) const

Find sub-string b in this string.

◆ contains() [1/3]

bool contains ( char b) const

Check if this string contains character b

◆ contains() [2/3]

bool contains ( const char * b) const

Check if this string contains sub-string b

◆ contains() [3/3]

bool contains ( const String & b) const

Check if this string contains sub-string b

◆ replace() [1/5]

void replace ( char a,
char b )

Replace all occurance of a in this string by b.

◆ replace() [2/5]

void replace ( const char * b,
const char * s )

Replace all occurance of b in this string by s.

◆ replace() [3/5]

void replace ( const char * b,
const String & s )

Replace all occurance of b in this string by s.

◆ replace() [4/5]

void replace ( const String & b,
const char * s )

Replace all occurance of b in this string by s.

◆ replace() [5/5]

void replace ( const String & b,
const String & s )

Replace all occurance of b in this string by s.

◆ replaced() [1/4]

String replaced ( const char * b,
const char * s ) const

Obtain a copy of this string where all occurances of b are replaced by s.

◆ replaced() [2/4]

String replaced ( const char * b,
const String & s ) const

Obtain a copy of this string where all occurances of b are replaced by s.

◆ replaced() [3/4]

String replaced ( const String & b,
const char * s ) const

Obtain a copy of this string where all occurances of b are replaced by s.

◆ replaced() [4/4]

String replaced ( const String & b,
const String & s ) const

Obtain a copy of this string where all occurances of b are replaced by s.

◆ split() [1/3]

List< String > split ( char sep) const

Create a string list by splitting this string into pieces.

Parameters
sepsplit marker(s) to search for
Returns
list of pieces without the split marker(s)

◆ split() [2/3]

List< String > split ( const char * sep) const

Create a string list by splitting this string into pieces.

Parameters
sepsplit marker(s) to search for
Returns
list of pieces without the split marker(s)

◆ split() [3/3]

List< String > split ( const String & sep) const

Create a string list by splitting this string into pieces.

Parameters
sepsplit marker(s) to search for
Returns
list of pieces without the split marker(s)

◆ breakUp()

List< String > breakUp ( long m) const

Breakup this string into equal sized pieces of m characters.

◆ operator+=() [1/3]

String & operator+= ( char b)

Append b to this string.

◆ operator+=() [2/3]

String & operator+= ( const char * b)

Append b to this string.

◆ operator+=() [3/3]

String & operator+= ( const String & b)

Append b to this string.

◆ times()

String times ( long n) const

Return a string which comprises of n times this string concatenated together

◆ operator*()

String operator* ( long n) const

Return a string which comprises of n times this string concatenated together

◆ paste()

String paste ( long i0,
long i1,
const String & text ) const

Create an edited version of this string by replacing a sub-string.

Parameters
i0begin of sub-string (index of first selected character)
i1end of sub-string (index behind the last selected charater)
texttext that will replace the sub-string
Returns
new string with range [i0, i1) replaced by text

◆ downcase()

void downcase ( )

Convert all upper-case characters in this string to the corresponding lower-case characters.

◆ upcase()

void upcase ( )

Convert all lower-case characters in this string to the corresponding uppser-case characters.

◆ downcased()

String downcased ( ) const

Return a copy of this string with all upper-case characters converted to the corresponding lower-case characters

◆ upcased()

String upcased ( ) const

Return a copy of this string with all lower-case characters converted to the corresponding upper-case characters

◆ trim() [1/2]

void trim ( const char * ls = " \t\n\r",
const char * ts = nullptr )

Remove leading and trailing whitespace.

Parameters
lsSet of characters to detect as leading whitespace
tsSet of characters to detect as trailing whitespace

◆ trim() [2/2]

void trim ( const String & ls,
const String & ts )

Remove leading and trailing whitespace.

Parameters
lsSet of characters to detect as leading whitespace
tsSet of characters to detect as trailing whitespace

◆ trimBom()

void trimBom ( )

Remove a UTF-8 encoded Byte Order Mark (BOM) if present.

◆ trimmed() [1/2]

String trimmed ( const char * ls = " \t\n\r",
const char * ts = nullptr ) const

Obtain a copy of this string with leading and trailing whitespace removed.

Parameters
lsSet of characters to detect as leading whitespace
tsSet of characters to detect as trailing whitespace
Returns
Trimmed string

◆ trimmed() [2/2]

String trimmed ( const String & ls,
const String & ts ) const

Obtain a copy of this string with leading and trailing whitespace removed.

Parameters
lsSet of characters to detect as leading whitespace
tsSet of characters to detect as trailing whitespace
Returns
Trimmed string

◆ trimLeading() [1/2]

void trimLeading ( const char * ws = " \t\n\r")

Remove leading whitespace.

Parameters
ws&Set of characters to detect as whitespace

◆ trimLeading() [2/2]

void trimLeading ( const String & ws)

Remove leading whitespace.

Parameters
ws&Set of characters to detect as whitespace

◆ leadingTrimmed() [1/2]

String leadingTrimmed ( const char * ws = " \t\n\r") const

Obtain a copy of this string with leading whitespace removed.

Parameters
wsSet of characters to detect as whitespace
Returns
trimmed string

◆ leadingTrimmed() [2/2]

String leadingTrimmed ( const String & ws) const

Obtain a copy of this string with leading whitespace removed.

Parameters
wsSet of characters to detect as whitespace
Returns
trimmed string

◆ trimTrailing() [1/2]

void trimTrailing ( const char * ws = " \t\n\r")

Remove trailing whitespace.

Parameters
wsSet of characters to detect as whitespace

◆ trimTrailing() [2/2]

void trimTrailing ( const String & ws)

Remove trailing whitespace.

Parameters
wsSet of characters to detect as whitespace

◆ trailingTrimmed() [1/2]

String trailingTrimmed ( const char * ws = " \t\n\r") const

Obtain a copy of this string with trailing whitespace removed.

Parameters
wsSet of characters to detect as whitespace
Returns
Trimmed string

◆ trailingTrimmed() [2/2]

String trailingTrimmed ( const String & ws) const

Obtain a copy of this string with trailing whitespace removed.

Parameters
wsSet of characters to detect as whitespace
Returns
Trimmed string

◆ simplify() [1/2]

void simplify ( const char * ws = " \t\n\r")

Replace multi-character whitespace sequences within this string by single space characters.

Parameters
wset of characters to detect as whitespace

◆ simplify() [2/2]

void simplify ( const String & ws)

Replace multi-character whitespace sequences within this string by single space characters.

Parameters
wset of characters to detect as whitespace

◆ simplified() [1/2]

String simplified ( const char * ws = " \t\n\r") const

Replace multi-character whitespace sequences within this string by single space characters.

Parameters
wset of characters to detect as whitespace

◆ simplified() [2/2]

String simplified ( const String & ws) const

Replace multi-character whitespace sequences within this string by single space characters.

Parameters
wset of characters to detect as whitespace

◆ escape()

void escape ( )

Replace all non-printable and non-ASCII characters by escape sequences.

Todo
add support for escaping UTF-8 sequences

◆ escaped()

String escaped ( ) const

Replace all non-printable and non-ASCII characters by escape sequences.

Todo
add support for escaping UTF-8 sequences

◆ expand()

void expand ( )

Replace escape sequences by their character value or multi-byte representation.

◆ expanded()

String expanded ( )

Replace escape sequences by their character value or multi-byte representation.

◆ indented()

String indented ( const String & prefix)

Insert prefix at the beginning of each line of text.

◆ toBool()

bool toBool ( Out< bool > ok = None{}) const

Read this string as a boolean value.

Parameters
okReturns true if this string can be completely read as a boolean value literal
Returns
Parsed boolean value

◆ toInt()

int toInt ( Out< bool > ok = None{}) const

Read this string as an integer number.

Parameters
okReturns true if this string can be completely read as an integer number literal
Returns
Parsed integer value

◆ toLong()

long toLong ( Out< bool > ok = None{}) const

Read this string as an long integer number.

Parameters
okReturns true if this string can be completely read as a long integer number literal
Returns
Parsed long integer value

◆ toDouble()

double toDouble ( Out< bool > ok = None{}) const

Read this string as an floating point number.

Parameters
okReturns true if this string can be completely read as a floating point number literal
Returns
Parsed floating point value

◆ read()

template<class T >
bool read ( Out< T > value) const

Read this string as a value ot type T.

Parameters
valueReturns the parsed value, if successful
Returns
True if successful

◆ readNumber()

template<class T , int base = -1>
bool readNumber ( Out< T > value) const

Read this string as a number of type T.

Template Parameters
baseNumber base
Parameters
valueReturns the parsed value, if successful
Returns
True if successful

◆ readNumberInRange()

template<class T , int base = -1>
bool readNumberInRange ( long i0,
long i1,
Out< T > value ) const

Read the sub-string in range [i0, i1) as a number of type T.

Template Parameters
baseNumber base
Parameters
i0Begin of sub-string (index of first selected character)
i1End of sub-string (index behind the last selected charater)
valueReturns the parsed value, if successful
Returns
True if successful

◆ begin() [1/2]

iterator begin ( )

Return iterator pointing to the first item (if any)

◆ end() [1/2]

iterator end ( )

Return iterator pointing behind the last item

◆ begin() [2/2]

const_iterator begin ( ) const

Return readonly iterator pointing to the first item (if any)

◆ cbegin()

const_iterator cbegin ( ) const

Return readonly iterator pointing to the first item (if any)

◆ end() [2/2]

const_iterator end ( ) const

Return readonly iterator pointing behind the last item

◆ cend()

const_iterator cend ( ) const

Return readonly iterator pointing behind the last item

◆ rbegin() [1/2]

reverse_iterator rbegin ( )

Return reverse iterator pointing to the last item (if any)

◆ rend() [1/2]

reverse_iterator rend ( )

Return reverse iterator pointing before the first item

◆ rbegin() [2/2]

const_reverse_iterator rbegin ( ) const

Return readonly reverse iterator pointing to the last item (if any)

◆ crbegin()

const_reverse_iterator crbegin ( ) const

Return readonly reverse iterator pointing to the last item (if any)

◆ rend() [2/2]

const_reverse_iterator rend ( ) const

Return reverse iterator pointing before the first item

◆ crend()

const_reverse_iterator crend ( ) const

Return reverse iterator pointing before the first item

◆ isRootPath()

bool isRootPath ( ) const

Check if this path points to the root directory.

◆ isAbsolutePath()

bool isAbsolutePath ( ) const

Check if this path is an absolute path.

◆ isRelativePath()

bool isRelativePath ( ) const

Check if this path is a relative path.

◆ isHerePath()

bool isHerePath ( ) const

Check if this is a here path (e.g.

"." or "././")

◆ absolutePathRelativeTo()

String absolutePathRelativeTo ( const String & currentDir) const

Convert to an absolute path.

Parameters
currentDirAbsolute path to the current directory
Returns
Absolute path

◆ fileName()

String fileName ( ) const

Return the file name component of this path

◆ baseName()

String baseName ( ) const

Return the file name of this path without the file type suffix

See also
longBaseName()

◆ fileSuffix()

String fileSuffix ( ) const

Return the file type suffix of this path

See also
shortFileSuffix()

◆ longBaseName()

String longBaseName ( ) const

Return the file name of this path up to the last '.

' or end of string

See also
baseName()

◆ shortFileSuffix()

String shortFileSuffix ( ) const

Return the short file type suffix of this path

See also
fileSuffix

◆ sansFileSuffix()

String sansFileSuffix ( ) const

Return the same file path without the file name's suffix

◆ operator/()

String operator/ ( const String & relativePath) const

Extend this path by relativePath.

◆ cd()

String cd ( const String & target) const

Navigate from this path to target path.

◆ cdUp()

String cdUp ( ) const

Convenience method, equivalent to cd("..")

◆ canonicalPath()

String canonicalPath ( ) const

Remove redundant and ambigous components from this path.

◆ operator==()

bool operator== ( const String & other) const

Equality operator.

◆ operator<=>() [1/2]

std::strong_ordering operator<=> ( const String & other) const

Ordering operator.

◆ operator<=>() [2/2]

std::strong_ordering operator<=> ( const char * other) const

Ordering operator.

◆ isCString()

bool isCString ( ) const

Check if this string is zero-terminated.

◆ cString()

String cString ( ) const

Return a zero-terminated version of this string

◆ asBytes()

const Bytes & asBytes ( ) const

Return this string as byte array

◆ operator char *()

operator char * ( )

Automatic conversion to low-level C-string.

◆ operator const char *()

operator const char * ( ) const

Automatic conversion to low-level C-string.

◆ operator void *()

operator void * ( )
explicit

Automatic conversion to low-level data pointer.

◆ operator const void *()

operator const void * ( ) const
explicit

Automatic conversion to constant low-level data pointer.