Sane C++ Libraries: SC::StringIterator< CharIterator (original) (raw)

A position inside a fixed range [start, end) of UTF code points. More...

#include <[StringIterator.h](StringIterator%5F8h%5Fsource.html)>

Public Member Functions
constexpr void setToStart ()
Rewind current position to start of iterator range.
constexpr void setToEnd ()
Set current position to end of iterator range.
constexpr bool isAtEnd () const
Check if current position is at end of iterator range.
constexpr bool isAtStart () const
Check if current position is at start of iterator range.
constexpr bool advanceUntilMatches (CodePoint c)
Advances position towards end until it matches CodePoint c or position == end
bool reverseAdvanceUntilMatches (CodePoint c)
Moves position towards start until CodePoint c is found or position == end
template
bool advanceAfterFinding (StringIterator< OtherIterator > other)
Advances position towards end until a matching range of character equal to other[it, end) is found.
bool advanceAfterFinding (StringIterator other)
template
bool advanceBeforeFinding (StringIterator< OtherIterator > other)
Advances position towards end until a matching range of character equal to other[it, end) is found.
bool advanceBeforeFinding (StringIterator other)
bool advanceByLengthOf (StringIterator other)
Advances position by the same number of code points as other.
bool advanceUntilMatchesAny (Span< const CodePoint > items, CodePoint &matched)
Advances position until any CodePoint in the given Span is found.
bool reverseAdvanceUntilMatchesAny (Span< const CodePoint > items, CodePoint &matched)
Moves position towards start until any CodePoint in the given Span is found.
bool advanceUntilDifferentFrom (CodePoint c, CodePoint *optionalReadChar=nullptr)
Advances position until a code point different from c is found or end is reached.
constexpr bool advanceIfMatches (CodePoint c)
Advance position only if next code point matches c.
bool advanceBackwardIfMatches (CodePoint c)
Move position by one code point towards start if previous code point matches c
bool advanceIfMatchesAny (Span< const CodePoint > items)
Advance position only if any of the code points in given Span is matched.
bool advanceIfMatchesRange (CodePoint first, CodePoint last)
Advance position if any code point in the range [first, last] is matched.
bool match (CodePoint c)
Check if code unit at current position matches CodePoint c
constexpr bool advanceRead (CodePoint &c)
Decode code unit at current position and advance.
bool read (CodePoint &c)
Read code unit at current position.
bool advanceBackwardRead (CodePoint &c)
Move to previous position and read code unit.
constexpr bool stepForward ()
Move position to next code point.
constexpr bool stepBackward ()
Move position to previous code point.
constexpr bool advanceCodePoints (size_t numCodePoints)
Move position forward (towards end) by variable number of code points.
bool reverseAdvanceCodePoints (size_t numCodePoints)
Move position backwards (towards start) by variable number of code pints.
constexpr bool isFollowedBy (CodePoint c)
Check if next code point is c
constexpr bool isPrecededBy (CodePoint c)
Check if previous code point is c
constexpr StringIterator sliceFromStartUntil (StringIterator otherPoint) const
Returns another StringIterator range, starting from start to otherPoint position.
constexpr ssize_t bytesDistanceFrom (StringIterator other) const
Get distance in bytes from current position to another StringIterator current position.
bool endsWithAnyOf (Span< const CodePoint > codePoints) const
Check if this Iterator ends with any code point in the given span.
bool startsWithAnyOf (Span< const CodePoint > codePoints) const
Check if this Iterator starts with any code point in the given span.
template
bool endsWith (IteratorType other) const
Check if this Iterator at its end matches entirely another Iterator's range.
template
bool startsWith (IteratorType other) const
Check if this Iterator at its start matches entirely another Iterator's range.
Static Public Member Functions
static constexpr StringEncoding getEncoding ()
Protected Member Functions
template<typename OtherIterator , bool after>
bool advanceBeforeOrAfterFinding (StringIterator< OtherIterator > other)
bool advanceAfterFindingSameIterator (StringIterator other)
bool advanceBeforeFindingSameIterator (StringIterator other)
bool advanceOfBytes (ssize_t bytesLength)
constexpr StringIterator (const CodeUnit *it, const CodeUnit *end)
Static Protected Member Functions
static constexpr const CodeUnit * getNextOf (const CodeUnit *src, const char *end)
static constexpr const CodeUnit * getPreviousOf (const CodeUnit *src, const char *start)
Protected Attributes
const CodeUnit * it
const CodeUnit * start
const CodeUnit * end
Friends
struct StringView

template
struct SC::StringIterator< CharIterator >

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.

Note

Code points are not the same as perceived characters (that would be grapheme clusters). Invariants: start <= end and it >= start and it <= end.

Template Parameters

advanceAfterFinding()

template

template

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.

Parameters

other The range of character to be found [it, end)

Returns

true if other was found, false if end was reached

advanceBackwardIfMatches()

template

bool SC::StringIterator< CharIterator >::advanceBackwardIfMatches ( CodePoint c) nodiscard

Move position by one code point towards start if previous code point matches c

Parameters

c The CodePoint being searched

Returns

true if next code point matches c, false otherwise or if position is already at end

advanceBackwardRead()

template

Move to previous position and read code unit.

Parameters

Returns

true if position is at start before decoding code unit

advanceBeforeFinding()

template

template

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.

Parameters

other The range of character to be found [it, end)

Returns

true if other was found, false if end was reached

advanceByLengthOf()

template

Advances position by the same number of code points as other.

