-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStrings.swift
More file actions
34 lines (26 loc) · 798 Bytes
/
Strings.swift
File metadata and controls
34 lines (26 loc) · 798 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
34
//
// Strings.swift
// textToCode
//
// from https://gist.github.com/reitzig/67b41e75176ddfd432cb09392a270218
//
//
import Foundation
fileprivate let badChars = CharacterSet.alphanumerics.inverted
extension String {
var uppercasingFirst: String {
return prefix(1).uppercased() + dropFirst()
}
var lowercasingFirst: String {
return prefix(1).lowercased() + dropFirst()
}
var camelized: String {
guard !isEmpty else {
return ""
}
let parts = self.components(separatedBy: badChars)
let first = String(describing: parts.first!).lowercasingFirst
let rest = parts.dropFirst().map({String($0).uppercasingFirst})
return ([first] + rest).joined(separator: "")
}
}