LLGL 0.05 Beta
Loading...
Searching...
No Matches
LLGL::BasicStringLiteral< TChar, Traits, Allocator > Class Template Reference

Constant string container template to either reference a compile-time string literal (lightweight) or own a dynamic string (non-mutable). More...

#include <StringLiteral.h>

Public Types

using value_type = const TChar
using size_type = std::size_t
using difference_type = std::ptrdiff_t
using const_reference = const TChar&
using reference = const_reference
using const_pointer = const TChar*
using pointer = TChar*
using const_iterator = const TChar*
using iterator = const_iterator
using const_reverse_iterator = std::reverse_iterator<const_iterator>
using reverse_iterator = const_reverse_iterator

Public Member Functions

 BasicStringLiteral ()
 Initializes an empty string literal.
 BasicStringLiteral (const BasicStringLiteral &rhs)
 Initializes the string with a copy of the input string.
 BasicStringLiteral (BasicStringLiteral &&rhs) noexcept
 Moves ownership from the input string literal to the newly constructed string literal.
BasicStringLiteral & operator= (const BasicStringLiteral &rhs)
BasicStringLiteral & operator= (BasicStringLiteral &&rhs)
 BasicStringLiteral (const_pointer str)
 Initializes the string literal as a reference (non-managed).
 BasicStringLiteral (const_pointer str, CopyTag)
 Initializes the string literal as a managed copy of the input string.
 BasicStringLiteral (const BasicStringView< TChar, Traits > &str)
 Initializes the string literal with the specified null-terminated string.
template<template< class, class, class > class TString>
 BasicStringLiteral (const TString< TChar, Traits, Allocator > &str)
 Initializes the string literal with another templated string class. This would usually be std::basic_string.
 ~BasicStringLiteral ()
 Destructs the string literal. If this is a managed string, it will delete its internal memory.
bool empty () const noexcept
 Returns true if this string literal is empty, i.e. size() and length() return 0.
size_type size () const noexcept
 Returns the length of this string. This is equivalent to length().
size_type length () const noexcept
 Returns the length of this string. This is equivalent to size().
const_pointer data () const noexcept
 Returns the raw pointer of this string literal.
const_pointer c_str () const noexcept
 Returns the raw pointer of this string literal.
const_reference at (size_type pos) const
 Returns a constant reference to the character at the specified zero-based position.
const_reference front () const
 Returns a constant reference to the first character of this string.
const_reference back () const
 Returns a constant reference to the last character of this string.
const_iterator begin () const noexcept
const_iterator cbegin () const noexcept
 Returns constant iterator to the beginning of this string.
const_reverse_iterator rbegin () const
const_reverse_iterator crbegin () const
 Returns constant reverse iterator to the end of this string.
const_iterator end () const noexcept
const_iterator cend () const noexcept
 Returns constant iterator to the end of this string.
const_reverse_iterator rend () const
const_reverse_iterator crend () const
 Returns constant reverse iterator to the beginning of this string.
int compare (const BasicStringLiteral &str) const
 Compares this string with the specified string in a strict-weak-order (SWO).
int compare (size_type pos1, size_type count1, const BasicStringLiteral &str) const
 Compares a sub-view of this string with the specified string.
int compare (size_type pos1, size_type count1, const BasicStringLiteral &str, size_type pos2, size_type count2=npos) const
 Compares a sub-view of this string with a sub-view of the specified string.
size_type find (TChar chr, size_type pos=0) const noexcept
size_type find_first_of (const TChar *sequence, size_type pos=0) const noexcept
size_type find_first_of (const TChar *sequence, size_type pos, size_type count) const noexcept
size_type find_first_not_of (const TChar *sequence, size_type pos=0) const noexcept
size_type find_first_not_of (const TChar *sequence, size_type pos, size_type count) const noexcept
size_type find_last_of (const TChar *sequence, size_type pos=BasicStringLiteral::npos) const noexcept
size_type find_last_of (const TChar *sequence, size_type pos, size_type count) const noexcept
size_type find_last_not_of (const TChar *sequence, size_type pos=BasicStringLiteral::npos) const noexcept
size_type find_last_not_of (const TChar *sequence, size_type pos, size_type count) const noexcept
void clear ()
 Clears this string literal by making it a reference to the empty string.
const_reference operator[] (size_type pos) const
 operator BasicStringView< TChar, Traits > () const
 Implicitly converts this string literal as string view.

Static Public Attributes

static constexpr size_type npos = size_type(-1)
 Constant value for an invalid position. This is the largest possible value for size_type.

Detailed Description

