@@ -9,9 +9,9 @@ extension UTF8Span {
99 . init( self )
1010 }
1111
12+ // **TODO**: Examples in below doc
13+
1214 /// Iterate the `Unicode.Scalar`s contents of a `UTF8Span`.
13- ///
14- /// **TODO**: Examples
1515 @frozen
1616 public struct UnicodeScalarIterator : ~ Escapable {
1717 public let codeUnits : UTF8Span
@@ -37,6 +37,8 @@ extension UTF8Span {
3737 /// of the next scalar.
3838 ///
3939 /// Returns `nil` if at the end of the `UTF8Span`.
40+ ///
41+ /// - Complexity: O(1)
4042 @lifetime ( self : copy self )
4143 public mutating func next( ) -> Unicode . Scalar ? {
4244 guard currentCodeUnitOffset < codeUnits. count else {
@@ -55,6 +57,8 @@ extension UTF8Span {
5557 /// previous scalar.
5658 ///
5759 /// Returns `nil` if at the start of the `UTF8Span`.
60+ ///
61+ /// - Complexity: O(1)
5862 @lifetime ( self : copy self )
5963 public mutating func previous( ) -> Unicode . Scalar ? {
6064 guard currentCodeUnitOffset > 0 else {
@@ -73,6 +77,8 @@ extension UTF8Span {
7377 ///
7478 /// Returns the number of `Unicode.Scalar`s skipped over, which can be 0
7579 /// if at the end of the UTF8Span.
80+ ///
81+ /// - Complexity: O(1)
7682 @lifetime ( self : copy self )
7783 public mutating func skipForward( ) -> Int {
7884 guard currentCodeUnitOffset < codeUnits. count else {
@@ -90,6 +96,8 @@ extension UTF8Span {
9096 ///
9197 /// Returns the number of `Unicode.Scalar`s skipped over, which can be
9298 /// fewer than `n` if at the end of the UTF8Span.
99+ ///
100+ /// - Complexity: O(n)
93101 @lifetime ( self : copy self )
94102 public mutating func skipForward( by n: Int ) -> Int {
95103 var numSkipped = 0
@@ -105,6 +113,8 @@ extension UTF8Span {
105113 ///
106114 /// Returns the number of `Unicode.Scalar`s skipped over, which can be 0
107115 /// if at the start of the UTF8Span.
116+ ///
117+ /// - Complexity: O(1)
108118 @lifetime ( self : copy self )
109119 public mutating func skipBack( ) -> Int {
110120 guard currentCodeUnitOffset > 0 else {
@@ -122,6 +132,8 @@ extension UTF8Span {
122132 ///
123133 /// Returns the number of `Unicode.Scalar`s skipped over, which can be
124134 /// fewer than `n` if at the start of the UTF8Span.
135+ ///
136+ /// - Complexity: O(n)
125137 @lifetime ( self : copy self )
126138 public mutating func skipBack( by n: Int ) -> Int {
127139 var numSkipped = 0
@@ -132,35 +144,39 @@ extension UTF8Span {
132144 return numSkipped
133145 }
134146
147+ // TODO: Example for reset docs
148+
135149 /// Reset to the nearest scalar-aligned code unit offset `<= i`.
136150 ///
137- /// **TODO**: Example
151+ /// - Complexity: O(1)
138152 @lifetime ( self : copy self )
139153 public mutating func reset( roundingBackwardsFrom i: Int ) {
140154 self . currentCodeUnitOffset = codeUnits. _scalarAlignBackwards ( i)
141155 }
142156
143157 /// Reset to the nearest scalar-aligned code unit offset `>= i`.
144158 ///
145- /// **TODO**: Example
159+ /// - Complexity: O(1)
146160 @lifetime ( self : copy self )
147161 public mutating func reset( roundingForwardsFrom i: Int ) {
148162 self . currentCodeUnitOffset = codeUnits. _scalarAlignForwards ( i)
149163 }
150164
165+ // TODO: for below, verify that there is no path to UB, just garabage-data or guaranteed
166+ // trap!
167+
151168 /// Reset this iterator to `codeUnitOffset`, skipping _all_ safety
152169 /// checks (including bounds checks).
153170 ///
154171 /// Note: This is only for very specific, low-level use cases. If
155172 /// `codeUnitOffset` is not properly scalar-aligned, this function can
156173 /// result in undefined behavior when, e.g., `next()` is called.
157174 ///
158- /// TODO: verify that we're not UB, just garabage-data or guaranteed
159- /// trap!
160- ///
161175 /// For example, this could be used by a regex engine to backtrack to a
162176 /// known-valid previous position.
163177 ///
178+ ///
179+ /// - Complexity: O(1)
164180 @unsafe
165181 @lifetime ( self : copy self )
166182 public mutating func reset( toUnchecked codeUnitOffset: Int ) {
@@ -172,6 +188,8 @@ extension UTF8Span {
172188 /// current position.
173189 ///
174190 /// The resultant `UTF8Span` has the same lifetime constraints as `self`.
191+ ///
192+ /// - Complexity: O(1)
175193 @lifetime ( copy self)
176194 public func prefix( ) -> UTF8Span {
177195 let slice = codeUnits. span. extracting ( 0 ..< currentCodeUnitOffset)
@@ -185,6 +203,8 @@ extension UTF8Span {
185203 /// current position.
186204 ///
187205 /// The resultant `UTF8Span` has the same lifetime constraints as `self`.
206+ ///
207+ /// - Complexity: O(1)
188208 @lifetime ( copy self)
189209 public func suffix( ) -> UTF8Span {
190210 let slice = codeUnits. span. extracting ( currentCodeUnitOffset..< codeUnits. count)
@@ -208,9 +228,9 @@ extension UTF8Span {
208228 . init( self )
209229 }
210230
231+ // **TODO**: Examples in below doc
232+
211233 /// Iterate the `Character` contents of a `UTF8Span`.
212- ///
213- /// **TODO**: Examples
214234 public struct CharacterIterator : ~ Escapable {
215235 public let codeUnits : UTF8Span
216236
0 commit comments