@@ -131,57 +131,43 @@ public extension String {
131
131
return self [ 0 ..< index] ! + string + self [ index..< length] !
132
132
}
133
133
134
- /**
135
- Strips whitespaces from the beginning of self.
136
-
137
- :returns: Stripped string
138
- */
139
- func ltrimmed ( ) -> String {
140
- return ltrimmed ( NSCharacterSet . whitespaceAndNewlineCharacterSet ( ) )
141
- }
142
-
143
134
/**
144
135
Strips the specified characters from the beginning of self.
145
136
146
137
:returns: Stripped string
147
138
*/
148
- func ltrimmed ( set: NSCharacterSet ) -> String {
139
+ func trimmedLeft ( set: NSCharacterSet = NSCharacterSet . whitespaceAndNewlineCharacterSet ( ) ) -> String {
149
140
if let range = rangeOfCharacterFromSet ( set. invertedSet) {
150
141
return self [ range. startIndex..< endIndex]
151
142
}
152
143
153
144
return " "
154
145
}
155
-
156
- /**
157
- Strips whitespaces from the end of self.
158
146
159
- :returns: Stripped string
160
- */
161
- func rtrimmed ( ) -> String {
162
- return rtrimmed ( NSCharacterSet . whitespaceAndNewlineCharacterSet ( ) )
163
- }
147
+ @availability ( * , unavailable, message= " use 'trimmedLeft' instead " ) func ltrimmed ( set: NSCharacterSet = NSCharacterSet . whitespaceAndNewlineCharacterSet ( ) ) -> String { }
164
148
165
149
/**
166
150
Strips the specified characters from the end of self.
167
151
168
152
:returns: Stripped string
169
153
*/
170
- func rtrimmed ( set: NSCharacterSet ) -> String {
154
+ func trimmedRight ( set: NSCharacterSet = NSCharacterSet . whitespaceAndNewlineCharacterSet ( ) ) -> String {
171
155
if let range = rangeOfCharacterFromSet ( set. invertedSet, options: NSStringCompareOptions . BackwardsSearch) {
172
156
return self [ startIndex..< range. endIndex]
173
157
}
174
158
175
159
return " "
176
160
}
177
-
161
+
162
+ @availability ( * , unavailable, message= " use 'trimmedRight' instead " ) func rtrimmed ( set: NSCharacterSet = NSCharacterSet . whitespaceAndNewlineCharacterSet ( ) ) -> String { }
163
+
178
164
/**
179
165
Strips whitespaces from both the beginning and the end of self.
180
166
181
167
:returns: Stripped string
182
168
*/
183
169
func trimmed ( ) -> String {
184
- return ltrimmed ( ) . rtrimmed ( )
170
+ return trimmedLeft ( ) . trimmedRight ( )
185
171
}
186
172
187
173
/**
@@ -307,53 +293,73 @@ public extension String {
307
293
Repeats the string first n times
308
294
*/
309
295
public func * ( first: String , n: Int ) -> String {
296
+
310
297
var result = String ( )
311
298
312
299
n. times {
313
300
result += first
314
301
}
315
302
316
303
return result
304
+
317
305
}
318
306
319
307
// Pattern matching using a regular expression
320
308
public func =~ ( string: String , pattern: String ) -> Bool {
309
+
321
310
let regex = ExSwift . regex ( pattern, ignoreCase: false ) !
322
311
let matches = regex. numberOfMatchesInString ( string, options: nil , range: NSMakeRange ( 0 , string. length) )
312
+
323
313
return matches > 0
314
+
324
315
}
325
316
326
317
// Pattern matching using a regular expression
327
318
public func =~ ( string: String , regex: NSRegularExpression ) -> Bool {
319
+
328
320
let matches = regex. numberOfMatchesInString ( string, options: nil , range: NSMakeRange ( 0 , string. length) )
321
+
329
322
return matches > 0
323
+
330
324
}
331
325
332
326
// This version also allowes to specify case sentitivity
333
327
public func =~ ( string: String , options: ( pattern: String , ignoreCase: Bool ) ) -> Bool {
328
+
334
329
if let matches = ExSwift . regex ( options. pattern, ignoreCase: options. ignoreCase) ? . numberOfMatchesInString ( string, options: nil , range: NSMakeRange ( 0 , string. length) ) {
335
330
return matches > 0
336
331
}
337
332
338
333
return false
334
+
339
335
}
340
336
341
337
// Match against all the alements in an array of String
342
338
public func =~ ( strings: [ String ] , pattern: String ) -> Bool {
339
+
343
340
let regex = ExSwift . regex ( pattern, ignoreCase: false ) !
341
+
344
342
return strings. all { 0ドル =~ regex }
343
+
345
344
}
346
345
347
346
public func =~ ( strings: [ String ] , options: ( pattern: String , ignoreCase: Bool ) ) -> Bool {
347
+
348
348
return strings. all { 0ドル =~ options }
349
+
349
350
}
350
351
351
352
// Match against any element in an array of String
352
353
public func |~ ( strings: [ String ] , pattern: String ) -> Bool {
354
+
353
355
let regex = ExSwift . regex ( pattern, ignoreCase: false ) !
356
+
354
357
return strings. any { 0ドル =~ regex }
358
+
355
359
}
356
360
357
361
public func |~ ( strings: [ String ] , options: ( pattern: String , ignoreCase: Bool ) ) -> Bool {
362
+
358
363
return strings. any { 0ドル =~ options }
364
+
359
365
}
0 commit comments