xentara-utils v1.2.1
Xentara utilities library
Loading...
Searching...
No Matches
xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits > Class Template Reference

A string that uses a statically allocated buffer for the data. More...

#include <string/StaticString.hpp>

Public Types

using traits_type = CharTraits
 The character traits.
 
using value_type = Char
 The character type.
 
using size_type = std::size_t
 The type used for sizes.
 
using difference_type = std::ptrdiff_t
 The type used for distances.
 
using reference = value_type &
 A reference to an character.
 
using const_reference = const value_type &
 A const reference to an character.
 
using pointer = value_type *
 A pointer to an character.
 
using const_pointer = const value_type *
 A const pointer to an character.
 
using iterator = core::ContiguousIterator< pointer, BasicStaticString >
 An iterator.
 
using const_iterator = core::ContiguousIterator< const_pointer, BasicStaticString >
 A const iterator.
 
using reverse_iterator = std::reverse_iterator< iterator >
 An iterator for iterating in reverse order.
 
using const_reverse_iterator = std::reverse_iterator< const_iterator >
 A const iterator for iterating in reverse order.
 

Public Member Functions

constexpr BasicStaticString () noexcept
 Constructor for an empty string.
 
Character Access
constexpr operator std::basic_string_view< Char, CharTraits > () const noexcept
 conversion to a string view
 
template<typename Allocator >
constexpr operator std::basic_string< Char, CharTraits, Allocator > () const noexcept
 conversion to an std::string
 
constexpr auto view () const noexcept -> std::basic_string_view< Char, CharTraits >
 Gets the data as a string view.
 
template<typename Allocator = std::allocator<Char>>
constexpr auto str (const Allocator &allocator=Allocator()) const noexcept -> std::basic_string< Char, CharTraits, Allocator >
 Gets the data as an std::string.
 
constexpr auto at (size_type index) const -> const_reference
 Accesses the character at a certain index.
 
constexpr auto at (size_type index) -> reference
 Accesses the character at a certain index.
 
constexpr auto operator[] (size_type index) const noexcept -> const_reference
 Subscript operator.
 
constexpr auto operator[] (size_type index) noexcept -> reference
 Subscript operator.
 
constexpr auto front () const noexcept -> const_reference
 Returns the first character.
 
constexpr auto front () noexcept -> reference
 Returns the first character.
 
constexpr auto back () const noexcept -> const_reference
 Returns the last character.
 
constexpr auto back () noexcept -> reference
 Returns the last character.
 
constexpr auto data () const noexcept -> const Char *
 Gets a pointer to the data.
 
constexpr auto data () noexcept -> Char *
 Gets a pointer to the data.
 
constexpr auto c_str () const noexcept -> const Char *
 Gets the data as a null terminated string.
 
Iterators
constexpr auto begin () noexcept -> iterator
 Creates a begin iterator.
 
constexpr auto begin () const noexcept -> const_iterator
 Creates a begin iterator.
 
constexpr auto cbegin () const noexcept -> const_iterator
 Creates a begin iterator.
 
constexpr auto end () noexcept -> iterator
 Creates an end iterator.
 
constexpr auto end () const noexcept -> const_iterator
 Creates an end iterator.
 
constexpr auto cend () const noexcept -> const_iterator
 Creates an end iterator.
 
constexpr auto rbegin () noexcept -> reverse_iterator
 Creates a reverse begin iterator.
 
constexpr auto rbegin () const noexcept -> const_reverse_iterator
 Creates a reverse begin iterator.
 
constexpr auto crbegin () const noexcept -> const_reverse_iterator
 Creates a reverse begin iterator.
 
constexpr auto rend () noexcept -> reverse_iterator
 Creates a reverse end iterator.
 
constexpr auto rend () const noexcept -> const_reverse_iterator
 Creates a reverse end iterator.
 
constexpr auto crend () const noexcept -> const_reverse_iterator
 Creates a reverse end iterator.
 
Buffer Access
constexpr auto buffer () noexcept -> std::span< Char >
 Returns the internal buffer.
 
constexpr auto bufferEnd () noexcept -> iterator
 Creates an end iterator for the entire buffer.
 
constexpr auto bufferEnd () const noexcept -> const_iterator
 Creates an end iterator for the entire buffer.
 
