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

Constant string view container template. Keeps pointer to string and its length. More...

#include <StringView.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 = const_pointer
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

 BasicStringView ()=default
 BasicStringView (const BasicStringView &)=default
 BasicStringView (BasicStringView &&)=default
BasicStringView & operator= (const BasicStringView &)=default
BasicStringView & operator= (BasicStringView &&)=default
 BasicStringView (const_pointer str)
 Initializes the string view with the specified null-terminated string.
 BasicStringView (const_pointer str, size_type len)
 Initializes the string view with a pointer to the data and size.
template<template< class, class, class > class TString, class Allocator>
 BasicStringView (const TString< TChar, Traits, Allocator > &str)
 Initializes the string view with another templated string class. This would usually be std::basic_string.
bool empty () const noexcept
 Returns true if this string view 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 view.
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.
BasicStringView substr (size_type pos=0, size_type count=npos) const
 Returns a sub-view of this string view.
int compare (const BasicStringView &str) const
 Compares this string with the specified string in a strict-weak-order (SWO).
int compare (size_type pos1, size_type count1, const BasicStringView &str) const
 Compares a sub-view of this string with the specified string.
int compare (size_type pos1, size_type count1, const BasicStringView &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=BasicStringView::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=BasicStringView::npos) const noexcept
size_type find_last_not_of (const TChar *sequence, size_type pos, size_type count) const noexcept
const_reference operator[] (size_type pos) const

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>>
class LLGL::BasicStringView< TChar, Traits >

Constant string view container template. Keeps pointer to string and its length.

Remarks
This does not provide a null-terminated string.
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>>
using LLGL::BasicStringView< TChar, Traits >::const_iterator = const TChar*

◆ const_pointer

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

◆ const_reference

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

◆ const_reverse_iterator

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

◆ difference_type

template<typename TChar, typename Traits = std::char_traits<TChar>>
using LLGL::BasicStringView< TChar, Traits >::difference_type = std::ptrdiff_t

◆ iterator

template<typename TChar, typename Traits = std::char_traits<TChar>>
using LLGL::BasicStringView< TChar, Traits >::iterator = const_iterator

◆ pointer

template<typename TChar, typename Traits = std::char_traits<TChar>>
using LLGL::BasicStringView< TChar, Traits >::pointer = const_pointer

◆ reference

template<typename TChar, typename Traits = std::char_traits<TChar>>
using LLGL::BasicStringView< TChar, Traits >::reference = const_reference

◆ reverse_iterator

template<typename TChar, typename Traits = std::char_traits<TChar>>
using LLGL::BasicStringView< TChar, Traits >::reverse_iterator = const_reverse_iterator

◆ size_type

template<typename TChar, typename Traits = std::char_traits<TChar>>
using LLGL::BasicStringView< TChar, Traits >::size_type = std::size_t

◆ value_type

template<typename TChar, typename Traits = std::char_traits<TChar>>
using LLGL::BasicStringView< TChar, Traits >::value_type = const TChar

Constructor & Destructor Documentation

◆ BasicStringView() [1/6]

template<typename TChar, typename Traits = std::char_traits<TChar>>
LLGL::BasicStringView< TChar, Traits >::BasicStringView ( )
default

◆ BasicStringView() [2/6]

template<typename TChar, typename Traits = std::char_traits<TChar>>
LLGL::BasicStringView< TChar, Traits >::BasicStringView ( const BasicStringView< TChar, Traits > & )
default

◆ BasicStringView() [3/6]

template<typename TChar, typename Traits = std::char_traits<TChar>>
LLGL::BasicStringView< TChar, Traits >::BasicStringView ( BasicStringView< TChar, Traits > && )
default

◆ BasicStringView() [4/6]

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

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

◆ BasicStringView() [5/6]

template<typename TChar, typename Traits = std::char_traits<TChar>>
LLGL::BasicStringView< TChar, Traits >::BasicStringView ( const_pointer str,
size_type len )
inline

Initializes the string view with a pointer to the data and size.

◆ BasicStringView() [6/6]

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

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

Member Function Documentation

◆ at()

template<typename TChar, typename Traits = std::char_traits<TChar>>
const_reference LLGL::BasicStringView< TChar, Traits >::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>>
const_reference LLGL::BasicStringView< TChar, Traits >::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>>
const_iterator LLGL::BasicStringView< TChar, Traits >::begin ( ) const
inlinenoexcept
See also
cbegin

◆ cbegin()

template<typename TChar, typename Traits = std::char_traits<TChar>>
const_iterator LLGL::BasicStringView< TChar, Traits >::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>>
const_iterator LLGL::BasicStringView< TChar, Traits >::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.

◆ compare() [1/3]

template<typename TChar, typename Traits = std::char_traits<TChar>>
int LLGL::BasicStringView< TChar, Traits >::compare ( const BasicStringView< TChar, Traits > & 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>>
int LLGL::BasicStringView< TChar, Traits >::compare ( size_type pos1,
size_type count1,
const BasicStringView< TChar, Traits > & str ) const
inline

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

See also
compare(const BasicStringView&)

◆ compare() [3/3]

template<typename TChar, typename Traits = std::char_traits<TChar>>
int LLGL::BasicStringView< TChar, Traits >::compare ( size_type pos1,
size_type count1,
const BasicStringView< TChar, Traits > & 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 BasicStringView&)

◆ crbegin()

template<typename TChar, typename Traits = std::char_traits<TChar>>
const_reverse_iterator LLGL::BasicStringView< TChar, Traits >::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>>
const_reverse_iterator LLGL::BasicStringView< TChar, Traits >::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>>
const_pointer LLGL::BasicStringView< TChar, Traits >::data ( ) const
inlinenoexcept

Returns the raw pointer of this string view.

Remarks
This does not necessarily point to a NUL-terminated string like std::string does. A string view only covers a range from the first to the last character of a string whose memory is managed elsewhere.

◆ empty()

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

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

See also
size
length

◆ end()

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

◆ find()

template<typename TChar, typename Traits = std::char_traits<TChar>>
size_type LLGL::BasicStringView< TChar, Traits >::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>>
size_type LLGL::BasicStringView< TChar, Traits >::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>>
size_type LLGL::BasicStringView< TChar, Traits >::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>>
size_type LLGL::BasicStringView< TChar, Traits >::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>>
size_type LLGL::BasicStringView< TChar, Traits >::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>>
size_type LLGL::BasicStringView< TChar, Traits >::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>>
size_type LLGL::BasicStringView< TChar, Traits >::find_last_not_of ( const TChar * sequence,
size_type pos = BasicStringView< TChar, Traits >::npos ) const
inlinenoexcept

◆ find_last_of() [1/2]

template<typename TChar, typename Traits = std::char_traits<TChar>>
size_type LLGL::BasicStringView< TChar, Traits >::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>>
size_type LLGL::BasicStringView< TChar, Traits >::find_last_of ( const TChar * sequence,
size_type pos = BasicStringView< TChar, Traits >::npos ) const
inlinenoexcept

◆ front()

template<typename TChar, typename Traits = std::char_traits<TChar>>
const_reference LLGL::BasicStringView< TChar, Traits >::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>>
size_type LLGL::BasicStringView< TChar, Traits >::length ( ) const
inlinenoexcept

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

◆ operator=() [1/2]

template<typename TChar, typename Traits = std::char_traits<TChar>>
BasicStringView & LLGL::BasicStringView< TChar, Traits >::operator= ( BasicStringView< TChar, Traits > && )
default

◆ operator=() [2/2]

template<typename TChar, typename Traits = std::char_traits<TChar>>
BasicStringView & LLGL::BasicStringView< TChar, Traits >::operator= ( const BasicStringView< TChar, Traits > & )
default

◆ operator[]()

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

◆ rbegin()

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

◆ rend()

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

◆ size()

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

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

See also
length

◆ substr()

template<typename TChar, typename Traits = std::char_traits<TChar>>
BasicStringView LLGL::BasicStringView< TChar, Traits >::substr ( size_type pos = 0,
size_type count = npos ) const
inline

Returns a sub-view of this string view.

Parameters
[in]posOptional zero-based position to the beginning of this string. By default 0.
[in]countOptional length of the sub-view. This will be clamped to the size of this string minus the input position pos. By default npos.
Returns
Empty string view if pos is out of bounds.

Member Data Documentation

◆ npos

template<typename TChar, typename Traits = std::char_traits<TChar>>
size_type LLGL::BasicStringView< TChar, Traits >::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: