Overview
TheGlyphIterator is a UTF-8 sensitive iterator designed specifically for text buffer navigation. Unlike raw byte iterators, it understands Unicode and moves by complete code points rather than individual bytes. It’s aware of the gap buffer structure and automatically clamps to valid positions.
This is the primary “pointer” into text used throughout the Zep editor.
Source: include/zep/glyph_iterator.h:41
Key Features
- UTF-8 aware: Moves by complete Unicode code points, not bytes
- Gap buffer compatible: Knows how to navigate the gap buffer structure
- Auto-clamping: Automatically clamps to valid buffer positions
- Line-aware: Can clamp movement to line boundaries
Declaration
include/zep/glyph_iterator.h:44-45
Construction
Constructor
buffer- Pointer to the ZepBuffer to iterate overoffset- Initial byte offset position (default: 0)
Copy Constructor
include/zep/glyph_iterator.h:44-45
Position and Validity
Index()
include/zep/glyph_iterator.h:47
Valid()
true if the iterator is in a valid state (associated with a buffer and pointing to a valid position).
Source: include/zep/glyph_iterator.h:48
Invalidate()
include/zep/glyph_iterator.h:49
Movement Operations
Forward/Backward by Code Points
Postfix Increment/Decrement
include/zep/glyph_iterator.h:56-57
Compound Assignment
include/zep/glyph_iterator.h:58-59
Arithmetic Operators
include/zep/glyph_iterator.h:61-62
Move()
count code points (positive for forward, negative for backward). Does not clamp.
Returns: Reference to *this for chaining
Source: include/zep/glyph_iterator.h:68
MoveClamped()
count code points, clamping to the specified line boundary.
Parameters:
count- Number of code points to move (positive/negative)clamp- Line boundary to respect (default: last character before carriage return)
*this for chaining
Source: include/zep/glyph_iterator.h:67
Clamp()
*this for chaining
Source: include/zep/glyph_iterator.h:69
Peek Operations
Peek methods return a new iterator without modifying the current one:Peek()
count code points without clamping.
Source: include/zep/glyph_iterator.h:71
PeekLineClamped()
count code points, clamped to line boundaries.
Source: include/zep/glyph_iterator.h:72
PeekByteOffset()
count bytes (not code points). Useful for low-level buffer operations.
Source: include/zep/glyph_iterator.h:73
Clamped()
include/zep/glyph_iterator.h:74
Character Access
Char()
include/zep/glyph_iterator.h:65
operator*
include/zep/glyph_iterator.h:66
Comparison Operators
include/zep/glyph_iterator.h:50-55
Assignment
include/zep/glyph_iterator.h:64
Helper Structures
GlyphRange
include/zep/glyph_iterator.h:98-111
ByteRange
include/zep/glyph_iterator.h:12-24
Distance Functions
CodePointDistance()
itr1 to itr2
Source: include/zep/glyph_iterator.h:81
ByteDistance()
include/zep/glyph_iterator.h:93
LineLocation Enum
include/zep/glyph_iterator.h:26-35
Example Usage
Design Notes
- UTF-8 multi-byte handling: The iterator automatically handles multi-byte UTF-8 sequences, ensuring movement always lands on valid code point boundaries
- Gap buffer integration: The iterator is aware of the gap buffer’s internal structure and transparently skips the gap
- Auto-clamping philosophy: Iterators prefer to remain valid rather than enter error states, automatically clamping when operations would move them out of bounds
- Line-aware navigation: The
LineLocationenum enables intelligent movement within lines, respecting boundaries like the first visible character or last character before line breaks
