forked from intitni/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathString+Extension.swift
More file actions
33 lines (29 loc) · 974 Bytes
/
String+Extension.swift
File metadata and controls
33 lines (29 loc) · 974 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import Foundation
public extension String {
func removedTrailingWhitespacesAndNewlines() -> String {
var text = self[...]
while let last = text.last, last.isNewline || last.isWhitespace {
text = text.dropLast(1)
}
return String(text)
}
func removedTrailingCharacters(in set: CharacterSet) -> String {
var text = self[...]
while let last = text.last, set.containsUnicodeScalars(of: last) {
text = text.dropLast(1)
}
return String(text)
}
func removeLeadingCharacters(in set: CharacterSet) -> String {
var text = self[...]
while let first = text.first, set.containsUnicodeScalars(of: first) {
text = text.dropFirst()
}
return String(text)
}
}
extension CharacterSet {
func containsUnicodeScalars(of character: Character) -> Bool {
return character.unicodeScalars.allSatisfy(contains(_:))
}
}