Safe Haskell | None |
---|---|
Language | Haskell2010 |
Functions for working with characters. Character literals are enclosed in 'a'
pair of single quotes.
Since we don't have a browser and we don't have a default locale, functions
like toLocaleUpper
and toLocaleUpper
are not supported. If you need
something like that you can check out the 'text-icu' package which provides
functions like toUpper :: LocaleName -> Text -> Text
.
Characters
The character type Char
is an enumeration whose values represent
Unicode (or equivalently ISO/IEC 10646) code points (i.e. characters, see
http://www.unicode.org/ for details). This set extends the ISO 8859-1
(Latin-1) character set (the first 256 characters), which is itself an extension
of the ASCII character set (the first 128 characters). A character literal in
Haskell has type Char
.
To convert a Char
to or from the corresponding Int
value defined
by Unicode, use toEnum
and fromEnum
from the
Enum
class respectively (or equivalently ord
and
chr
).
Instances
ASCII Letters
isUpper :: Char -> Bool Source #
Detect upper case ASCII characters.
isUpper 'A' == True isUpper 'B' == True ... isUpper 'Z' == True
isUpper '0' == False isUpper 'a' == False isUpper '-' == False isUpper 'Σ' == False
isLower :: Char -> Bool Source #
Detect lower case ASCII characters.
isLower 'a' == True isLower 'b' == True ... isLower 'z' == True
isLower '0' == False isLower 'A' == False isLower '-' == False isLower 'π' == False
isAlpha :: Char -> Bool Source #
Detect upper case and lower case ASCII characters.
isAlpha 'a' == True isAlpha 'b' == True isAlpha 'E' == True isAlpha 'Y' == True
isAlpha '0' == False isAlpha '-' == False isAlpha 'π' == False
isAlphaNum :: Char -> Bool Source #
Detect upper case and lower case ASCII characters.
isAlphaNum 'a' == True isAlphaNum 'b' == True isAlphaNum 'E' == True isAlphaNum 'Y' == True isAlphaNum '0' == True isAlphaNum '7' == True
isAlphaNum '-' == False isAlphaNum 'π' == False
Digits
isDigit :: Char -> Bool Source #
Detect digits 0123456789
isDigit '0' == True isDigit '1' == True ... isDigit '9' == True
isDigit 'a' == False isDigit 'b' == False isDigit 'A' == False
isOctDigit :: Char -> Bool Source #
Detect octal digits 01234567
isOctDigit '0' == True isOctDigit '1' == True ... isOctDigit '7' == True
isOctDigit '8' == False isOctDigit 'a' == False isOctDigit 'A' == False
isHexDigit :: Char -> Bool Source #
Detect hexadecimal digits 0123456789abcdefABCDEF
Conversion
Unicode Code Points
toCode :: Char -> Int Source #
Convert to the corresponding Unicode code point.
toCode 'A' == 65 toCode 'B' == 66 toCode '木' == 26408 toCode '𝌆' == 0x1D306 toCode '😃' == 0x1F603
fromCode :: Int -> Char Source #
Convert a Unicode code point to a character.
fromCode 65 == 'A' fromCode 66 == 'B' fromCode 0x6728 == '\26408' -- '木' fromCode 0x1D306 == '\119558' -- '𝌆' fromCode 0x1F603 == '\128515' -- '😃' fromCode (-1) == '\65533' -- '�'
The full range of unicode is from 0
to 0x10FFFF
. With numbers outside that
range, you get the replacement character#Replacement_character).