Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 53b6941

Browse files
committed
String: ltrimmed renamed to trimmedLeft
String: rtrimmed renamed to trimmedRight
1 parent cdfb586 commit 53b6941

File tree

2 files changed

+29
-21
lines changed

2 files changed

+29
-21
lines changed

‎ExSwift/Int.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ public extension Int {
212212
NSTimeInterval conversion extensions
213213
*/
214214
public extension Int {
215+
215216
var years: NSTimeInterval {
216217
return 365 * self.days
217218
}
@@ -251,4 +252,5 @@ public extension Int {
251252
var second: NSTimeInterval {
252253
return self.seconds
253254
}
255+
254256
}

‎ExSwift/String.swift

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -131,57 +131,43 @@ public extension String {
131131
return self[0..<index]! + string + self[index..<length]!
132132
}
133133

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-
143134
/**
144135
Strips the specified characters from the beginning of self.
145136

146137
:returns: Stripped string
147138
*/
148-
func ltrimmed (set: NSCharacterSet) -> String {
139+
func trimmedLeft (set: NSCharacterSet=NSCharacterSet.whitespaceAndNewlineCharacterSet()) -> String {
149140
if let range = rangeOfCharacterFromSet(set.invertedSet) {
150141
return self[range.startIndex..<endIndex]
151142
}
152143

153144
return ""
154145
}
155-
156-
/**
157-
Strips whitespaces from the end of self.
158146

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 { }
164148

165149
/**
166150
Strips the specified characters from the end of self.
167151

168152
:returns: Stripped string
169153
*/
170-
func rtrimmed (set: NSCharacterSet) -> String {
154+
func trimmedRight (set: NSCharacterSet=NSCharacterSet.whitespaceAndNewlineCharacterSet()) -> String {
171155
if let range = rangeOfCharacterFromSet(set.invertedSet, options: NSStringCompareOptions.BackwardsSearch) {
172156
return self[startIndex..<range.endIndex]
173157
}
174158

175159
return ""
176160
}
177-
161+
162+
@availability(*, unavailable, message="use 'trimmedRight' instead") func rtrimmed (set: NSCharacterSet = NSCharacterSet.whitespaceAndNewlineCharacterSet()) -> String { }
163+
178164
/**
179165
Strips whitespaces from both the beginning and the end of self.
180166

181167
:returns: Stripped string
182168
*/
183169
func trimmed () -> String {
184-
return ltrimmed().rtrimmed()
170+
return trimmedLeft().trimmedRight()
185171
}
186172

187173
/**
@@ -307,53 +293,73 @@ public extension String {
307293
Repeats the string first n times
308294
*/
309295
public func * (first: String, n: Int) -> String {
296+
310297
var result = String()
311298

312299
n.times {
313300
result += first
314301
}
315302

316303
return result
304+
317305
}
318306

319307
// Pattern matching using a regular expression
320308
public func =~ (string: String, pattern: String) -> Bool {
309+
321310
let regex = ExSwift.regex(pattern, ignoreCase: false)!
322311
let matches = regex.numberOfMatchesInString(string, options: nil, range: NSMakeRange(0, string.length))
312+
323313
return matches > 0
314+
324315
}
325316

326317
// Pattern matching using a regular expression
327318
public func =~ (string: String, regex: NSRegularExpression) -> Bool {
319+
328320
let matches = regex.numberOfMatchesInString(string, options: nil, range: NSMakeRange(0, string.length))
321+
329322
return matches > 0
323+
330324
}
331325

332326
// This version also allowes to specify case sentitivity
333327
public func =~ (string: String, options: (pattern: String, ignoreCase: Bool)) -> Bool {
328+
334329
if let matches = ExSwift.regex(options.pattern, ignoreCase: options.ignoreCase)?.numberOfMatchesInString(string, options: nil, range: NSMakeRange(0, string.length)) {
335330
return matches > 0
336331
}
337332

338333
return false
334+
339335
}
340336

341337
// Match against all the alements in an array of String
342338
public func =~ (strings: [String], pattern: String) -> Bool {
339+
343340
let regex = ExSwift.regex(pattern, ignoreCase: false)!
341+
344342
return strings.all { 0ドル =~ regex }
343+
345344
}
346345

347346
public func =~ (strings: [String], options: (pattern: String, ignoreCase: Bool)) -> Bool {
347+
348348
return strings.all { 0ドル =~ options }
349+
349350
}
350351

351352
// Match against any element in an array of String
352353
public func |~ (strings: [String], pattern: String) -> Bool {
354+
353355
let regex = ExSwift.regex(pattern, ignoreCase: false)!
356+
354357
return strings.any { 0ドル =~ regex }
358+
355359
}
356360

357361
public func |~ (strings: [String], options: (pattern: String, ignoreCase: Bool)) -> Bool {
362+
358363
return strings.any { 0ドル =~ options }
364+
359365
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /