@@ -58,64 +58,7 @@ extension Optional {
58
58
}
59
59
}
60
60
61
-
62
61
extension String {
63
-
64
- //===--- Bridging Helpers -----------------------------------------------===//
65
- //===--------------------------------------------------------------------===//
66
-
67
- /// The corresponding `NSString` - a convenience for bridging code.
68
- var _ns : NSString {
69
- return self as NSString
70
- }
71
-
72
- /// Return an `Index` corresponding to the given offset in our UTF-16
73
- /// representation.
74
- func _index( _ utf16Index: Int ) -> Index {
75
- return Index ( encodedOffset: utf16Index)
76
- }
77
-
78
- /// Return a `Range<Index>` corresponding to the given `NSRange` of
79
- /// our UTF-16 representation.
80
- func _range( _ r: NSRange ) -> Range < Index > {
81
- return _index ( r. location) ..< _index ( r. location + r. length)
82
- }
83
-
84
- /// Return a `Range<Index>?` corresponding to the given `NSRange` of
85
- /// our UTF-16 representation.
86
- func _optionalRange( _ r: NSRange ) -> Range < Index > ? {
87
- if r. location == NSNotFound {
88
- return nil
89
- }
90
- return _range ( r)
91
- }
92
-
93
- /// Invoke `body` on an `Int` buffer. If `index` was converted from
94
- /// non-`nil`, convert the buffer to an `Index` and write it into the
95
- /// memory referred to by `index`
96
- func _withOptionalOutParameter< Result> (
97
- _ index: UnsafeMutablePointer < Index > ? ,
98
- _ body: ( UnsafeMutablePointer < Int > ? ) -> Result
99
- ) -> Result {
100
- var utf16Index : Int = 0
101
- let result = ( index != nil ? body ( & utf16Index) : body ( nil ) )
102
- index? . pointee = self . _index ( utf16Index)
103
- return result
104
- }
105
-
106
- /// Invoke `body` on an `NSRange` buffer. If `range` was converted
107
- /// from non-`nil`, convert the buffer to a `Range<Index>` and write
108
- /// it into the memory referred to by `range`
109
- func _withOptionalOutParameter< Result> (
110
- _ range: UnsafeMutablePointer < Range < Index > > ? ,
111
- _ body: ( UnsafeMutablePointer < NSRange > ? ) -> Result
112
- ) -> Result {
113
- var nsRange = NSRange ( location: 0 , length: 0 )
114
- let result = ( range != nil ? body ( & nsRange) : body ( nil ) )
115
- range? . pointee = self . _range ( nsRange)
116
- return result
117
- }
118
-
119
62
//===--- Class Methods --------------------------------------------------===//
120
63
//===--------------------------------------------------------------------===//
121
64
@@ -227,6 +170,64 @@ extension String {
227
170
return nil
228
171
}
229
172
}
173
+ }
174
+
175
+ extension String {
176
+
177
+ //===--- Bridging Helpers -----------------------------------------------===//
178
+ //===--------------------------------------------------------------------===//
179
+
180
+ /// The corresponding `NSString` - a convenience for bridging code.
181
+ var _ns : NSString {
182
+ return self as NSString
183
+ }
184
+
185
+ /// Return an `Index` corresponding to the given offset in our UTF-16
186
+ /// representation.
187
+ func _index( _ utf16Index: Int ) -> Index {
188
+ return Index ( encodedOffset: utf16Index)
189
+ }
190
+
191
+ /// Return a `Range<Index>` corresponding to the given `NSRange` of
192
+ /// our UTF-16 representation.
193
+ func _range( _ r: NSRange ) -> Range < Index > {
194
+ return _index ( r. location) ..< _index ( r. location + r. length)
195
+ }
196
+
197
+ /// Return a `Range<Index>?` corresponding to the given `NSRange` of
198
+ /// our UTF-16 representation.
199
+ func _optionalRange( _ r: NSRange ) -> Range < Index > ? {
200
+ if r. location == NSNotFound {
201
+ return nil
202
+ }
203
+ return _range ( r)
204
+ }
205
+
206
+ /// Invoke `body` on an `Int` buffer. If `index` was converted from
207
+ /// non-`nil`, convert the buffer to an `Index` and write it into the
208
+ /// memory referred to by `index`
209
+ func _withOptionalOutParameter< Result> (
210
+ _ index: UnsafeMutablePointer < Index > ? ,
211
+ _ body: ( UnsafeMutablePointer < Int > ? ) -> Result
212
+ ) -> Result {
213
+ var utf16Index : Int = 0
214
+ let result = ( index != nil ? body ( & utf16Index) : body ( nil ) )
215
+ index? . pointee = self . _index ( utf16Index)
216
+ return result
217
+ }
218
+
219
+ /// Invoke `body` on an `NSRange` buffer. If `range` was converted
220
+ /// from non-`nil`, convert the buffer to a `Range<Index>` and write
221
+ /// it into the memory referred to by `range`
222
+ func _withOptionalOutParameter< Result> (
223
+ _ range: UnsafeMutablePointer < Range < Index > > ? ,
224
+ _ body: ( UnsafeMutablePointer < NSRange > ? ) -> Result
225
+ ) -> Result {
226
+ var nsRange = NSRange ( location: 0 , length: 0 )
227
+ let result = ( range != nil ? body ( & nsRange) : body ( nil ) )
228
+ range? . pointee = self . _range ( nsRange)
229
+ return result
230
+ }
230
231
231
232
//===--- Instance Methods/Properties-------------------------------------===//
232
233
//===--------------------------------------------------------------------===//
0 commit comments