Parameters

other The other range of character

Returns

true if advance succeeded, false if end was reached

advanceCodePoints()

template

Move position forward (towards end) by variable number of code points.

Parameters

numCodePoints number of code points to move forward

Returns

true if it's possible advancing numCodePoints before reaching end

advanceIfMatches()

template

bool SC::StringIterator< CharIterator >::advanceIfMatches ( CodePoint c) nodiscardconstexpr

Advance position only if next code point matches c.

Parameters

c The CodePoint being searched

Returns

true if next code point matches c, false otherwise or if position is already at end

advanceIfMatchesAny()

template

Advance position only if any of the code points in given Span is matched.

Parameters

items Span of points to be checked

Returns

true if next code point was successfully matched

advanceIfMatchesRange()

template

bool SC::StringIterator< CharIterator >::advanceIfMatchesRange ( CodePoint first, CodePoint last ) nodiscard

Advance position if any code point in the range [first, last] is matched.

Parameters

first The initial CodePoint defining the range to be checked
last The final CodePoint defining the range to be checked

Returns

true if a code point in the given range was matched

advanceRead()

template

Decode code unit at current position and advance.

Parameters

Returns

true if position is at end before decoding code unit

advanceUntilDifferentFrom()

template

bool SC::StringIterator< CharIterator >::advanceUntilDifferentFrom ( CodePoint c, CodePoint * optionalReadChar = nullptr ) nodiscard

Advances position until a code point different from c is found or end is reached.

Parameters

c The CodePoint to be compared
optionalReadChar The CodePoint that was found, different from c

Returns

true if it finds at least one code point different from c, false if iterator ends before finding it

advanceUntilMatches()

template

bool SC::StringIterator< CharIterator >::advanceUntilMatches ( CodePoint c) nodiscardconstexpr

Advances position towards end until it matches CodePoint c or position == end

Parameters

c The CodePoint to be searched

Returns

true if c was found, false if end was reached

advanceUntilMatchesAny()

template

bool SC::StringIterator< CharIterator >::advanceUntilMatchesAny ( Span< const CodePoint > items, CodePoint & matched ) nodiscard

Advances position until any CodePoint in the given Span is found.

Parameters

items A contiguous span of CodePoint to match
matched The matched CodePoint in the Span

Returns

true if one CodePoint was matched, false if end was reached

bytesDistanceFrom()

template

Get distance in bytes from current position to another StringIterator current position.

Parameters

Returns

(signed) number of bytes between the two StringIterator

endsWith()

template

template

Check if this Iterator at its end matches entirely another Iterator's range.

Parameters

other The other iterator to match

Returns

true if this Iterator matches entire other Iterator at its end

endsWithAnyOf()

template

Check if this Iterator ends with any code point in the given span.

Parameters

codePoints A span of code points to check for

Returns

true if at least one code point of codepoints exists at the end of the range

isAtEnd()

template

Check if current position is at end of iterator range.

Returns

true if position is at end of iterator range

isAtStart()

template

Check if current position is at start of iterator range.

Returns

true if position is at start of iterator range

isFollowedBy()

template

Check if next code point is c

Parameters

Returns

true if next code point is c

isPrecededBy()

template

Check if previous code point is c

Parameters

Returns

true if previous code point is c

match()

template

Check if code unit at current position matches CodePoint c

Parameters

Returns

true if code unit at current position matches c, false if there is no match or position is at end

read()

template

Read code unit at current position.

Parameters

Returns

true if position is at end before decoding code unit

reverseAdvanceCodePoints()

template

Move position backwards (towards start) by variable number of code pints.

Parameters

numCodePoints number of code points to move backwards

Returns

true if it's possible moving numCodePoints backwards before reaching start

reverseAdvanceUntilMatches()

template

bool SC::StringIterator< CharIterator >::reverseAdvanceUntilMatches ( CodePoint c) nodiscard

Moves position towards start until CodePoint c is found or position == end

Parameters

c The CodePoint to be searched

Returns

true if c was found, false if start was reached

reverseAdvanceUntilMatchesAny()

template

bool SC::StringIterator< CharIterator >::reverseAdvanceUntilMatchesAny ( Span< const CodePoint > items, CodePoint & matched ) nodiscard

Moves position towards start until any CodePoint in the given Span is found.

Parameters

items A contiguous span of CodePoint to match
matched The matched CodePoint in the Span

Returns

true if one CodePoint was matched, false if start was reached

setToEnd()

template

Set current position to end of iterator range.

setToStart()

template

Rewind current position to start of iterator range.

sliceFromStartUntil()

template

Returns another StringIterator range, starting from start to otherPoint position.

Parameters

otherPoint The StringIterator containing the ending position to slice to

Returns

The new StringIterator [start, otherPoint.position]

startsWith()

template

template

Check if this Iterator at its start matches entirely another Iterator's range.

Parameters

other The other iterator to match

Returns

true if this Iterator matches entire other at its start

startsWithAnyOf()

template

bool SC::StringIterator< CharIterator >::startsWithAnyOf ( Span< const CodePoint > codePoints) const nodiscard

Check if this Iterator starts with any code point in the given span.

Parameters

codePoints A span of code points to check for

Returns

true if at least one code point of codepoints exists at the start of the range

stepBackward()

template

Move position to previous code point.

Returns

true if position is not at start before trying to move backwards

stepForward()

template

Move position to next code point.

Returns

true if position is not at end before trying to move forward


The documentation for this struct was generated from the following file: