utf-42
Loading...
Searching...
No Matches
utf42::basic_string_view< char_t > Class Template Reference

A class that provides a lightweight, non-owning view of a string. More...

#include <utf42.h>

Public Types

using pointer = const char_t *
 Pointer type to characters.
 
using reference = const char_t &
 Reference type to characters.
 
using char_type = char_t
 Character type.
 
using size_type = std::size_t
 Type for sizes of the string.
 

Public Member Functions

constexpr basic_string_view ()
 Default constructor initializes to an empty string view.
 
constexpr basic_string_view (nullptr_t)=delete
 Deleted constructor from nullptr to avoid unintended usage.
 
template<std::size_t N>
constexpr basic_string_view (const char_t(&pStr)[N])
 Constructor from a C-style string.
 
constexpr size_type length () const noexcept
 Get the length of the string.
 
constexpr pointer data () const noexcept
 Get a pointer to the underlying character data.
 
std::basic_string< char_tstr () const
 Convert to std::basic_string for further manipulation.
 

Detailed Description

template<typename char_t>
class utf42::basic_string_view< char_t >

A class that provides a lightweight, non-owning view of a string.

This class allows for efficient string manipulation without ownership, making it particularly useful for passing around substring references or interfacing with C-style strings. It avoids unnecessary data copies and allocations, enhancing performance in string handling operations.

Warning
This class is a very simple class to achieve the purpose of this library. It does not contain any extra features. You may use your own custom containers to treat the data. On C++ > 17 the standard std::basic_string_view is used on it's stead.
Template Parameters
char_tThe character type (e.g., char, wchar_t) that the view will operate on.
Note
Only available on C++14 and C++11

Constructor & Destructor Documentation

◆ basic_string_view()

template<typename char_t >
template<std::size_t N>
constexpr utf42::basic_string_view< char_t >::basic_string_view ( const char_t(&)  pStr[N])
inlineconstexpr

Constructor from a C-style string.

Initializes the string view with a given null-terminated string and calculates its length.

Parameters
pStrPointer to the null-terminated string.

Member Function Documentation

◆ data()

template<typename char_t >
constexpr pointer utf42::basic_string_view< char_t >::data ( ) const
inlineconstexprnoexcept

Get a pointer to the underlying character data.

Returns
pointer Pointer to the character data.

◆ length()

template<typename char_t >
constexpr size_type utf42::basic_string_view< char_t >::length ( ) const
inlineconstexprnoexcept

Get the length of the string.

Returns
size_type The length of the string.

◆ str()

template<typename char_t >
std::basic_string< char_t > utf42::basic_string_view< char_t >::str ( ) const
inline

Convert to std::basic_string for further manipulation.

Returns
std::basic_string<char_t> The string representation.

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