This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension String { | |
func camelCaseToSnakeCase() -> String { | |
let acronymPattern = "([A-Z]+)([A-Z][a-z]|[0-9])" | |
let normalPattern = "([a-z0-9])([A-Z])" | |
return self.processCamalCaseRegex(pattern: acronymPattern)? | |
.processCamalCaseRegex(pattern: normalPattern)?.lowercased() ?? self.lowercased() | |
} | |
fileprivate func processCamalCaseRegex(pattern: String) -> String? { | |
let regex = try? NSRegularExpression(pattern: pattern, options: []) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
Version 2, December 2004 | |
Copyright (C) 2016 Esa-Matti Suuronen <[email protected]> | |
Everyone is permitted to copy and distribute verbatim or modified | |
copies of this license document, and changing it is allowed as long | |
as the name is changed. |