unicode-data-0.6.0: Access Unicode Character Database (UCD)
Copyright(c) 2020 Composewell Technologies and Contributors
LicenseApache-2.0
Maintainerstreamly@composewell.com
Stabilityexperimental
Safe HaskellSafe-Inferred
LanguageHaskell2010

Unicode.Char.Numeric

Description

Numeric character property related functions.

Since: 0.3.0

Synopsis

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 #

Same a intToDigit, but with upper case.

>>> intToDigiT <$> [0..15]
"0123456789ABCDEF"

Since: 0.6.0

Re-export from base

isDigit :: Char -> Bool #

isOctDigit :: Char -> Bool #

isHexDigit :: Char -> Bool #

digitToInt :: Char -> Int #

intToDigit :: Int -> Char #