Non-owning view over a range of characters with UTF Encoding. More...
#include <StringView.h>
Public Member Functions | |
| constexpr | StringView (StringSpan ssv) |
| Span< const uint8_t > | toBytesSpan () const SC_LANGUAGE_LIFETIME_BOUND |
Obtain a const uint8_t Span from this StringView. | |
| template<typename Func > | |
| constexpr auto | withIterator (Func &&func) const |
| Call given lambda with one of StringIteratorASCII, StringIteratorUTF8, StringIteratorUTF16 depending on encoding. | |
| template<typename StringIterator > | |
| constexpr StringIterator | getIterator () const |
| Returns a StringIterator from current StringView. | |
| constexpr bool | operator!= (StringView other) const |
| Compare this StringView with another StringView for inequality. | |
| constexpr bool | operator== (StringView other) const |
| Compare this StringView with another StringView for equality. | |
| constexpr bool | fullyOverlaps (StringView other, size_t &commonOverlappingPoints) const |
| Check if this StringView is equal to other StringView (operates on code points, not on utf graphemes). | |
| constexpr bool | isEmpty () const |
| Check 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. | |
| bool | endsWithAnyOf (Span< const StringCodePoint > codePoints) const |
| Check if StringView ends with any utf code point in the given span. | |
| bool | startsWithAnyOf (Span< const StringCodePoint > codePoints) const |
| Check if StringView starts with any utf code point in the given span. | |
| bool | startsWith (const StringView str) const |
| Check if StringView starts with another StringView. | |
| bool | endsWith (const StringView str) const |
| Check if StringView ends with another StringView. | |
| bool | containsString (const StringView str) const |
| Check if StringView contains another StringView. | |
| bool | splitAfter (const StringView stringToMatch, StringView &remainingAfterSplit) const |
| Returns the remaining part of the string after matching stringToMatch. | |
| bool | splitBefore (const StringView stringToMatch, StringView &stringBeforeSplit) const |
| Returns the part of the string before matching stringToMatch. | |
| bool | containsCodePoint (StringCodePoint c) const |
| Check if StringView contains given utf code point. | |
| constexpr bool | hasCompatibleEncoding (StringView str) const |
| Check if current StringView has compatible encoding with str. | |
| StringView | sliceStartEnd (size_t start, size_t end) const |
Get slice [start, end) starting at offset start and ending at end (measured in utf code points) | |
| StringView | sliceStartLength (size_t start, size_t length) const |
Get slice [start, start+length] starting at offset start and of length code points. | |
| StringView | sliceStart (size_t offset) const |
Get slice [offset, end] measured in utf code points. | |
| StringView | sliceEnd (size_t offset) const |
Get slice [end-offset, end] measured in utf code points. | |
| StringView | trimEndAnyOf (Span< const StringCodePoint > codePoints) const |
Returns a shortened StringView removing ending utf code points matching the codePoints span. | |
| StringView | trimStartAnyOf (Span< const StringCodePoint > codePoints) const |
Returns a shortened StringView removing starting utf code points matching the codePoints span. | |
| StringView | trimAnyOf (Span< const StringCodePoint > codePoints) const |
Returns a shortened StringView removing starting and ending utf code points inside the codePoints span. | |
| StringView | trimWhiteSpaces () const |
| Returns a shortened StringView without starting/ending utf code points inside {'\r', '\n', '\t', ' '}. | |
| bool | isIntegerNumber () const |
| If the current view is an integer number, returns true. | |
| bool | isFloatingNumber () const |
| Check if StringView can be parsed as an floating point number. | |
| bool | parseInt32 (int32_t &value) const |
| Try parsing current StringView as a 32 bit integer. | |
| bool | parseFloat (float &value) const |
| Try parsing current StringView as a floating point number. | |
| bool | parseDouble (double &value) const |
| Try parsing current StringView as a double precision floating point number. | |
| template<typename Type > | |
| constexpr SC::StringIteratorASCII | getIterator (identity< Type >) const |
| template<typename StringIterator > | |
| SC::StringView | fromIterators (StringIterator from, StringIterator to, StringEncoding encoding) |
| template<typename StringIterator > | |
| SC::StringView | fromIteratorUntilEnd (StringIterator it, StringEncoding encoding) |
| template<typename StringIterator > | |
| constexpr SC::StringView | fromIteratorFromStart (StringIterator it, StringEncoding encoding) |
| 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. | |
Public Member Functions inherited from SC::StringSpan | |
| 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 StringView | fromNullTerminated (const char *text, StringEncoding encoding) |
| template<typename Func > | |
| static constexpr auto | withIterators (StringView s1, StringView s2, Func &&func) |
| Call given lambda with one of StringIteratorASCII, StringIteratorUTF8, StringIteratorUTF16 depending on encoding. | |
| template<typename StringIterator > | |
| static StringView | fromIterators (StringIterator from, StringIterator to, StringEncoding encoding=StringIterator::getEncoding()) |
Returns a StringView starting at from and ending at to. | |
| template<typename StringIterator > | |
| static StringView | fromIteratorUntilEnd (StringIterator it, StringEncoding encoding=StringIterator::getEncoding()) |
Returns a section of a string, from it to end of StringView. | |
| template<typename StringIterator > | |
| static constexpr StringView | fromIteratorFromStart (StringIterator it, StringEncoding encoding=StringIterator::getEncoding()) |
Returns a section of a string, from start of StringView to it. | |
Static Public Member Functions inherited from SC::StringSpan | |
| 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. | |
Additional Inherited Members | ||
Public Types inherited from SC::StringSpan | ||
| enum class | Comparison { Smaller = -1 , Equals = 0 , Bigger = 1 } | |
| Result of ordering comparison done by StringSpan::compare. More... | ||
Public Attributes inherited from SC::StringSpan | ||
Protected Attributes inherited from SC::StringSpan | ||
| union { | ||
| const char * text | ||
| }; | ||
| size_t | textSizeInBytes: sizeof(size_t) * 8 - NumOptionBits | |
| size_t | encoding: 2 | |
| size_t | hasNullTerm: 1 | |
Static Protected Attributes inherited from SC::StringSpan | ||
| static constexpr size_t | NumOptionBits = 3 | |
| static constexpr size_t | MaxLength = (~static_cast<size_t>(0)) >> NumOptionBits | |
Non-owning view over a range of characters with UTF Encoding.
It additional also holds the SC::StringEncoding information (ASCII, UTF8 or UTF16). During construction the encoding information and the null-termination state must be specified. All methods are const because it's not possible to modify a string with it.
Example (Construct)
Example (Construct from null terminated string)
|
nodiscard |
Check if StringView contains given utf code point.
| c | The utf code point to check against |
true if this StringView contains code point c
|
nodiscard |
Check if StringView contains another StringView.
| str | The other StringView to check with current |
true if this StringView contains strExample:
|
nodiscard |
Check if StringView ends with another StringView.
| str | The other StringView to check with current |
true if this StringView ends with strExample:
|
nodiscard |
Check if StringView ends with any utf code point in the given span.
| codePoints | The utf code points to check against |
true if this StringView ends with any code point inside codePointsExample:
|
staticconstexpr |
Returns a section of a string, from start of StringView to it.
| StringIterator | One among StringIteratorASCII, StringIteratorUTF8 and StringIteratorUTF16 |
| it | The iterator pointing at the start of the specified portion of StringView. |
| encoding | What encoding should be assigned to the resulting StringView |
it
|
static |
Returns a StringView starting at from and ending at to.
| StringIterator | One among StringIteratorASCII, StringIteratorUTF8 and StringIteratorUTF16 |
| from | Indicates where the StringView will start. The from iterator will be shortened until the start of to. |
| to | Indicates where the StringView will end. |
| encoding | What encoding should be assigned to the resulting StringView |
from and ending at to. > to an empty StringView will be returned
|
static |
Returns a section of a string, from it to end of StringView.
| StringIterator | One among StringIteratorASCII, StringIteratorUTF8 and StringIteratorUTF16 |
| it | The iterator pointing at the start of the specified portion of StringView. |
| encoding | What encoding should be assigned to the resulting StringView |
it up to StringView end
|
nodiscardconstexpr |
Check if this StringView is equal to other StringView (operates on code points, not on utf graphemes).
Returns the number of code points that are the same in both StringView-s.
| other | The StringView to be compared to |
| commonOverlappingPoints | number of equal code points in both StringView |
true if the two StringViews are equalExample:
|
constexpr |
Returns a StringIterator from current StringView.
| StringIterator | can be StringIteratorASCII, StringIteratorUTF8 or StringIteratorUTF16 |
|
nodiscardconstexpr |
Check if current StringView has compatible encoding with str.
This means checking if two encodings have the same utf unit size.
| str | The other StringView to check with current |
true if this StringView has compatible encoding with str
|
inlinenodiscardconstexpr |
Check if StringView is empty.
true if string is empty
|
nodiscard |
Check if StringView can be parsed as an floating point number.
true if StringView is a floating point number.Example:
|
nodiscard |
If the current view is an integer number, returns true.
Check if StringView can be parsed as an integer number.
true if StringView is an integer number.Example:
|
inlinenodiscardconstexpr |
Check if StringView is immediately followed by a null termination character.
true if StringView is immediately followed by a null termination character
|
inlinenodiscardconstexpr |
Compare this StringView with another StringView for inequality.
| other | StringView to be compared with current one |
|
nodiscardconstexpr |
Compare this StringView with another StringView for equality.
| other | StringView to be compared with current one |
|
nodiscard |
Try parsing current StringView as a double precision floating point number.
| value | Will receive the parsed double precision floating point number, if function returns true. |
true if the StringView has been successfully parsed as a double precision floating point number.Example:
|
nodiscard |
Try parsing current StringView as a floating point number.
| value | Will receive the parsed floating point number, if function returns true. |
true if the StringView has been successfully parsed as a floating point number.Example:
|
nodiscard |
Try parsing current StringView as a 32 bit integer.
| value | Will receive the parsed 32 bit integer, if function returns true. |
true if the StringView has been successfully parsed as a 32 bit integer.Example:
|
inlinenodiscardconstexpr |
Get size of the StringView in bytes.
|
nodiscard |
Get slice [end-offset, end] measured in utf code points.
| offset | The initial code point where the slice starts |
[end-offset, end]Example:
|
nodiscard |
Get slice [offset, end] measured in utf code points.
| offset | The initial code point where the slice starts |
[offset, end]Example:
|
nodiscard |
Get slice [start, end) starting at offset start and ending at end (measured in utf code points)
| start | The initial code point where the slice starts |
| end | One after the final code point where the slice ends |
[start, end) StringView sliceExample:
|
nodiscard |
Get slice [start, start+length] starting at offset start and of length code points.
| start | The initial code point where the slice starts |
| length | One after the final code point where the slice ends |
[start, start+length] StringView sliceExample:
|
nodiscard |
Returns the remaining part of the string after matching stringToMatch.
| stringToMatch | String to match inside the source string |
| remainingAfterSplit | Portion of this StringView AFTER first match of stringToMatch (excluding the match) |
true if stringToMatch has been found and split has been written to remainingAfterSplitExample:
|
nodiscard |
Returns the part of the string before matching stringToMatch.
| stringToMatch | String to match inside the source string |
| stringBeforeSplit | Portion of this StringView BEFORE first match of stringToMatch (excluding the match) |
true if stringToMatch has been found and split has been written to remainingAfterSplitExample:
|
nodiscard |
Check if StringView starts with another StringView.
| str | The other StringView to check with current |
true if this StringView starts with strExample:
|
nodiscard |
Check if StringView starts with any utf code point in the given span.
| codePoints | The utf code points to check against |
true if this StringView starts with any code point inside codePointsExample:
|
inlineconstexpr |
Constructs a StringView with a null terminated string terminal.
|
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 |
Construct an empty StringView.
Obtain a const uint8_t Span from this StringView.
|
nodiscard |
Returns a shortened StringView removing starting and ending utf code points inside the codePoints span.
| codePoints | The span of utf code points to look for |
Example:
|
nodiscard |
Returns a shortened StringView removing ending utf code points matching the codePoints span.
| codePoints | The span of utf code points to look for |
Example:
|
nodiscard |
Returns a shortened StringView removing starting utf code points matching the codePoints span.
| codePoints | The span of utf code points to look for |
Example:
|
nodiscard |
Returns a shortened StringView without starting/ending utf code points inside {'\r', '\n', '\t', ' '}.
Example:
|
nodiscardconstexpr |
Call given lambda with one of StringIteratorASCII, StringIteratorUTF8, StringIteratorUTF16 depending on encoding.
| Func | A function/lambda with auto operator()({StringIteratorASCII | StringIteratorUTF8 | / StringIteratorUTF16}) |
| func | lambda / functor to be called |
|
staticnodiscardconstexpr |
Call given lambda with one of StringIteratorASCII, StringIteratorUTF8, StringIteratorUTF16 depending on encoding.
| Func | Func A function/lambda with auto operator()({StringIteratorASCII | StringIteratorUTF8 | / StringIteratorUTF16}, {StringIteratorASCII | StringIteratorUTF8 | StringIteratorUTF16}) |
| s1 | StringView that will be passed as first iterator |
| s2 | StringView that will be passed as second iterator |
| func | the lambda / to be invoked |