PLCnext API Documentation 25.0.2.69
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
Arp::Base::Core::BasicString< C, A > Class Template Reference

This template class implements the extensions of class String related to std::string, where the character type might be specified accordingly for UTF8 or UTF16 strings, respectively. More...

#include <BasicString.hxx>

Public Types

using Allocator = A
 The characters allocator type.
 
using AllocatorTraits = std::allocator_traits< Allocator >
 The allocator type traits.
 
using CharType = C
 The character type.
 
using Char8uType = Arp::Base::Core::char8u
 The UTF8 character type.
 
using SelfType = BasicString< CharType, Allocator >
 The self type.
 
using StdString = std::basic_string< CharType, std::char_traits< CharType >, Allocator >
 The type of the basic std string.
 
using Reference = typename StdString::reference
 The reference type of this type.
 
using ConstReference = typename StdString::const_reference
 The const reference type of this type.
 
using Iterator = typename StdString::iterator
 The iterator type of this type.
 
using ConstIterator = typename StdString::const_iterator
 The iterator type of this type.
 
using ReverseIterator = typename StdString::reverse_iterator
 The iterator type of this type.
 
using ConstReverseIterator = typename StdString::const_reverse_iterator
 Used by Split() operations.
 
using Tokens = std::vector< SelfType >
 Used by initializing operations.
 
using AppendToken = std::function< void(SelfType &&) >
 
using Bytes = std::vector< byte >
 
using allocator_type = Allocator
 The allocator type of this type.
 
using value_type = CharType
 The char type of this type.
 
using size_type = typename StdString::size_type
 The size type of this type.
 
using difference_type = typename StdString::difference_type
 The difference type of this type.
 
using reference = typename StdString::reference
 The reference type of this type.
 
using const_reference = typename StdString::const_reference
 The const reference type of this type.
 
using pointer = typename AllocatorTraits::pointer
 The pointer type of this type.
 
using const_pointer = typename AllocatorTraits::const_pointer
 The const pointer type of this type.
 
using iterator = typename StdString::iterator
 The iterator type of this type.
 
using const_iterator = typename StdString::const_iterator
 The const iterator type of this type.
 
using reverse_iterator = typename StdString::reverse_iterator
 The reverse iterator type of this type.
 
using const_reverse_iterator = typename StdString::const_reverse_iterator
 The const reverse iterator type of this type.
 

Public Member Functions

 BasicString (void)
 The default constructor constructs an empty string instance.
 
 BasicString (const SelfType &arg)
 The copy constructor copies the as argument passed string deeply. More...
 
 BasicString (SelfType &&arg) noexcept
 This move constructor moves the as argument passed string to this string. More...
 
SelfTypeoperator= (const SelfType &arg)
 This assignment operator copies the right-hand-side operand to this string. More...
 
SelfTypeoperator= (SelfType &&arg) noexcept
 This move assignment operator moves the right-hand-side operand to this string. More...
 
 ~BasicString (void)
 The destructor deallocates all memory of this instance.
 
 BasicString (const Allocator &alloc)
 This constructor creates an empty string instance. More...
 
 BasicString (const Bytes &bytes, const Allocator &alloc=Allocator())
 Copies the as arguments passed bytes to this string. More...
 
 BasicString (const StdString &arg)
 This copy constructor copies the as argument passed std::string to this string. More...
 
 BasicString (StdString &&arg) noexcept
 This move constructor moves the as argument passed std::string to this string. More...
 
 BasicString (const SelfType &arg, const Allocator &alloc)
 This constructor copies the as argument passed string deeply. More...
 
 BasicString (const SelfType &arg, size_type offset, size_type count=NPos)
 This constructor copies the as argument passed string partially. More...
 
 BasicString (const SelfType &arg, size_type offset, size_type count, const Allocator &alloc)
 This constructor copies the as argument passed string partially. More...
 
 BasicString (const CharType *pChars, size_type count)
 This constructor copies the as argument passed C-string. More...
 
 BasicString (const CharType *pChars, size_type count, const Allocator &alloc)
 This constructor copies the as argument passed C-string. More...
 
 BasicString (const CharType *pChars)
 This constructor copies the as argument passed C-string. More...
 
 BasicString (const Char8uType *pChars)
 This constructor copies the as argument passed C-string. More...
 
 BasicString (const CharType *pChars, const Allocator &alloc)
 This constructor copies the as argument passed C-string. More...
 
 BasicString (size_type count, CharType c)
 Fills the string with count consecutive copies of character c . More...
 
 BasicString (size_type count, CharType c, const Allocator &alloc)
 Fills the string with count consecutive copies of character c . More...
 
 BasicString (SelfType &&arg, const Allocator &alloc)
 This move constructor moves the as argument passed string to this string. More...
 
 BasicString (std::initializer_list< CharType > arg, const Allocator &alloc=Allocator())
 Copies each of the characters in initList , in the same order. More...
 
 BasicString (Iterator first, Iterator last, const Allocator &alloc=Allocator())
 Copies the sequence of characters in the range [first,last), in the same order.. More...
 
 BasicString (ConstIterator first, ConstIterator last, const Allocator &alloc=Allocator())
 Copies the sequence of characters in the range [first,last), in the same order.. More...
 
SelfTypeReplaceAll (const SelfType &pattern, const SelfType &replacement)
 Replaces a given pattern by a replacement string. More...
 
Allocator GetAllocator (void) const
 Gets the allocator of this string. More...
 
StdStringGetStdString (void)
 Gets the basic std string. More...
 
const StdStringGetStdString (void) const
 
SelfType TrimLeft (void) const
 
SelfType TrimLeft (CharType trim) const
 
SelfType TrimRight (void) const
 
SelfType TrimRight (CharType trim) const
 
SelfType Trim (void) const
 
SelfType Trim (CharType trim) const
 
Tokens Split (CharType delimiter, bool trimTokens=true, bool removeEmptyTokens=true) const
 Splits this string into tokens using the specified delimiter characters (multiple). More...
 
Tokens Split (std::span< const CharType > delimiters, bool trimTokens=true, bool removeEmptyTokens=true) const
 Splits this string into tokens using the specified delimiter characters (multiple). More...
 
Tokens SplitByWord (const SelfType &delimiter, bool trimTokens=true, bool removeEmptyTokens=true) const
 Splits this string into tokens using the specified (single) delimiter string. More...
 
void Split (CharType delimiter, bool trimTokens, bool removeEmptyTokens, AppendToken appendToken) const
 
void Split (std::span< const CharType > delimiters, bool trimTokens, bool removeEmptyTokens, AppendToken appendToken) const
 
void SplitByWord (const SelfType &delimiter, bool trimTokens, bool removeEmptyTokens, AppendToken appendToken) const
 

Static Public Member Functions

template<typename... Args>
static SelfType Format (const SelfType &format, const Args &... args)
 Formats the format string using the .NET/Python syntax with the given variadic arguments. More...
 
template<typename... Args>
static SelfType Format (const char *format, const Args &... args)
 Formats the format C-string using the .NET/Python syntax with the given variadic arguments. More...
 
template<typename... Args>
static SelfType FormatPrintf (const char *format, const Args &... args)
 Formats the format C-string using the printf syntax with the given variadic arguments. More...
 

Static Public Attributes

static const size_type NPos = size_type(-1)
 
static const SelfType Empty
 
static const SelfType NewLine
 

Detailed Description

template<class C, class A = std::allocator<C>>
class Arp::Base::Core::BasicString< C, A >

This template class implements the extensions of class String related to std::string, where the character type might be specified accordingly for UTF8 or UTF16 strings, respectively.

Template Parameters
CThe char type of the string, this should be char for UTF8 strings and char16 for UTF16 strings. wchar_t is not recommended, because it has 2 bytes wide on Windows, but 4 bytes wide on Linux.
AThe characters allocator type of the string, which defaults to std::allocator<C>>

Constructor & Destructor Documentation

◆ BasicString() [1/20]

template<class C , class A >
Arp::Base::Core::BasicString< C, A >::BasicString ( const SelfType arg)
inlinedefault

The copy constructor copies the as argument passed string deeply.

Parameters
argThe argument to copy.

◆ BasicString() [2/20]

template<class C , class A >
Arp::Base::Core::BasicString< C, A >::BasicString ( SelfType &&  arg)
inlinedefaultnoexcept

This move constructor moves the as argument passed string to this string.

Parameters
argThe argument to move.

◆ BasicString() [3/20]

template<class C , class A >
Arp::Base::Core::BasicString< C, A >::BasicString ( const Allocator alloc)
inlineexplicit

This constructor creates an empty string instance.

Parameters
allocThe allocator to use.

◆ BasicString() [4/20]

template<class C , class A >
Arp::Base::Core::BasicString< C, A >::BasicString ( const Bytes &  bytes,
const Allocator alloc = Allocator() 
)
inlineexplicit

Copies the as arguments passed bytes to this string.

Parameters
bytesThe bytes to copy to this string.
allocThe allocator to use.

◆ BasicString() [5/20]

template<class C , class A >
Arp::Base::Core::BasicString< C, A >::BasicString ( const StdString arg)
inline

This copy constructor copies the as argument passed std::string to this string.

Parameters
argThe argument to copy.

◆ BasicString() [6/20]

template<class C , class A >
Arp::Base::Core::BasicString< C, A >::BasicString ( StdString &&  arg)
inlinenoexcept

This move constructor moves the as argument passed std::string to this string.

