Sane C++ Libraries: SC::StringSpan Struct Reference (original) (raw)
An read-only view over a string (to avoid including Strings library when parsing is not needed). More...
#include <[StringSpan.h](StringSpan%5F8h%5Fsource.html)>

| Public Types | |
|---|---|
| enum class | Comparison { Smaller = -1 , Equals = 0 , Bigger = 1 } |
| Result of ordering comparison done by StringSpan::compare. More... | |
| 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. | |
| Comparison | compare (StringSpan other) const |
| Ordering comparison between non-normalized StringView (operates on code points, not on utf graphemes) | |
| bool | operator== (const StringSpan other) const |
| bool | operator!= (const StringSpan other) const |
| 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. | |
| size_t | sizeInBytesIncludingTerminator () const |
| Get size of the StringView in bytes, including null terminator (2 bytes on UTF16) | |
| constexpr StringEncoding | getEncoding () const |
| Get encoding of this StringView. | |
| constexpr const char * | bytesWithoutTerminator () const |
| Directly access the memory of this StringView. | |
| const char * | bytesIncludingTerminator () const |
| Directly access the memory of this null terminated-StringView. | |
| const char * | getNullTerminatedNative () const |
| Directly access the memory of this null terminated-StringView: | |
| Result | writeNullTerminatedTo (NativeWritable &string) const |
| Writes this Span to a destination Span, using native encoding and null-terminating it. | |
| Result | appendNullTerminatedTo (NativeWritable &string, bool removePreviousNullTerminator=true) const |
| Appends this Span to a destination Span, using native encoding and null-terminating it. | |
| Static Public Member Functions | |
|---|---|
| static constexpr StringSpan | fromNullTerminated (const char *text, StringEncoding encoding) |
| Constructs a StringView from a null terminated string. | |
| static uint32_t | advanceUTF8 (const char *&it, const char *end) |
| Decode a single UTF8 code point and advance the iterator. | |
| static uint32_t | advanceUTF16 (const char *&it, const char *end) |
| Decode a single UTF16 code point and advance the iterator. | |
| 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.
◆ Comparison
| SC::StringSpan::StringSpan ( StringEncoding encoding = StringEncoding::Ascii) | inlineconstexpr |
|---|
◆ StringSpan() [2/3]
| SC::StringSpan::StringSpan ( Span< const char > text, bool nullTerm, StringEncoding encoding ) | inlineconstexpr |
|---|
Construct a StringView from a Span of bytes.
Parameters
| 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 |
◆ StringSpan() [3/3]
| SC::StringSpan::StringSpan ( const char(&) _str_[N]) | inlineconstexpr |
|---|
Constructs a StringView with a null terminated string terminal.
◆ advanceUTF16()
| static uint32_t SC::StringSpan::advanceUTF16 ( const char *& it, const char * end ) | static |
|---|
Decode a single UTF16 code point and advance the iterator.
Returns
The decoded code point, or 0 if the sequence is invalid (or end is reached)
◆ advanceUTF8()
| static uint32_t SC::StringSpan::advanceUTF8 ( const char *& it, const char * end ) | static |
|---|
Decode a single UTF8 code point and advance the iterator.
Returns
The decoded code point, or 0 if the sequence is invalid (or end is reached)
◆ appendNullTerminatedTo()
| Result SC::StringSpan::appendNullTerminatedTo | ( | NativeWritable & | string, |
|---|---|---|---|
| bool | removePreviousNullTerminator = true ) const |
Appends this Span to a destination Span, using native encoding and null-terminating it.
Parameters
| string | The destination writable string to write to |
|---|---|
| removePreviousNullTerminator | If true, the previous null terminator is removed |
◆ bytesIncludingTerminator()
| const char * SC::StringSpan::bytesIncludingTerminator ( ) const | nodiscard |
|---|
Directly access the memory of this null terminated-StringView.
Warning
This method will assert if string is not null terminated.
◆ bytesWithoutTerminator()
| const char * SC::StringSpan::bytesWithoutTerminator ( ) const | inlinenodiscardconstexpr |
|---|
Directly access the memory of this StringView.
◆ compare()
| Comparison SC::StringSpan::compare ( StringSpan other) const | nodiscard |
|---|
Ordering comparison between non-normalized StringView (operates on code points, not on utf graphemes)
◆ fromNullTerminated()
| static constexpr StringSpan SC::StringSpan::fromNullTerminated ( const char * text, StringEncoding encoding ) | inlinestaticconstexpr |
|---|
Constructs a StringView from a null terminated string.
◆ getEncoding()
| StringEncoding SC::StringSpan::getEncoding ( ) const | inlinenodiscardconstexpr |
|---|
◆ getNullTerminatedNative()
| const char * SC::StringSpan::getNullTerminatedNative ( ) const | inlinenodiscard |
|---|
Directly access the memory of this null terminated-StringView:
- On Windows return type will be
const wchar_t*. - On other platforms return type will be
const char*.
◆ isEmpty()
| bool SC::StringSpan::isEmpty ( ) const | inlinenodiscardconstexpr |
|---|
◆ isNullTerminated()
| bool SC::StringSpan::isNullTerminated ( ) const | inlinenodiscardconstexpr |
|---|
Check if StringView is immediately followed by a null termination character.
◆ sizeInBytes()
| size_t SC::StringSpan::sizeInBytes ( ) const | inlinenodiscardconstexpr |
|---|
◆ sizeInBytesIncludingTerminator()
| size_t SC::StringSpan::sizeInBytesIncludingTerminator ( ) const | nodiscard |
|---|
Get size of the StringView in bytes, including null terminator (2 bytes on UTF16)
Warning
This method will Assert if this isNullTerminated returns false
◆ toCharSpan()
| Span< const char > SC::StringSpan::toCharSpan ( ) const | inlinenodiscard |
|---|
◆ writeNullTerminatedTo()
Writes this Span to a destination Span, using native encoding and null-terminating it.
Parameters
| string | The destination writable string to write to |
|---|
The documentation for this struct was generated from the following file: