A position inside a fixed range [start, end)
of UTF code points.
More...
#include <StringIterator.h>
Public Types | |
using | CodeUnit = char |
using | CodePoint = StringCodePoint |
Public Member Functions | |
constexpr void | setToStart () |
Rewind current position to start of iterator range. More... | |
constexpr void | setToEnd () |
Set current position to end of iterator range. More... | |
constexpr bool | isAtEnd () const |
Check if current position is at end of iterator range. More... | |
constexpr bool | isAtStart () const |
Check if current position is at start of iterator range. More... | |
constexpr bool | advanceUntilMatches (CodePoint c) |
Advances position towards end until it matches CodePoint c or position == end More... | |
bool | reverseAdvanceUntilMatches (CodePoint c) |
Moves position towards start until CodePoint c is found or position == end More... | |
bool | advanceAfterFinding (StringIterator other) |
Advances position towards end until a matching range of character equal to other[it, end) is found. More... | |
bool | advanceBeforeFinding (StringIterator other) |
Advances position towards end until a matching range of character equal to other[it, end) is found. More... | |
bool | advanceByLengthOf (StringIterator other) |
Advances position by the same number of code points as other. More... | |
bool | advanceUntilMatchesAny (Span< const CodePoint > items, CodePoint &matched) |
Advances position until any CodePoint in the given Span is found. More... | |
bool | reverseAdvanceUntilMatchesAny (Span< const CodePoint > items, CodePoint &matched) |
Moves position towards start until any CodePoint in the given Span is found. More... | |
bool | advanceUntilDifferentFrom (CodePoint c, CodePoint *optionalReadChar=nullptr) |
Advances position until a code point different from c is found or end is reached. More... | |
constexpr bool | advanceIfMatches (CodePoint c) |
Advance position only if next code point matches c . More... | |
bool | advanceBackwardIfMatches (CodePoint c) |
Move position by one code point towards start if previous code point matches c More... | |
bool | advanceIfMatchesAny (Span< const CodePoint > items) |
Advance position only if any of the code points in given Span is matched. More... | |
bool | advanceIfMatchesRange (CodePoint first, CodePoint last) |
Advance position if any code point in the range [first, last] is matched. More... | |
bool | match (CodePoint c) |
Check if code unit at current position matches CodePoint c More... | |
constexpr bool | advanceRead (CodePoint &c) |
Decode code unit at current position and advance. More... | |
bool | read (CodePoint &c) |
Read code unit at current position. More... | |
bool | advanceBackwardRead (CodePoint &c) |
Move to previous position and read code unit. More... | |
constexpr bool | stepForward () |
Move position to next code point. More... | |
constexpr bool | stepBackward () |
Move position to previous code point. More... | |
constexpr bool | advanceCodePoints (size_t numCodePoints) |
Move position forward (towards end ) by variable number of code points. More... | |
bool | reverseAdvanceCodePoints (size_t numCodePoints) |
Move position backwards (towards start ) by variable number of code pints. More... | |
constexpr bool | isFollowedBy (CodePoint c) |
Check if next code point is c More... | |
constexpr bool | isPrecededBy (CodePoint c) |
Check if previous code point is c More... | |
constexpr StringIterator | sliceFromStartUntil (StringIterator otherPoint) const |
Returns another StringIterator range, starting from start to otherPoint position. More... | |
constexpr ssize_t | bytesDistanceFrom (StringIterator other) const |
Get distance in bytes from current position to another StringIterator current position. More... | |
bool | endsWithAnyOf (Span< const CodePoint > codePoints) const |
Check if this Iterator ends with any code point in the given span. More... | |
bool | startsWithAnyOf (Span< const CodePoint > codePoints) const |
Check if this Iterator starts with any code point in the given span. More... | |
template<typename IteratorType > | |
bool | endsWith (IteratorType other) const |
Check if this Iterator at its end matches entirely another Iterator's range. More... | |
template<typename IteratorType > | |
bool | startsWith (IteratorType other) const |
Check if this Iterator at its start matches entirely another Iterator's range. More... | |
Static Public Member Functions | |
static constexpr StringEncoding | getEncoding () |
Protected Member Functions | |
bool | advanceOfBytes (ssize_t bytesLength) |
constexpr | StringIterator (const CodeUnit *it, const CodeUnit *end) |
constexpr auto * | getCurrentIt () const |
Static Protected Member Functions | |
static constexpr const CodeUnit * | getNextOf (const CodeUnit *src) |
static constexpr const CodeUnit * | getPreviousOf (const CodeUnit *src) |
Protected Attributes | |
const CodeUnit * | it |
const CodeUnit * | start |
const CodeUnit * | end |
Friends | |
struct | StringView |
A position inside a fixed range [start, end)
of UTF code points.
It's a range of bytes (start and end pointers) with a current pointer pointing at a specific code point of the range. There are three classes derived from it (SC::StringIteratorASCII, SC::StringIteratorUTF8 and SC::StringIteratorUTF16) and they allow doing operations along the string view in UTF code points.
CharIterator | StringIteratorASCII, StringIteratorUTF8 or StringIteratorUTF16 |
bool SC::StringIterator< CharIterator >::advanceAfterFinding | ( | StringIterator< CharIterator > | other | ) |
Advances position towards end
until a matching range of character equal to other[it, end)
is found.
Position pointer is advanced additional after the matching range.
other | The range of character to be found [it, end) |
true
if other was found, false
if end was reached bool SC::StringIterator< CharIterator >::advanceBackwardIfMatches | ( | CodePoint | c | ) |
Move position by one code point towards start if previous code point matches c
c | The CodePoint being searched |
true
if next code point matches c
, false
otherwise or if position is already at end bool SC::StringIterator< CharIterator >::advanceBackwardRead | ( | CodePoint & | c | ) |
Move to previous position and read code unit.
c | output code point read |
true
if position is at start
before decoding code unit bool SC::StringIterator< CharIterator >::advanceBeforeFinding | ( | StringIterator< CharIterator > | other | ) |
Advances position towards end
until a matching range of character equal to other[it, end)
is found.
Position pointer is stopped before the first matching character of the range.
other | The range of character to be found [it, end) |
true
if other was found, false
if end was reached
|
inline |
Advances position by the same number of code points as other.
other | The other range of character |
true
if advance succeeded, false
if end
was reached
|
constexpr |
Move position forward (towards end
) by variable number of code points.
numCodePoints | number of code points to move forward |
true
if it's possible advancing numCodePoints
before reaching end
|
constexpr |
Advance position only if next code point matches c
.
c | The CodePoint being searched |
true
if next code point matches c
, false
otherwise or if position is already at end bool SC::StringIterator< CharIterator >::advanceIfMatchesAny | ( | Span< const CodePoint > | items | ) |
bool SC::StringIterator< CharIterator >::advanceIfMatchesRange | ( | CodePoint | first, |
CodePoint | last | ||
) |
Advance position if any code point in the range [first, last] is matched.
first | The initial CodePoint defining the range to be checked |
last | The final CodePoint defining the range to be checked |
true
if a code point in the given range was matched
|
constexpr |
Decode code unit at current position and advance.
c | output code point read |
true
if position is at end
before decoding code unit bool SC::StringIterator< CharIterator >::advanceUntilDifferentFrom | ( | CodePoint | c, |
CodePoint * | optionalReadChar = nullptr |
||
) |
Advances position until a code point different from c
is found or end
is reached.
c | The CodePoint to be compared |
optionalReadChar | The CodePoint that was found, different from c |
true
if it finds at least one code point different from c, false
if iterator ends before finding it
|
constexpr |
Advances position towards end
until it matches CodePoint c
or position == end
c | The CodePoint to be searched |
true
if c was found, false
if end was reached bool SC::StringIterator< CharIterator >::advanceUntilMatchesAny | ( | Span< const CodePoint > | items, |
CodePoint & | matched | ||
) |
|
constexpr |
Get distance in bytes from current position to another StringIterator current position.
other | The StringIterator from which to compute distance |
bool SC::StringIterator< CharIterator >::endsWith | ( | IteratorType | other | ) | const |
Check if this Iterator at its end matches entirely another Iterator's range.
other | The other iterator to match |
true
if this Iterator matches entire other
Iterator at its end
bool SC::StringIterator< CharIterator >::endsWithAnyOf | ( | Span< const CodePoint > | codePoints | ) | const |
Check if this Iterator ends with any code point in the given span.
codePoints | A span of code points to check for |
true
if at least one code point of codepoints
exists at the end of the range
|
inlineconstexpr |
Check if current position is at end of iterator range.
true
if position is at end of iterator range
|
inlineconstexpr |
Check if current position is at start of iterator range.
true
if position is at start of iterator range
|
constexpr |
Check if next code point is c
c | the code point |
true
if next code point is c
|
constexpr |
Check if previous code point is c
c | the code point |
true
if previous code point is c
|
inline |
Check if code unit at current position matches CodePoint c
c | code point to match |
true
if code unit at current position matches c
, false
if there is no match or position is at end
bool SC::StringIterator< CharIterator >::read | ( | CodePoint & | c | ) |
Read code unit at current position.
c | output code point read |
true
if position is at end
before decoding code unit bool SC::StringIterator< CharIterator >::reverseAdvanceCodePoints | ( | size_t | numCodePoints | ) |
Move position backwards (towards start
) by variable number of code pints.
numCodePoints | number of code points to move backwards |
true
if it's possible moving numCodePoints
backwards before reaching start
bool SC::StringIterator< CharIterator >::reverseAdvanceUntilMatches | ( | CodePoint | c | ) |
Moves position towards start until CodePoint c
is found or position == end
c | The CodePoint to be searched |
true
if c
was found, false
if start
was reached bool SC::StringIterator< CharIterator >::reverseAdvanceUntilMatchesAny | ( | Span< const CodePoint > | items, |
CodePoint & | matched | ||
) |
|
inlineconstexpr |
Set current position to end of iterator range.
|
inlineconstexpr |
Rewind current position to start of iterator range.
|
constexpr |
Returns another StringIterator range, starting from start
to otherPoint
position.
otherPoint | The StringIterator containing the ending position to slice to |
[start, otherPoint.position]
bool SC::StringIterator< CharIterator >::startsWith | ( | IteratorType | other | ) | const |
Check if this Iterator at its start matches entirely another Iterator's range.
other | The other iterator to match |
true
if this Iterator matches entire other
at its start
bool SC::StringIterator< CharIterator >::startsWithAnyOf | ( | Span< const CodePoint > | codePoints | ) | const |
Check if this Iterator starts with any code point in the given span.
codePoints | A span of code points to check for |
true
if at least one code point of codepoints
exists at the start of the range
|
constexpr |
Move position to previous code point.
true
if position is not at start
before trying to move backwards
|
constexpr |
Move position to next code point.
true
if position is not at end
before trying to move forward