template<typename TChar, typename Traits = std::char_traits<TChar>, typename Allocator = std::allocator<TChar>>
class LLGL::BasicStringLiteral< TChar, Traits, Allocator >

Constant string container template to either reference a compile-time string literal (lightweight) or own a dynamic string (non-mutable).

Remarks
This provides a null-terminated string and serves as a lightweight representation for a string that is not meant to change once assigned.
Template Parameters
TCharSpecifies the string character type.
TraitsSpecifies the character traits. By default std::char_traits<TChar>.

Member Typedef Documentation

◆ const_iterator

template<typename TChar, typename Traits = std::char_traits<TChar>, typename Allocator = std::allocator<TChar>>
using LLGL::BasicStringLiteral< TChar, Traits, Allocator >::const_iterator = const TChar*

◆ const_pointer

template<typename TChar, typename Traits = std::char_traits<TChar>, typename Allocator = std::allocator<TChar>>
using LLGL::BasicStringLiteral< TChar, Traits, Allocator >::const_pointer = const TChar*

◆ const_reference

template<typename TChar, typename Traits = std::char_traits<TChar>, typename Allocator = std::allocator<TChar>>
using LLGL::BasicStringLiteral< TChar, Traits, Allocator >::const_reference = const TChar&

◆ const_reverse_iterator

template<typename TChar, typename Traits = std::char_traits<TChar>, typename Allocator = std::allocator<TChar>>
using LLGL::BasicStringLiteral< TChar, Traits, Allocator >::const_reverse_iterator = std::reverse_iterator<const_iterator>

◆ difference_type

template<typename TChar, typename Traits = std::char_traits<TChar>, typename Allocator = std::allocator<TChar>>
using LLGL::BasicStringLiteral< TChar, Traits, Allocator >::difference_type = std::ptrdiff_t

◆ iterator

template<typename TChar, typename Traits = std::char_traits<TChar>, typename Allocator = std::allocator<TChar>>
using LLGL::BasicStringLiteral< TChar, Traits, Allocator >::iterator = const_iterator

◆ pointer

template<typename TChar, typename Traits = std::char_traits<TChar>, typename Allocator = std::allocator<TChar>>
using LLGL::BasicStringLiteral< TChar, Traits, Allocator >::pointer = TChar*

◆ reference

template<typename TChar, typename Traits = std::char_traits<TChar>, typename Allocator = std::allocator<TChar>>
using LLGL::BasicStringLiteral< TChar, Traits, Allocator >::reference = const_reference

◆ reverse_iterator

template<typename TChar, typename Traits = std::char_traits<TChar>, typename Allocator = std::allocator<TChar>>
using LLGL::BasicStringLiteral< TChar, Traits, Allocator >::reverse_iterator = const_reverse_iterator

◆ size_type

template<typename TChar, typename Traits = std::char_traits<TChar>, typename Allocator = std::allocator<TChar>>
using LLGL::BasicStringLiteral< TChar, Traits, Allocator >::size_type = std::size_t

◆ value_type

template<typename TChar, typename Traits = std::char_traits<TChar>, typename Allocator = std::allocator<TChar>>
using LLGL::BasicStringLiteral< TChar, Traits, Allocator >::value_type = const TChar

Constructor & Destructor Documentation

◆ BasicStringLiteral() [1/7]

template<typename TChar, typename Traits = std::char_traits<TChar>, typename Allocator = std::allocator<TChar>>
LLGL::BasicStringLiteral< TChar, Traits, Allocator >::BasicStringLiteral ( )
inline

Initializes an empty string literal.

◆ BasicStringLiteral() [2/7]

template<typename TChar, typename Traits = std::char_traits<TChar>, typename Allocator = std::allocator<TChar>>
LLGL::BasicStringLiteral< TChar, Traits, Allocator >::BasicStringLiteral ( const BasicStringLiteral< TChar, Traits, Allocator > & rhs)
inline

Initializes the string with a copy of the input string.

Remarks
This either makes a lightweight copy of the reference or allocates a new managed string.

◆ BasicStringLiteral() [3/7]

template<typename TChar, typename Traits = std::char_traits<TChar>, typename Allocator = std::allocator<TChar>>
LLGL::BasicStringLiteral< TChar, Traits, Allocator >::BasicStringLiteral ( BasicStringLiteral< TChar, Traits, Allocator > && rhs)
inlinenoexcept

Moves ownership from the input string literal to the newly constructed string literal.

◆ BasicStringLiteral() [4/7]

template<typename TChar, typename Traits = std::char_traits<TChar>, typename Allocator = std::allocator<TChar>>
LLGL::BasicStringLiteral< TChar, Traits, Allocator >::BasicStringLiteral ( const_pointer str)
inline

Initializes the string literal as a reference (non-managed).

◆ BasicStringLiteral() [5/7]

template<typename TChar, typename Traits = std::char_traits<TChar>, typename Allocator = std::allocator<TChar>>
LLGL::BasicStringLiteral< TChar, Traits, Allocator >::BasicStringLiteral ( const_pointer str,
CopyTag  )
inlineexplicit

Initializes the string literal as a managed copy of the input string.

◆ BasicStringLiteral() [6/7]

template<typename TChar, typename Traits = std::char_traits<TChar>, typename Allocator = std::allocator<TChar>>
LLGL::BasicStringLiteral< TChar, Traits, Allocator >::BasicStringLiteral ( const BasicStringView< TChar, Traits > & str)
inline

Initializes the string literal with the specified null-terminated string.

◆ BasicStringLiteral() [7/7]

template<typename TChar, typename Traits = std::char_traits<TChar>, typename Allocator = std::allocator<TChar>>
template<template< class, class, class > class TString>
LLGL::BasicStringLiteral< TChar, Traits, Allocator >::BasicStringLiteral ( const TString< TChar, Traits, Allocator > & str)
inline

Initializes the string literal with another templated string class. This would usually be std::basic_string.

◆ ~BasicStringLiteral()

template<typename TChar, typename Traits = std::char_traits<TChar>, typename Allocator = std::allocator<TChar>>
LLGL::BasicStringLiteral< TChar, Traits, Allocator >::~BasicStringLiteral ( )
inline

Destructs the string literal. If this is a managed string, it will delete its internal memory.

Member Function Documentation

◆ at()

template<typename TChar, typename Traits = std::char_traits<TChar>, typename Allocator = std::allocator<TChar>>
const_reference LLGL::BasicStringLiteral< TChar, Traits, Allocator >::at ( size_type pos) const
inline

Returns a constant reference to the character at the specified zero-based position.

Remarks
If the string is empty, the behavior of this function is undefined.

◆ back()

template<typename TChar, typename Traits = std::char_traits<TChar>, typename Allocator = std::allocator<TChar>>
const_reference LLGL::BasicStringLiteral< TChar, Traits, Allocator >::back ( ) const
inline

Returns a constant reference to the last character of this string.

Remarks
If the string is empty, the behavior of this function is undefined.

◆ begin()

template<typename TChar, typename Traits = std::char_traits<TChar>, typename Allocator = std::allocator<TChar>>
const_iterator LLGL::BasicStringLiteral< TChar, Traits, Allocator >::begin ( ) const
inlinenoexcept
See also
cbegin

◆ c_str()

template<typename TChar, typename Traits = std::char_traits<TChar>, typename Allocator = std::allocator<TChar>>
const_pointer LLGL::BasicStringLiteral< TChar, Traits, Allocator >::c_str ( ) const
inlinenoexcept

Returns the raw pointer of this string literal.

Remarks
This points to a NUL-terminated string like std::string does.

◆ cbegin()

template<typename TChar, typename Traits = std::char_traits<TChar>, typename Allocator = std::allocator<TChar>>
const_iterator LLGL::BasicStringLiteral< TChar, Traits, Allocator >::cbegin ( ) const
inlinenoexcept

Returns constant iterator to the beginning of this string.

Remarks
This can also be used on an empty string as long as it's not dereferenced on such a string.

◆ cend()

template<typename TChar, typename Traits = std::char_traits<TChar>, typename Allocator = std::allocator<TChar>>
const_iterator LLGL::BasicStringLiteral< TChar, Traits, Allocator >::cend ( ) const
inlinenoexcept

Returns constant iterator to the end of this string.

Remarks
This can also be used on an empty string as long as it's not dereferenced on such a string.

◆ clear()

template<typename TChar, typename Traits = std::char_traits<TChar>, typename Allocator = std::allocator<TChar>>
void LLGL::BasicStringLiteral< TChar, Traits, Allocator >::clear ( )
inline

Clears this string literal by making it a reference to the empty string.

Remarks
If this was a managed string, its internal memory will be deleted.

◆ compare() [1/3]

template<typename TChar, typename Traits = std::char_traits<TChar>, typename Allocator = std::allocator<TChar>>
int LLGL::BasicStringLiteral< TChar, Traits, Allocator >::compare ( const BasicStringLiteral< TChar, Traits, Allocator > & str) const
inline

Compares this string with the specified string in a strict-weak-order (SWO).

