Last active
December 20, 2017 15:54
-
-
Save ha1f/7bd5f6d3e9645ececf0da081a2225987 to your computer and use it in GitHub Desktop.
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
import Foundation | |
extension UnicodeScalar { | |
/// `a-z{ | |
var isLowerCase: Bool { | |
return value >= 0x61 && value <= 0x7a | |
} | |
/// @A-Z[ | |
var isUpperCase: Bool { | |
return value >= 0x41 && value <= 0x5a | |
} | |
func uppercased() -> UnicodeScalar { | |
if isLowerCase { | |
return UnicodeScalar(value - 0x20)! | |
} else { | |
return self | |
} | |
} | |
func lowercased() -> UnicodeScalar { | |
if isUpperCase { | |
return UnicodeScalar(value + 0x20)! | |
} else { | |
return self | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment