Copyright | (c) 2020 Composewell Technologies and Contributors |
---|---|
License | Apache-2.0 |
Maintainer | streamly@composewell.com |
Stability | experimental |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Unicode.Char.Numeric
Description
Numeric character property related functions.
Since: 0.3.0
Synopsis
- isNumeric :: Char -> Bool
- numericValue :: Char -> Maybe Rational
- integerValue :: Integral a => Char -> Maybe a
- intToDigiT :: Int -> Char
- isDigit :: Char -> Bool
- isOctDigit :: Char -> Bool
- isHexDigit :: Char -> Bool
- digitToInt :: Char -> Int
- intToDigit :: Int -> Char
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
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 :: Integral a => Char -> Maybe a Source #
Integer value of a character, if relevant.
This is a special case of numericValue
.
Warning: There is a risk of integer overflow depending of the chosen concrete return type. As of Unicode 15.1 the results range from 0 to 1e16.
>>>
minimum [v | v@Just{} <- integerValue <$> [minBound..]] :: Maybe Integer
Just 0>>>
maximum (integerValue <$> [minBound..]) :: Maybe Integer
Just 10000000000000000>>>
integerValue '\x4EAC' :: Maybe Int64 -- OK
Just 10000000000000000>>>
integerValue '\x4EAC' :: Maybe Int32 -- Will overflow!
Just 1874919424
Therefore it is advised to use:
.integerValue
@Int64
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
Single digit characters
intToDigiT :: Int -> Char Source #
Re-export from base
isOctDigit :: Char -> Bool #
isHexDigit :: Char -> Bool #
digitToInt :: Char -> Int #
intToDigit :: Int -> Char #