Skip to content

Instantly share code, notes, and snippets.

@ha1f
Last active December 20, 2017 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ha1f/7bd5f6d3e9645ececf0da081a2225987 to your computer and use it in GitHub Desktop.
Save ha1f/7bd5f6d3e9645ececf0da081a2225987 to your computer and use it in GitHub Desktop.
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