An read-only view over a string (to avoid including Strings library when parsing is not needed). More...
#include <StringSpan.h>
Public Member Functions | |
constexpr | StringSpan (StringEncoding encoding=StringEncoding::Ascii) |
Construct an empty StringView. | |
constexpr | StringSpan (Span< const char > text, bool nullTerm, StringEncoding encoding) |
Construct a StringView from a Span of bytes. | |
template<size_t N> | |
constexpr | StringSpan (const char(&str)[N]) |
Constructs a StringView with a null terminated string terminal. | |
constexpr bool | operator== (const StringSpan other) const |
Span< const char > | toCharSpan () const |
Obtain a const char Span from this StringView. | |
constexpr bool | isEmpty () const |
Return true if StringView is empty. | |
constexpr bool | isNullTerminated () const |
Check if StringView is immediately followed by a null termination character. | |
constexpr size_t | sizeInBytes () const |
Get size of the StringView in bytes. | |
constexpr StringEncoding | getEncoding () const |
Get encoding of this StringView. | |
constexpr const char * | bytesWithoutTerminator () const |
Directly access the memory of this StringView. | |
auto | getNullTerminatedNative () const |
Directly access the memory of this null terminated-StringView. | |
Static Public Member Functions | |
static constexpr StringSpan | fromNullTerminated (const char *text, StringEncoding encoding) |
Constructs a StringView from a null terminated string. | |
Protected Attributes | ||
union { | ||
const char * text | ||
}; | ||
size_t | textSizeInBytes: sizeof(size_t) * 8 - NumOptionBits | |
size_t | encoding: 2 | |
size_t | hasNullTerm: 1 | |
Static Protected Attributes | |
static constexpr size_t | NumOptionBits = 3 |
static constexpr size_t | MaxLength = (~static_cast<size_t>(0)) >> NumOptionBits |
Friends | |
struct | StringView |
An read-only view over a string (to avoid including Strings library when parsing is not needed).
The most common use case is to pass it in and out of OS API as is for file system paths. Some libraries check the encoding and eventually convert the string to a different one when using specific OS api.
|
inlineconstexpr |
Construct an empty StringView.
|
inlineconstexpr |
Construct a StringView from a Span of bytes.
text | The span containing the text EXCLUDING eventual null terminator |
nullTerm | true if a null terminator code point is expected to be found after Span. On ASCII and UTF8 this is 1 byte, on UTF16 it must be 2 bytes. |
encoding | The encoding of the text contained in this StringView |
|
inlineconstexpr |
Constructs a StringView with a null terminated string terminal.
|
inlinenodiscardconstexpr |
Directly access the memory of this StringView.
|
inlinestaticconstexpr |
Constructs a StringView from a null terminated string.
|
inlinenodiscardconstexpr |
Get encoding of this StringView.
|
inlinenodiscard |
Directly access the memory of this null terminated-StringView.
const wchar_t*
. On other platforms return type will be const char*
.
|
inlinenodiscardconstexpr |
Return true if StringView is empty.
|
inlinenodiscardconstexpr |
Check if StringView is immediately followed by a null termination character.
|
inlinenodiscardconstexpr |
Get size of the StringView in bytes.
|
inlinenodiscard |
Obtain a const char
Span from this StringView.