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 | startsWithIgnoreCaseASCII (const StringView str) const |
| Check if StringView starts with another StringView using ASCII-only case-insensitive comparison. | |
| 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 | containsStringIgnoreCaseASCII (const StringView str) const |
| Check if StringView contains another StringView using ASCII-only case-insensitive comparison. | |
| bool | equalsIgnoreCaseASCII (const StringView str) const |
| Check if StringView is equal to another StringView using ASCII-only case-insensitive comparison. | |
| 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) |
Static Public Member Functions | |
| static 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. | |
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 contains another StringView using ASCII-only case-insensitive comparison.
Non-ASCII code points are compared without case folding.
|
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:
|
nodiscard |
Check if StringView is equal to another StringView using ASCII-only case-insensitive comparison.
Non-ASCII code points are compared without case folding.
|
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:
|
nodiscard |
Check if StringView starts with another StringView using ASCII-only case-insensitive comparison.
Non-ASCII code points are compared without case folding.
|
inline |
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 |