@@ -9,9 +9,9 @@ extension UTF8Span {
9
9
. init( self )
10
10
}
11
11
12
+ // **TODO**: Examples in below doc
13
+
12
14
/// Iterate the `Unicode.Scalar`s contents of a `UTF8Span`.
13
- ///
14
- /// **TODO**: Examples
15
15
@frozen
16
16
public struct UnicodeScalarIterator : ~ Escapable {
17
17
public let codeUnits : UTF8Span
@@ -37,6 +37,8 @@ extension UTF8Span {
37
37
/// of the next scalar.
38
38
///
39
39
/// Returns `nil` if at the end of the `UTF8Span`.
40
+ ///
41
+ /// - Complexity: O(1)
40
42
@lifetime ( self : copy self )
41
43
public mutating func next( ) -> Unicode . Scalar ? {
42
44
guard currentCodeUnitOffset < codeUnits. count else {
@@ -55,6 +57,8 @@ extension UTF8Span {
55
57
/// previous scalar.
56
58
///
57
59
/// Returns `nil` if at the start of the `UTF8Span`.
60
+ ///
61
+ /// - Complexity: O(1)
58
62
@lifetime ( self : copy self )
59
63
public mutating func previous( ) -> Unicode . Scalar ? {
60
64
guard currentCodeUnitOffset > 0 else {
@@ -73,6 +77,8 @@ extension UTF8Span {
73
77
///
74
78
/// Returns the number of `Unicode.Scalar`s skipped over, which can be 0
75
79
/// if at the end of the UTF8Span.
80
+ ///
81
+ /// - Complexity: O(1)
76
82
@lifetime ( self : copy self )
77
83
public mutating func skipForward( ) -> Int {
78
84
guard currentCodeUnitOffset < codeUnits. count else {
@@ -90,6 +96,8 @@ extension UTF8Span {
90
96
///
91
97
/// Returns the number of `Unicode.Scalar`s skipped over, which can be
92
98
/// fewer than `n` if at the end of the UTF8Span.
99
+ ///
100
+ /// - Complexity: O(n)
93
101
@lifetime ( self : copy self )
94
102
public mutating func skipForward( by n: Int ) -> Int {
95
103
var numSkipped = 0
@@ -105,6 +113,8 @@ extension UTF8Span {
105
113
///
106
114
/// Returns the number of `Unicode.Scalar`s skipped over, which can be 0
107
115
/// if at the start of the UTF8Span.
116
+ ///
117
+ /// - Complexity: O(1)
108
118
@lifetime ( self : copy self )
109
119
public mutating func skipBack( ) -> Int {
110
120
guard currentCodeUnitOffset > 0 else {
@@ -122,6 +132,8 @@ extension UTF8Span {
122
132
///
123
133
/// Returns the number of `Unicode.Scalar`s skipped over, which can be
124
134
/// fewer than `n` if at the start of the UTF8Span.
135
+ ///
136
+ /// - Complexity: O(n)
125
137
@lifetime ( self : copy self )
126
138
public mutating func skipBack( by n: Int ) -> Int {
127
139
var numSkipped = 0
@@ -132,35 +144,39 @@ extension UTF8Span {
132
144
return numSkipped
133
145
}
134
146
147
+ // TODO: Example for reset docs
148
+
135
149
/// Reset to the nearest scalar-aligned code unit offset `<= i`.
136
150
///
137
- /// **TODO**: Example
151
+ /// - Complexity: O(1)
138
152
@lifetime ( self : copy self )
139
153
public mutating func reset( roundingBackwardsFrom i: Int ) {
140
154
self . currentCodeUnitOffset = codeUnits. _scalarAlignBackwards ( i)
141
155
}
142
156
143
157
/// Reset to the nearest scalar-aligned code unit offset `>= i`.
144
158
///
145
- /// **TODO**: Example
159
+ /// - Complexity: O(1)
146
160
@lifetime ( self : copy self )
147
161
public mutating func reset( roundingForwardsFrom i: Int ) {
148
162
self . currentCodeUnitOffset = codeUnits. _scalarAlignForwards ( i)
149
163
}
150
164
165
+ // TODO: for below, verify that there is no path to UB, just garabage-data or guaranteed
166
+ // trap!
167
+
151
168
/// Reset this iterator to `codeUnitOffset`, skipping _all_ safety
152
169
/// checks (including bounds checks).
153
170
///
154
171
/// Note: This is only for very specific, low-level use cases. If
155
172
/// `codeUnitOffset` is not properly scalar-aligned, this function can
156
173
/// result in undefined behavior when, e.g., `next()` is called.
157
174
///
158
- /// TODO: verify that we're not UB, just garabage-data or guaranteed
159
- /// trap!
160
- ///
161
175
/// For example, this could be used by a regex engine to backtrack to a
162
176
/// known-valid previous position.
163
177
///
178
+ ///
179
+ /// - Complexity: O(1)
164
180
@unsafe
165
181
@lifetime ( self : copy self )
166
182
public mutating func reset( toUnchecked codeUnitOffset: Int ) {
@@ -172,6 +188,8 @@ extension UTF8Span {
172
188
/// current position.
173
189
///
174
190
/// The resultant `UTF8Span` has the same lifetime constraints as `self`.
191
+ ///
192
+ /// - Complexity: O(1)
175
193
@lifetime ( copy self)
176
194
public func prefix( ) -> UTF8Span {
177
195
let slice = codeUnits. span. extracting ( 0 ..< currentCodeUnitOffset)
@@ -185,6 +203,8 @@ extension UTF8Span {
185
203
/// current position.
186
204
///
187
205
/// The resultant `UTF8Span` has the same lifetime constraints as `self`.
206
+ ///
207
+ /// - Complexity: O(1)
188
208
@lifetime ( copy self)
189
209
public func suffix( ) -> UTF8Span {
190
210
let slice = codeUnits. span. extracting ( currentCodeUnitOffset..< codeUnits. count)
@@ -208,9 +228,9 @@ extension UTF8Span {
208
228
. init( self )
209
229
}
210
230
231
+ // **TODO**: Examples in below doc
232
+
211
233
/// Iterate the `Character` contents of a `UTF8Span`.
212
- ///
213
- /// **TODO**: Examples
214
234
public struct CharacterIterator : ~ Escapable {
215
235
public let codeUnits : UTF8Span
216
236
0 commit comments