unicode-data-0.3.0: Access Unicode character database
Copyright(c) 2020 Composewell Technologies and Contributors
LicenseApache-2.0
Maintainerstreamly@composewell.com
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

Unicode.Char.Numeric

Contents

Description

Numeric character property related functions.

Synopsis

Documentation

isNumber :: Char -> Bool Source #

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 GeneralCategorys, or False otherwise:

isNumber c == Data.Char.isNumber c

Since: 0.3.0

Re-export

isDigit :: Char -> Bool #

Selects ASCII digits, i.e. '0'..'9'.

isOctDigit :: Char -> Bool #

Selects ASCII octal digits, i.e. '0'..'7'.

isHexDigit :: Char -> Bool #

Selects ASCII hexadecimal digits, i.e. '0'..'9', 'a'..'f', 'A'..'F'.

digitToInt :: Char -> Int #

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

Expand

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'

intToDigit :: Int -> Char #

Convert an Int in the range 0..15 to the corresponding single digit Char. This function fails on other inputs, and generates lower-case hexadecimal digits.