Parameters
argThe argument to move.

◆ BasicString() [7/20]

template<class C , class A >
Arp::Base::Core::BasicString< C, A >::BasicString ( const SelfType arg,
const Allocator alloc 
)
inline

This constructor copies the as argument passed string deeply.

Parameters
argThe argument to copy deeply.
allocThe allocator to use.

◆ BasicString() [8/20]

template<class C , class A >
Arp::Base::Core::BasicString< C, A >::BasicString ( const SelfType arg,
size_type  offset,
size_type  count = NPos 
)
inline

This constructor copies the as argument passed string partially.

Parameters
argThe argument to copy partially.
offsetThe offset of arg to copy the chars from.
countThe number of chars to copy from arg .

◆ BasicString() [9/20]

template<class C , class A >
Arp::Base::Core::BasicString< C, A >::BasicString ( const SelfType arg,
size_type  offset,
size_type  count,
const Allocator alloc 
)
inline

This constructor copies the as argument passed string partially.

Parameters
argThe argument to copy partially.
offsetThe offset of arg to copy the chars from.
countThe number of chars to copy from arg .
allocThe allocator to use.

◆ BasicString() [10/20]

template<class C , class A >
Arp::Base::Core::BasicString< C, A >::BasicString ( const CharType pChars,
size_type  count 
)
inline

This constructor copies the as argument passed C-string.

Parameters
pCharsThe C-string to copy.
countThe number of chars to copy from pChars .

◆ BasicString() [11/20]

template<class C , class A >
Arp::Base::Core::BasicString< C, A >::BasicString ( const CharType pChars,
size_type  count,
const Allocator alloc 
)
inline

This constructor copies the as argument passed C-string.

Parameters
pCharsThe C-string to copy.
countThe number of chars to copy from pChars .
allocThe allocator to use.

◆ BasicString() [12/20]

template<class C , class A >
Arp::Base::Core::BasicString< C, A >::BasicString ( const CharType pChars)
inline

This constructor copies the as argument passed C-string.

Parameters
pCharsThe C-string to copy.

◆ BasicString() [13/20]

template<class C , class A >
Arp::Base::Core::BasicString< C, A >::BasicString ( const Char8uType pChars)
inline

This constructor copies the as argument passed C-string.

Parameters
pCharsThe UTF8 string to copy.

◆ BasicString() [14/20]

template<class C , class A >
Arp::Base::Core::BasicString< C, A >::BasicString ( const CharType pChars,
const Allocator alloc 
)
inline

This constructor copies the as argument passed C-string.

Parameters
pCharsThe C-string to copy.
allocThe allocator to use.

◆ BasicString() [15/20]

template<class C , class A >
Arp::Base::Core::BasicString< C, A >::BasicString ( size_type  count,
CharType  c 
)
inline

Fills the string with count consecutive copies of character c .

Parameters
countThe number of chars to fill this string with.
cThe char used to fill this string.

◆ BasicString() [16/20]

template<class C , class A >
Arp::Base::Core::BasicString< C, A >::BasicString ( size_type  count,
CharType  c,
const Allocator alloc 
)
inline

Fills the string with count consecutive copies of character c .

Parameters
countThe number of chars to fill this string with.
cThe char used to fill this string.
allocThe allocator to use.

◆ BasicString() [17/20]

template<class C , class A >
Arp::Base::Core::BasicString< C, A >::BasicString ( SelfType &&  arg,
const Allocator alloc 
)
inline

This move constructor moves the as argument passed string to this string.

Parameters
argThe argument to move.
allocThe allocator to use.

◆ BasicString() [18/20]

template<class C , class A >
Arp::Base::Core::BasicString< C, A >::BasicString ( std::initializer_list< CharType arg,
const Allocator alloc = Allocator() 
)
inline

Copies each of the characters in initList , in the same order.

Parameters
argThe initializer list of chars to copy.
allocThe allocator to use.

◆ BasicString() [19/20]

template<class C , class A >
Arp::Base::Core::BasicString< C, A >::BasicString ( Iterator  first,
Iterator  last,
const Allocator alloc = Allocator() 
)
inline

Copies the sequence of characters in the range [first,last), in the same order..

Parameters
firstThe begin iterator specifying the range of chars to copy.
lastThe end iterator specifying the range of chars to copy.
allocThe allocator to use.

◆ BasicString() [20/20]

template<class C , class A >
Arp::Base::Core::BasicString< C, A >::BasicString ( ConstIterator  first,
ConstIterator  last,
const Allocator alloc = Allocator() 
)
inline

Copies the sequence of characters in the range [first,last), in the same order..

Parameters
firstThe begin Iterator specifying the range of chars to copy.
lastThe end iterator specifying the range of chars to copy.
allocThe allocator to use.

Member Function Documentation

◆ Format() [1/2]