Returns
-1 if this string is considered to be ordered before the other string, +1 if this string is considered to be ordered after the other string, and 0 otherwise.

◆ compare() [2/3]

template<typename TChar, typename Traits = std::char_traits<TChar>, typename Allocator = std::allocator<TChar>>
int LLGL::BasicStringLiteral< TChar, Traits, Allocator >::compare ( size_type pos1,
size_type count1,
const BasicStringLiteral< TChar, Traits, Allocator > & str ) const
inline

Compares a sub-view of this string with the specified string.

See also
compare(const BasicStringLiteral&)

◆ compare() [3/3]

template<typename TChar, typename Traits = std::char_traits<TChar>, typename Allocator = std::allocator<TChar>>
int LLGL::BasicStringLiteral< TChar, Traits, Allocator >::compare ( size_type pos1,
size_type count1,
const BasicStringLiteral< TChar, Traits, Allocator > & str,
size_type pos2,
size_type count2 = npos ) const
inline

Compares a sub-view of this string with a sub-view of the specified string.

See also
compare(const BasicStringLiteral&)

◆ crbegin()

template<typename TChar, typename Traits = std::char_traits<TChar>, typename Allocator = std::allocator<TChar>>
const_reverse_iterator LLGL::BasicStringLiteral< TChar, Traits, Allocator >::crbegin ( ) const
inline

Returns constant reverse iterator to the end of this string.

Remarks
This can also be used on an empty string as long as it's not dereferenced on such a string.

◆ crend()

template<typename TChar, typename Traits = std::char_traits<TChar>, typename Allocator = std::allocator<TChar>>
const_reverse_iterator LLGL::BasicStringLiteral< TChar, Traits, Allocator >::crend ( ) const
inline

Returns constant reverse iterator to the beginning of this string.

Remarks
This can also be used on an empty string as long as it's not dereferenced on such a string.

◆ data()

template<typename TChar, typename Traits = std::char_traits<TChar>, typename Allocator = std::allocator<TChar>>
const_pointer LLGL::BasicStringLiteral< TChar, Traits, Allocator >::data ( ) const
inlinenoexcept

Returns the raw pointer of this string literal.

Remarks
This is equivalent to c_str().

◆ empty()

template<typename TChar, typename Traits = std::char_traits<TChar>, typename Allocator = std::allocator<TChar>>
bool LLGL::BasicStringLiteral< TChar, Traits, Allocator >::empty ( ) const
inlinenoexcept

Returns true if this string literal is empty, i.e. size() and length() return 0.

See also
size
length

◆ end()

template<typename TChar, typename Traits = std::char_traits<TChar>, typename Allocator = std::allocator<TChar>>
const_iterator LLGL::BasicStringLiteral< TChar, Traits, Allocator >::end ( ) const
inlinenoexcept
See also
cend

◆ find()

template<typename TChar, typename Traits = std::char_traits<TChar>, typename Allocator = std::allocator<TChar>>
size_type LLGL::BasicStringLiteral< TChar, Traits, Allocator >::find ( TChar chr,
size_type pos = 0 ) const
inlinenoexcept
Returns
Position of the first character that equals the input character starting from position pos. Otherwise, StringView::npos is returned.

◆ find_first_not_of() [1/2]

template<typename TChar, typename Traits = std::char_traits<TChar>, typename Allocator = std::allocator<TChar>>
size_type LLGL::BasicStringLiteral< TChar, Traits, Allocator >::find_first_not_of ( const TChar * sequence,
size_type pos,
size_type count ) const
inlinenoexcept

◆ find_first_not_of() [2/2]

template<typename TChar, typename Traits = std::char_traits<TChar>, typename Allocator = std::allocator<TChar>>
size_type LLGL::BasicStringLiteral< TChar, Traits, Allocator >::find_first_not_of ( const TChar * sequence,
size_type pos = 0 ) const
inlinenoexcept

◆ find_first_of() [1/2]

template<typename TChar, typename Traits = std::char_traits<TChar>, typename Allocator = std::allocator<TChar>>
size_type LLGL::BasicStringLiteral< TChar, Traits, Allocator >::find_first_of ( const TChar * sequence,
size_type pos,
size_type count ) const
inlinenoexcept

◆ find_first_of() [2/2]

template<typename TChar, typename Traits = std::char_traits<TChar>, typename Allocator = std::allocator<TChar>>
size_type LLGL::BasicStringLiteral< TChar, Traits, Allocator >::find_first_of ( const TChar * sequence,
size_type pos = 0 ) const
inlinenoexcept

◆ find_last_not_of() [1/2]

template<typename TChar, typename Traits = std::char_traits<TChar>, typename Allocator = std::allocator<TChar>>
size_type LLGL::BasicStringLiteral< TChar, Traits, Allocator >::find_last_not_of ( const TChar * sequence,
size_type pos,
size_type count ) const
inlinenoexcept

◆ find_last_not_of() [2/2]

template<typename TChar, typename Traits = std::char_traits<TChar>, typename Allocator = std::allocator<TChar>>
size_type LLGL::BasicStringLiteral< TChar, Traits, Allocator >::find_last_not_of ( const TChar * sequence,
size_type pos = BasicStringLiteral< TChar, Traits, Allocator >::npos ) const
inlinenoexcept

◆ find_last_of() [1/2]

template<typename TChar, typename Traits = std::char_traits<TChar>, typename Allocator = std::allocator<TChar>>
size_type LLGL::BasicStringLiteral< TChar, Traits, Allocator >::find_last_of ( const TChar * sequence,
size_type pos,
size_type count ) const
inlinenoexcept

◆ find_last_of() [2/2]

template<typename TChar, typename Traits = std::char_traits<TChar>, typename Allocator = std::allocator<TChar>>
size_type LLGL::BasicStringLiteral< TChar, Traits, Allocator >::find_last_of ( const TChar * sequence,
size_type pos = BasicStringLiteral< TChar, Traits, Allocator >::npos ) const
inlinenoexcept

◆ front()

template<typename TChar, typename Traits = std::char_traits<TChar>, typename Allocator = std::allocator<TChar>>
const_reference LLGL::BasicStringLiteral< TChar, Traits, Allocator >::front ( ) const
inline

Returns a constant reference to the first character of this string.

Remarks
If the string is empty, the behavior of this function is undefined.

◆ length()

template<typename TChar, typename Traits = std::char_traits<TChar>, typename Allocator = std::allocator<TChar>>
size_type LLGL::BasicStringLiteral< TChar, Traits, Allocator >::length ( ) const
inlinenoexcept

Returns the length of this string. This is equivalent to size().

◆ operator BasicStringView< TChar, Traits >()

template<typename TChar, typename Traits = std::char_traits<TChar>, typename Allocator = std::allocator<TChar>>
LLGL::BasicStringLiteral< TChar, Traits, Allocator >::operator BasicStringView< TChar, Traits > ( ) const
inline

Implicitly converts this string literal as string view.

◆ operator=() [1/2]

template<typename TChar, typename Traits = std::char_traits<TChar>, typename Allocator = std::allocator<TChar>>
BasicStringLiteral & LLGL::BasicStringLiteral< TChar, Traits, Allocator >::operator= ( BasicStringLiteral< TChar, Traits, Allocator > && rhs)
inline

◆ operator=() [2/2]

template<typename TChar, typename Traits = std::char_traits<TChar>, typename Allocator = std::allocator<TChar>>
BasicStringLiteral & LLGL::BasicStringLiteral< TChar, Traits, Allocator >::operator= ( const BasicStringLiteral< TChar, Traits, Allocator > & rhs)
inline

◆ operator[]()

template<typename TChar, typename Traits = std::char_traits<TChar>, typename Allocator = std::allocator<TChar>>
const_reference LLGL::BasicStringLiteral< TChar, Traits, Allocator >::operator[] ( size_type pos) const
inline
See also
at

◆ rbegin()

template<typename TChar, typename Traits = std::char_traits<TChar>, typename Allocator = std::allocator<TChar>>
const_reverse_iterator LLGL::BasicStringLiteral< TChar, Traits, Allocator >::rbegin ( ) const
inline
See also
crbegin

◆ rend()

template<typename TChar, typename Traits = std::char_traits<TChar>, typename Allocator = std::allocator<TChar>>
const_reverse_iterator LLGL::BasicStringLiteral< TChar, Traits, Allocator >::rend ( ) const
inline
See also
crend

◆ size()

template<typename TChar, typename Traits = std::char_traits<TChar>, typename Allocator = std::allocator<TChar>>
size_type LLGL::BasicStringLiteral< TChar, Traits, Allocator >::size ( ) const
inlinenoexcept

Returns the length of this string. This is equivalent to length().

See also
length

Member Data Documentation

◆ npos

template<typename TChar, typename Traits = std::char_traits<TChar>, typename Allocator = std::allocator<TChar>>
size_type LLGL::BasicStringLiteral< TChar, Traits, Allocator >::npos = size_type(-1)
staticconstexpr

Constant value for an invalid position. This is the largest possible value for size_type.

See also
substr

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