constexpr auto cBufferEnd () const noexcept -> const_iterator
 Creates an end iterator for the entire buffer.
 
constexpr auto rBufferBegin () noexcept -> reverse_iterator
 Creates a reverse begin iterator for the entire buffer.
 
constexpr auto rBufferBegin () const noexcept -> const_reverse_iterator
 Creates a reverse begin iterator for the entire buffer.
 
constexpr auto crBufferBegin () const noexcept -> const_reverse_iterator
 Creates a reverse begin iterator for the entire buffer.
 
Modifiers
constexpr auto resize (std::size_t size) noexcept -> void
 Resizes the string.
 
constexpr auto clear () noexcept -> void
 Clears the string.
 

Size and Capacity

constexpr auto empty () const noexcept -> bool
 Determines whether the string is empty.
 
constexpr auto size () const noexcept -> std::size_t
 Gets the current size.
 
constexpr auto capacity () const noexcept -> std::size_t
 Gets the capacity of the string.
 
static constexpr auto max_size () noexcept -> std::size_t
 Gets the maximum size.
 

Detailed Description

template<tools::CharType Char, std::size_t kCapacity, typename CharTraits = std::char_traits<Char>>
class xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits >

A string that uses a statically allocated buffer for the data.

This class behaves just like std::string, but doesn't require any heap allocation. Instead, the string data is allocated in a static buffer of a fixed size.

Template Parameters
CharThe character type
kCapacityThe capacity of the string
CharTraitsThe char traits used for interacting with the standard C++ library

Member Typedef Documentation

◆ const_iterator

template<tools::CharType Char, std::size_t kCapacity, typename CharTraits = std::char_traits<Char>>
using xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits >::const_iterator = core::ContiguousIterator<const_pointer, BasicStaticString>

A const iterator.

◆ const_pointer

template<tools::CharType Char, std::size_t kCapacity, typename CharTraits = std::char_traits<Char>>
using xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits >::const_pointer = const value_type *

A const pointer to an character.

◆ const_reference

template<tools::CharType Char, std::size_t kCapacity, typename CharTraits = std::char_traits<Char>>
using xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits >::const_reference = const value_type &

A const reference to an character.

◆ const_reverse_iterator

template<tools::CharType Char, std::size_t kCapacity, typename CharTraits = std::char_traits<Char>>
using xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits >::const_reverse_iterator = std::reverse_iterator<const_iterator>

A const iterator for iterating in reverse order.

◆ difference_type

template<tools::CharType Char, std::size_t kCapacity, typename CharTraits = std::char_traits<Char>>
using xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits >::difference_type = std::ptrdiff_t

The type used for distances.

◆ iterator

template<tools::CharType Char, std::size_t kCapacity, typename CharTraits = std::char_traits<Char>>
using xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits >::iterator = core::ContiguousIterator<pointer, BasicStaticString>

An iterator.

◆ pointer

template<tools::CharType Char, std::size_t kCapacity, typename CharTraits = std::char_traits<Char>>
using xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits >::pointer = value_type *

A pointer to an character.

◆ reference

template<tools::CharType Char, std::size_t kCapacity, typename CharTraits = std::char_traits<Char>>
using xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits >::reference = value_type &

A reference to an character.

◆ reverse_iterator

template<tools::CharType Char, std::size_t kCapacity, typename CharTraits = std::char_traits<Char>>
using xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits >::reverse_iterator = std::reverse_iterator<iterator>

An iterator for iterating in reverse order.

◆ size_type

template<tools::CharType Char, std::size_t kCapacity, typename CharTraits = std::char_traits<Char>>
using xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits >::size_type = std::size_t

The type used for sizes.

◆ traits_type

template<tools::CharType Char, std::size_t kCapacity, typename CharTraits = std::char_traits<Char>>
using xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits >::traits_type = CharTraits

The character traits.

◆ value_type

template<tools::CharType Char, std::size_t kCapacity, typename CharTraits = std::char_traits<Char>>
using xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits >::value_type = Char

The character type.

Constructor & Destructor Documentation

◆ BasicStaticString()

template<tools::CharType Char, std::size_t kCapacity, typename CharTraits = std::char_traits<Char>>
constexpr xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits >::BasicStaticString ( )
constexprnoexcept

Constructor for an empty string.

Member Function Documentation

◆ at() [1/2]