template<class C , class A >
template<typename... Args>
BasicString< C, A >::SelfType Arp::Base::Core::BasicString< C, A >::Format ( const char *  format,
const Args &...  args 
)
inlinestatic

Formats the format C-string using the .NET/Python syntax with the given variadic arguments.

Parameters
formatThe C-string to format using .NET/Python syntax for placeholders like {}, {1} or {2}.
argsThe variadic arguments to format into the format string.
Returns
The formatted string.

◆ Format() [2/2]

template<class C , class A >
template<typename... Args>
BasicString< C, A >::SelfType Arp::Base::Core::BasicString< C, A >::Format ( const SelfType format,
const Args &...  args 
)
inlinestatic

Formats the format string using the .NET/Python syntax with the given variadic arguments.

Parameters
formatThe string to format using .NET/Python syntax for placeholders like {}, {1} or {2}.
argsThe variadic arguments to format into the format string.
Returns
The formatted string.

◆ FormatPrintf()

template<class C , class A >
template<typename... Args>
BasicString< C, A >::SelfType Arp::Base::Core::BasicString< C, A >::FormatPrintf ( const char *  format,
const Args &...  args 
)
inlinestatic

Formats the format C-string using the printf syntax with the given variadic arguments.

Parameters
formatThe C-string to format in printf syntax for placeholders like d, f or i.
argsThe variadic arguments to format into the format string.
Returns
The formatted string.

◆ GetAllocator()

template<class C , class A >
BasicString< C, A >::Allocator Arp::Base::Core::BasicString< C, A >::GetAllocator ( void  ) const
inline

Gets the allocator of this string.

Returns
The allocator of this string.

◆ GetStdString()

template<class C , class A >
const BasicString< C, A >::StdString & Arp::Base::Core::BasicString< C, A >::GetStdString ( void  )
inline

Gets the basic std string.

Gets the basic std const string.

Returns
The basic std string.
Returns
The basic std const string.

◆ operator=() [1/2]

template<class C , class A >
BasicString< C, A >::SelfType & Arp::Base::Core::BasicString< C, A >::operator= ( const SelfType arg)
inlinedefault

This assignment operator copies the right-hand-side operand to this string.

Parameters
argThe argument to copy.
Returns
A reference to this instance.

◆ operator=() [2/2]

template<class C , class A >
BasicString< C, A >::SelfType & Arp::Base::Core::BasicString< C, A >::operator= ( SelfType &&  arg)
inlinedefaultnoexcept

This move assignment operator moves the right-hand-side operand to this string.

Parameters
argThe argument to move.
Returns
A reference to this instance.

◆ ReplaceAll()

template<class C , class A >
BasicString< C, A >::SelfType & Arp::Base::Core::BasicString< C, A >::ReplaceAll ( const SelfType pattern,
const SelfType replacement 
)
inline

Replaces a given pattern by a replacement string.

Parameters
patternThe pattern to search for replacing.
replacementThe replacement string for all matches.
Returns
A reference to this instance.

This is an extension to the C++ standard operations

◆ Split() [1/2]

template<class C , class A >
BasicString< C, A >::Tokens Arp::Base::Core::BasicString< C, A >::Split ( CharType  delimiter,
bool  trimTokens = true,
bool  removeEmptyTokens = true 
) const
inline

Splits this string into tokens using the specified delimiter characters (multiple).

Parameters
delimiterThe delimiter character to search for when splitting this string.
trimTokensIf set to true, the resulting tokens are trimmed from white-spaces.
removeEmptyTokensIf set to true, the empty tokens are omitted.
Returns
A container of string containing the resulting tokens.

◆ Split() [2/2]

template<class C , class A >
BasicString< C, A >::Tokens Arp::Base::Core::BasicString< C, A >::Split ( std::span< const CharType delimiters,
bool  trimTokens = true,
bool  removeEmptyTokens = true 
) const
inline

Splits this string into tokens using the specified delimiter characters (multiple).

Parameters
delimitersThe delimiters to search for when splitting this string.
trimTokensIf set to true, the resulting tokens are trimmed from white-spaces.
removeEmptyTokensIf set to true, the empty tokens are omitted.
Returns
A container of string containing the resulting tokens.

◆ SplitByWord()

template<class C , class A >
BasicString< C, A >::Tokens Arp::Base::Core::BasicString< C, A >::SplitByWord ( const SelfType delimiter,
bool  trimTokens = true,
bool  removeEmptyTokens = true 
) const
inline

Splits this string into tokens using the specified (single) delimiter string.

Parameters
delimiterThe (single) delimiter string to search for when splitting this string.
trimTokensIf set to true, the resulting tokens are trimmed from white-spaces.
removeEmptyTokensIf set to true, the empty tokens are omitted.
Returns
A container of strings containing the resulting tokens.

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