Numeric character property related functions.
Since: 0.3.0
Predicates
isNumeric :: Char -> Bool Source #
Selects Unicode character with a numeric value.
Note: a character may have a numeric value but return False
with
the predicate isNumber
, because
isNumber
only tests
GeneralCategory
: some CJK characters are
OtherLetter
and do have a numeric value.
isNumeric c == isJust (numericValue c)
Since: 0.3.1
isNumber :: Char -> Bool Source #
Deprecated: Use Unicode.Char.Numeric.Compat.isNumber instead. This function will be a synonym for isNumeric in a future release. See Unicode.Char.Numeric.Compat for behavior compatible with base:Data.Char.
Selects Unicode numeric characters, including digits from various scripts, Roman numerals, et cetera.
This function returns True
if its argument has one of the
following GeneralCategory
s, or False
otherwise:
Note: a character may have a numeric value (see numericValue
) but return
False
, because isNumber
only tests GeneralCategory
:
some CJK characters are OtherLetter
and do have a
numeric value. Use isNumeric
to cover those cases as well.
isNumber c == Data.Char.isNumber c
Since: 0.3.0
Numeric values
numericValue :: Char -> Maybe Rational Source #
Numeric value of a character, if relevant.
Note: a character may have a numeric value but return False
with
the predicate isNumber
, because
isNumber
only tests
GeneralCategory
: some CJK characters are
OtherLetter
and do have a numeric value.
Since: 0.3.1
integerValue :: Char -> Maybe Int Source #
Integer value of a character, if relevant.
This is a special case of numericValue
.
Note: a character may have a numeric value but return False
with
the predicate isNumber
, because
isNumber
only tests
GeneralCategory
: some CJK characters are
OtherLetter
and do have a numeric value.
Since: 0.3.1
Re-export from base
isOctDigit :: Char -> Bool Source #
Selects ASCII octal digits, i.e. '0'
..'7'
.
isHexDigit :: Char -> Bool Source #
Selects ASCII hexadecimal digits,
i.e. '0'
..'9'
, 'a'
..'f'
, 'A'
..'F'
.
digitToInt :: Char -> Int Source #
Convert a single digit Char
to the corresponding Int
. This
function fails unless its argument satisfies isHexDigit
, but
recognises both upper- and lower-case hexadecimal digits (that
is, '0'
..'9'
, 'a'
..'f'
, 'A'
..'F'
).
Examples
Characters '0'
through '9'
are converted properly to
0..9
:
>>>
map digitToInt ['0'..'9']
[0,1,2,3,4,5,6,7,8,9]
Both upper- and lower-case 'A'
through 'F'
are converted
as well, to 10..15
.
>>>
map digitToInt ['a'..'f']
[10,11,12,13,14,15]>>>
map digitToInt ['A'..'F']
[10,11,12,13,14,15]
Anything else throws an exception:
>>>
digitToInt 'G'
*** Exception: Char.digitToInt: not a digit 'G'>>>
digitToInt '♥'
*** Exception: Char.digitToInt: not a digit '\9829'