template<tools::CharType Char, std::size_t kCapacity, typename CharTraits = std::char_traits<Char>>
constexpr auto xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits >::at ( size_type  index) -> reference
constexpr

Accesses the character at a certain index.

Parameters
indexThe index
Returns
A reference to the character at the given index
Exceptions
std::out_of_rangeindex is out of range

◆ at() [2/2]

template<tools::CharType Char, std::size_t kCapacity, typename CharTraits = std::char_traits<Char>>
constexpr auto xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits >::at ( size_type  index) const -> const_reference
constexpr

Accesses the character at a certain index.

Parameters
indexThe index
Returns
A reference to the character at the given index
Exceptions
std::out_of_rangeindex is out of range

◆ back() [1/2]

template<tools::CharType Char, std::size_t kCapacity, typename CharTraits = std::char_traits<Char>>
constexpr auto xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits >::back ( ) const -> const_reference
constexprnoexcept

Returns the last character.

Note
Must not be called on an empty string
Returns
A reference to last character

◆ back() [2/2]

template<tools::CharType Char, std::size_t kCapacity, typename CharTraits = std::char_traits<Char>>
constexpr auto xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits >::back ( ) -> reference
constexprnoexcept

Returns the last character.

Note
Must not be called on an empty string
Returns
A reference to last character

◆ begin() [1/2]

template<tools::CharType Char, std::size_t kCapacity, typename CharTraits >
constexpr auto xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits >::begin ( ) const -> const_iterator
constexprnoexcept

Creates a begin iterator.

Returns
An iterator pointing at the first character, or end(), if the data is empty

◆ begin() [2/2]

template<tools::CharType Char, std::size_t kCapacity, typename CharTraits >
constexpr auto xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits >::begin ( ) -> iterator
constexprnoexcept

Creates a begin iterator.

Returns
An iterator pointing at the first character, or end(), if the data is empty

◆ buffer()

template<tools::CharType Char, std::size_t kCapacity, typename CharTraits = std::char_traits<Char>>
constexpr auto xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits >::buffer ( ) -> std::span<Char>
constexprnoexcept

Returns the internal buffer.

The returned buffer has enough room for capacity() characters. There is also room one character past the end of the buffer for a terminating null character.

It is safe to write past size(), but not past capacity() + 1. If you write data past size(), you must subsequently resize the string using resize(), or the terminating null character will be lost.

Returns
The buffer.

◆ bufferEnd() [1/2]

template<tools::CharType Char, std::size_t kCapacity, typename CharTraits >
constexpr auto xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits >::bufferEnd ( ) const -> const_iterator
constexprnoexcept

Creates an end iterator for the entire buffer.

Returns
An iterator pointing at the position past the last position in the buffer

◆ bufferEnd() [2/2]

template<tools::CharType Char, std::size_t kCapacity, typename CharTraits >
constexpr auto xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits >::bufferEnd ( ) -> iterator
constexprnoexcept

Creates an end iterator for the entire buffer.

Returns
An iterator pointing at the position past the last position in the buffer

◆ c_str()

template<tools::CharType Char, std::size_t kCapacity, typename CharTraits = std::char_traits<Char>>
constexpr auto xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits >::c_str ( ) const -> const Char *
constexprnoexcept

Gets the data as a null terminated string.

Returns
The data as a null terminated string.

◆ capacity()

template<tools::CharType Char, std::size_t kCapacity, typename CharTraits = std::char_traits<Char>>
constexpr auto xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits >::capacity ( ) const -> std::size_t
constexprnoexcept

Gets the capacity of the string.

Returns
The capacity, as defined by the kCapacity template parameter.

◆ cbegin()

template<tools::CharType Char, std::size_t kCapacity, typename CharTraits >
constexpr auto xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits >::cbegin ( ) const -> const_iterator
constexprnoexcept

Creates a begin iterator.

Returns
An iterator pointing at the first character, or end(), if the data is empty

◆ cBufferEnd()

template<tools::CharType Char, std::size_t kCapacity, typename CharTraits >
constexpr auto xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits >::cBufferEnd ( ) const -> const_iterator
constexprnoexcept

Creates an end iterator for the entire buffer.

Returns
An iterator pointing at the position past the last position in the buffer

◆ cend()

template<tools::CharType Char, std::size_t kCapacity, typename CharTraits >
constexpr auto xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits >::cend ( ) const -> const_iterator
constexprnoexcept

Creates an end iterator.

Returns
An iterator pointing at the position past the last character

◆ clear()

template<tools::CharType Char, std::size_t kCapacity, typename CharTraits = std::char_traits<Char>>
constexpr auto xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits >::clear ( ) -> void
constexprnoexcept

Clears the string.

◆ crbegin()

template<tools::CharType Char, std::size_t kCapacity, typename CharTraits >
constexpr auto xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits >::crbegin ( ) const -> const_reverse_iterator
constexprnoexcept

Creates a reverse begin iterator.

Returns
A reverse iterator pointing at the last character, or rend(), if the data is empty

◆ crBufferBegin()

template<tools::CharType Char, std::size_t kCapacity, typename CharTraits >
constexpr auto xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits >::crBufferBegin ( ) const -> const_reverse_iterator
constexprnoexcept

Creates a reverse begin iterator for the entire buffer.

Returns
A reverse iterator pointing at the last position in the buffer

◆ crend()

template<tools::CharType Char, std::size_t kCapacity, typename CharTraits >
constexpr auto xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits >::crend ( ) const -> const_reverse_iterator
constexprnoexcept

Creates a reverse end iterator.

Returns
A reverse iterator pointing at the position before the first character

◆ data() [1/2]

template<tools::CharType Char, std::size_t kCapacity, typename CharTraits = std::char_traits<Char>>
constexpr auto xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits >::data ( ) const -> const Char *
constexprnoexcept

Gets a pointer to the data.

Returns
A pointer to the data.

◆ data() [2/2]

template<tools::CharType Char, std::size_t kCapacity, typename CharTraits = std::char_traits<Char>>
constexpr auto xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits >::data ( ) -> Char *
constexprnoexcept

Gets a pointer to the data.

The returned pointer points to a buffer that has enough room for capacity() characters, plus a terminating null character. It is safe to write past size(), but not past capacity() + 1. If you write data past size(), you must subsequently resize the string using resize(), or the terminating null character will be lost.

Returns
A pointer to the data.

◆ empty()

template<tools::CharType Char, std::size_t kCapacity, typename CharTraits = std::char_traits<Char>>
constexpr auto xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits >::empty ( ) const -> bool
constexprnoexcept

Determines whether the string is empty.

Returns
Whether the string is empty

◆ end() [1/2]

template<tools::CharType Char, std::size_t kCapacity, typename CharTraits >
constexpr auto xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits >::end ( ) const -> const_iterator
constexprnoexcept

Creates an end iterator.

Returns
An iterator pointing at the position past the last character

◆ end() [2/2]

template<tools::CharType Char, std::size_t kCapacity, typename CharTraits >
constexpr auto xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits >::end ( ) -> iterator
constexprnoexcept

Creates an end iterator.

Returns
An iterator pointing at the position past the last character

◆ front() [1/2]

template<tools::CharType Char, std::size_t kCapacity, typename CharTraits = std::char_traits<Char>>
constexpr auto xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits >::front ( ) const -> const_reference
constexprnoexcept

Returns the first character.

Note
Must not be called on an empty string
Returns
A reference to first character

◆ front() [2/2]

template<tools::CharType Char, std::size_t kCapacity, typename CharTraits = std::char_traits<Char>>
constexpr auto xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits >::front ( ) -> reference
constexprnoexcept

Returns the first character.

Note
Must not be called on an empty string
Returns
A reference to first character

◆ max_size()

template<tools::CharType Char, std::size_t kCapacity, typename CharTraits = std::char_traits<Char>>
static constexpr auto xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits >::max_size ( ) -> std::size_t
staticconstexprnoexcept

Gets the maximum size.

Returns
The maximum size, as defined by the kCapacity template parameter.

◆ operator std::basic_string< Char, CharTraits, Allocator >()

template<tools::CharType Char, std::size_t kCapacity, typename CharTraits = std::char_traits<Char>>
template<typename Allocator >
constexpr xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits >::operator std::basic_string< Char, CharTraits, Allocator > ( ) const
constexprnoexcept

conversion to an std::string

Returns
A copy to the data

◆ operator std::basic_string_view< Char, CharTraits >()

template<tools::CharType Char, std::size_t kCapacity, typename CharTraits = std::char_traits<Char>>
constexpr xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits >::operator std::basic_string_view< Char, CharTraits > ( ) const
constexprnoexcept

conversion to a string view

Returns
A view to the data

◆ operator[]() [1/2]

template<tools::CharType Char, std::size_t kCapacity, typename CharTraits = std::char_traits<Char>>
constexpr auto xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits >::operator[] ( size_type  index) const -> const_reference
constexprnoexcept

Subscript operator.

Returns a reference to the character at a certain index

Parameters
indexThe index
Returns
A reference to the value at the given offset

◆ operator[]() [2/2]

template<tools::CharType Char, std::size_t kCapacity, typename CharTraits = std::char_traits<Char>>
constexpr auto xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits >::operator[] ( size_type  index) -> reference
constexprnoexcept

Subscript operator.

Returns a reference to the character at a certain index

Parameters
indexThe index
Returns
A reference to the value at the given offset

◆ rbegin() [1/2]

template<tools::CharType Char, std::size_t kCapacity, typename CharTraits >
constexpr auto xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits >::rbegin ( ) const -> const_reverse_iterator
constexprnoexcept

Creates a reverse begin iterator.

Returns
A reverse iterator pointing at the last character, or rend(), if the data is empty

◆ rbegin() [2/2]

template<tools::CharType Char, std::size_t kCapacity, typename CharTraits >
constexpr auto xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits >::rbegin ( ) -> reverse_iterator
constexprnoexcept

Creates a reverse begin iterator.

Returns
A reverse iterator pointing at the last character, or rend(), if the data is empty

◆ rBufferBegin() [1/2]

template<tools::CharType Char, std::size_t kCapacity, typename CharTraits >
constexpr auto xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits >::rBufferBegin ( ) const -> const_reverse_iterator
constexprnoexcept

Creates a reverse begin iterator for the entire buffer.

Returns
A reverse iterator pointing at the last position in the buffer

◆ rBufferBegin() [2/2]

template<tools::CharType Char, std::size_t kCapacity, typename CharTraits >
constexpr auto xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits >::rBufferBegin ( ) -> reverse_iterator
constexprnoexcept

Creates a reverse begin iterator for the entire buffer.

Returns
A reverse iterator pointing at the last position in the buffer

◆ rend() [1/2]

template<tools::CharType Char, std::size_t kCapacity, typename CharTraits >
constexpr auto xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits >::rend ( ) const -> const_reverse_iterator
constexprnoexcept

Creates a reverse end iterator.

Returns
A reverse iterator pointing at the position before the first character

◆ rend() [2/2]

template<tools::CharType Char, std::size_t kCapacity, typename CharTraits >
constexpr auto xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits >::rend ( ) -> reverse_iterator
constexprnoexcept

Creates a reverse end iterator.

Returns
A reverse iterator pointing at the position before the first character

◆ resize()

template<tools::CharType Char, std::size_t kCapacity, typename CharTraits = std::char_traits<Char>>
constexpr auto xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits >::resize ( std::size_t  size) -> void
constexprnoexcept

Resizes the string.

This function only sets the size, and does not modify any data, except for setting the terminating null character. The actual string data mujst have been written to the buffer already using data() or buffer().

Parameters
sizeThe new size. Must not exceed the capacity.

◆ size()

template<tools::CharType Char, std::size_t kCapacity, typename CharTraits = std::char_traits<Char>>
constexpr auto xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits >::size ( ) const -> std::size_t
constexprnoexcept

Gets the current size.

Returns
The curent size

◆ str()

template<tools::CharType Char, std::size_t kCapacity, typename CharTraits = std::char_traits<Char>>
template<typename Allocator = std::allocator<Char>>
constexpr auto xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits >::str ( const Allocator &  allocator = Allocator()) const -> std::basic_string<Char, CharTraits, Allocator>
constexprnoexcept

Gets the data as an std::string.

Returns
The data as a null terminated string.

◆ view()

template<tools::CharType Char, std::size_t kCapacity, typename CharTraits = std::char_traits<Char>>
constexpr auto xentara::utils::string::BasicStaticString< Char, kCapacity, CharTraits >::view ( ) const -> std::basic_string_view<Char, CharTraits>
constexprnoexcept

Gets the data as a string view.

Returns
The data as a string view.