Text.Ascii

text-latin1-0.3: Latin-1 (including ASCII) utility functions

Safe Haskell | Safe
Language | Haskell98

Text.Ascii

Contents

- ASCII checks
- Character properties
- Byte properties

Description

ASCII utility functions.

Synopsis

- data IsAscii = IsAscii
- isAscii :: Property IsAscii v => v -> Bool
- type Ascii α = Checked IsAscii α
- maybeAscii :: Char -> Maybe Word8
- ascii :: Char -> Word8
- isControl :: Char -> Bool
- isPrintable :: Char -> Bool
- isWhiteSpace :: Char -> Bool
- isSpaceOrTab :: Char -> Bool
- isLower :: Char -> Bool
- isUpper :: Char -> Bool
- toLower :: Char -> Char
- toUpper :: Char -> Char
- isAlpha :: Char -> Bool
- isAlphaNum :: Char -> Bool
- isDecDigit :: Char -> Bool
- isNzDecDigit :: Char -> Bool
- fromDecDigit :: Num a => Char -> Maybe a
- fromNzDecDigit :: Num a => Char -> Maybe a
- unsafeFromDecDigit :: Num a => Char -> a
- isBinDigit :: Char -> Bool
- isNzBinDigit :: Char -> Bool
- fromBinDigit :: Num a => Char -> Maybe a
- fromNzBinDigit :: Num a => Char -> Maybe a
- unsafeFromBinDigit :: Num a => Char -> a
- isOctDigit :: Char -> Bool
- isNzOctDigit :: Char -> Bool
- fromOctDigit :: Num a => Char -> Maybe a
- fromNzOctDigit :: Num a => Char -> Maybe a
- unsafeFromOctDigit :: Num a => Char -> a
- isUpHexDigit :: Char -> Bool
- isNzUpHexDigit :: Char -> Bool
- fromUpHexDigit :: Num a => Char -> Maybe a
- fromNzUpHexDigit :: Num a => Char -> Maybe a
- unsafeFromUpHexDigit :: Num a => Char -> a
- isLowHexDigit :: Char -> Bool
- isNzLowHexDigit :: Char -> Bool
- fromLowHexDigit :: Num a => Char -> Maybe a
- fromNzLowHexDigit :: Num a => Char -> Maybe a
- unsafeFromLowHexDigit :: Num a => Char -> a
- isHexDigit :: Char -> Bool
- isNzHexDigit :: Char -> Bool
- fromHexDigit :: Num a => Char -> Maybe a
- fromNzHexDigit :: Num a => Char -> Maybe a
- unsafeFromHexDigit :: Num a => Char -> a
- isControl8 :: Word8 -> Bool
- isPrintable8 :: Word8 -> Bool
- isWhiteSpace8 :: Word8 -> Bool
- isSpaceOrTab8 :: Word8 -> Bool
- isLower8 :: Word8 -> Bool
- isUpper8 :: Word8 -> Bool
- toLower8 :: Word8 -> Word8
- toUpper8 :: Word8 -> Word8
- isAlpha8 :: Word8 -> Bool
- isAlphaNum8 :: Word8 -> Bool
- isDecDigit8 :: Word8 -> Bool
- isNzDecDigit8 :: Word8 -> Bool
- fromDecDigit8 :: Num a => Word8 -> Maybe a
- fromNzDecDigit8 :: Num a => Word8 -> Maybe a
- unsafeFromDecDigit8 :: Num a => Word8 -> a
- isBinDigit8 :: Word8 -> Bool
- isNzBinDigit8 :: Word8 -> Bool
- fromBinDigit8 :: Num a => Word8 -> Maybe a
- fromNzBinDigit8 :: Num a => Word8 -> Maybe a
- unsafeFromBinDigit8 :: Num a => Word8 -> a
- isOctDigit8 :: Word8 -> Bool
- isNzOctDigit8 :: Word8 -> Bool
- fromOctDigit8 :: Num a => Word8 -> Maybe a
- fromNzOctDigit8 :: Num a => Word8 -> Maybe a
- unsafeFromOctDigit8 :: Num a => Word8 -> a
- isUpHexDigit8 :: Word8 -> Bool
- isNzUpHexDigit8 :: Word8 -> Bool
- fromUpHexDigit8 :: Num a => Word8 -> Maybe a
- fromNzUpHexDigit8 :: Num a => Word8 -> Maybe a
- unsafeFromUpHexDigit8 :: Num a => Word8 -> a
- isLowHexDigit8 :: Word8 -> Bool
- isNzLowHexDigit8 :: Word8 -> Bool
- fromLowHexDigit8 :: Num a => Word8 -> Maybe a
- fromNzLowHexDigit8 :: Num a => Word8 -> Maybe a
- unsafeFromLowHexDigit8 :: Num a => Word8 -> a
- isHexDigit8 :: Word8 -> Bool
- isNzHexDigit8 :: Word8 -> Bool
- fromHexDigit8 :: Num a => Word8 -> Maybe a
- fromNzHexDigit8 :: Num a => Word8 -> Maybe a
- unsafeFromHexDigit8 :: Num a => Word8 -> a

# ASCII checks

data IsAscii #

Constructors

IsAscii |

Instances

Property IsAscii Char # |
Methods holds :: IsAscii -> Char -> Bool #
Property IsAscii Word8 # |
Methods holds :: IsAscii -> Word8 -> Bool #
Property IsAscii ByteString # |
Methods holds :: IsAscii -> ByteString -> Bool #
Property IsAscii ByteString # |
Methods holds :: IsAscii -> ByteString -> Bool #
Property IsAscii Text # |
Methods holds :: IsAscii -> Text -> Bool #
Property IsAscii Text # |
Methods holds :: IsAscii -> Text -> Bool #
Property IsAscii α => Property IsAscii [α] # |
Methods holds :: IsAscii -> [α] -> Bool #
Eq α => Eq (Ascii α) # |
Methods (==) :: Ascii α -> Ascii α -> Bool # (/=) :: Ascii α -> Ascii α -> Bool #
Ord α => Ord (Ascii α) # |
Methods compare :: Ascii α -> Ascii α -> Ordering # (<) :: Ascii α -> Ascii α -> Bool # (<=) :: Ascii α -> Ascii α -> Bool # (>) :: Ascii α -> Ascii α -> Bool # (>=) :: Ascii α -> Ascii α -> Bool # max :: Ascii α -> Ascii α -> Ascii α # min :: Ascii α -> Ascii α -> Ascii α #
Show α => Show (Ascii α) # |
Methods showsPrec :: Int -> Ascii α -> ShowS # show :: Ascii α -> String # showList :: [Ascii α] -> ShowS #
IsString α => IsString (Ascii α) # |
Methods fromString :: String -> Ascii α #
Monoid α => Monoid (Ascii α) # |
Methods mempty :: Ascii α # mappend :: Ascii α -> Ascii α -> Ascii α # mconcat :: [Ascii α] -> Ascii α #
FoldCase (Ascii Char) # |
Methods foldCase :: Ascii Char -> Ascii Char # foldCaseList :: [Ascii Char] -> [Ascii Char]
FoldCase (Ascii α) => FoldCase (Ascii [α]) # |
Methods foldCase :: Ascii [α] -> Ascii [α] # foldCaseList :: [Ascii [α]] -> [Ascii [α]]
FoldCase (Ascii ByteString) # |
Methods foldCase :: Ascii ByteString -> Ascii ByteString # foldCaseList :: [Ascii ByteString] -> [Ascii ByteString]
FoldCase (Ascii ByteString) # |
Methods foldCase :: Ascii ByteString -> Ascii ByteString # foldCaseList :: [Ascii ByteString] -> [Ascii ByteString]
FoldCase (Ascii Text) # |
Methods foldCase :: Ascii Text -> Ascii Text # foldCaseList :: [Ascii Text] -> [Ascii Text]
FoldCase (Ascii Text) # |
Methods foldCase :: Ascii Text -> Ascii Text # foldCaseList :: [Ascii Text] -> [Ascii Text]
Hashable α => Hashable (Ascii α) # |
Methods hashWithSalt :: Int -> Ascii α -> Int # hash :: Ascii α -> Int #

isAscii :: Property IsAscii v => v -> Bool #

type Ascii α = Checked IsAscii α #

maybeAscii :: Char -> Maybe Word8 #

Map a character to its ASCII encoding if possible, otherwise return `Nothing`.

ascii :: Char -> Word8 #

Encode an ASCII character. No checks are performed.

# Character properties

isControl :: Char -> Bool #

Test if a character is an ASCII control character.

isPrintable :: Char -> Bool #

Test if a character is an ASCII printable character.

isWhiteSpace :: Char -> Bool #

Test if a character is an ASCII whitespace character.

isSpaceOrTab :: Char -> Bool #

Test if a character is the SPACE or the TAB character.

isLower :: Char -> Bool #

Test if a character is an ASCII lower-case letter.

isUpper :: Char -> Bool #

Test if a character is an ASCII upper-case letter.

toLower :: Char -> Char #

Map lower-case ASCII letters to the corresponding upper-case letters, leaving other characters as is.

toUpper :: Char -> Char #

Map upper-case ASCII letters to the corresponding lower-case letters, leaving other characters as is.

isAlpha :: Char -> Bool #

Test if a character is an ASCII letter.

isAlphaNum :: Char -> Bool #

Test if a character is either an ASCII letter or a decimal digit.

isDecDigit :: Char -> Bool #

Test if a character is a decimal digit ('0' ... '9').

isNzDecDigit :: Char -> Bool #

Test if a character is a non-zero decimal digit ('1' ... '9').

fromDecDigit :: Num a => Char -> Maybe a #

Map a decimal digit to the corresponding number. Return `Nothing` on other inputs.

fromNzDecDigit :: Num a => Char -> Maybe a #

Map non-zero decimal digits to the corresponding numbers. Return `Nothing` on other inputs.

unsafeFromDecDigit :: Num a => Char -> a #

Map decimal digits to the corresponding numbers. No checks are performed.

isBinDigit :: Char -> Bool #

Test if a character is a binary digit ('0' or '1').

isNzBinDigit :: Char -> Bool #

Test if a character is the non-zero binary digit ('1').

fromBinDigit :: Num a => Char -> Maybe a #

Map binary digits to the corresponding numbers. Return `Nothing` on other inputs.

fromNzBinDigit :: Num a => Char -> Maybe a #

Map the digit '1' to the number 1. Return `Nothing` on other inputs.

unsafeFromBinDigit :: Num a => Char -> a #

Map binary digits to the corresponding numbers. No checks are performed.

isOctDigit :: Char -> Bool #

Test if a character is an octal digit ('0' ... '7').

isNzOctDigit :: Char -> Bool #

Test if a character is a non-zero octal digit ('1' ... '7').

fromOctDigit :: Num a => Char -> Maybe a #

Map octal digits to the corresponding numbers. Return `Nothing` on other inputs.

fromNzOctDigit :: Num a => Char -> Maybe a #

Map non-zero octal digits to the corresponding numbers. Return `Nothing` on other inputs.

unsafeFromOctDigit :: Num a => Char -> a #

Map octal digits to the corresponding numbers. No checks are performed.

isUpHexDigit :: Char -> Bool #

Test if a character is an upper-case hexadecimal digit ('0' ... '9' or `A` ... `F`).

isNzUpHexDigit :: Char -> Bool #

Test if a character is a non-zero upper-case hexadecimal digit ('1' ... '9' or `A` ... `F`).

fromUpHexDigit :: Num a => Char -> Maybe a #

Map upper-case hexadecimal digits to the corresponding numbers. Return `Nothing` on other inputs.

fromNzUpHexDigit :: Num a => Char -> Maybe a #

Map non-zero upper-case hexadecimal digits to the corresponding numbers. Return `Nothing` on other inputs.

unsafeFromUpHexDigit :: Num a => Char -> a #

Map upper-case hexadecimal digits to the corresponding numbers. No checks are performed.

isLowHexDigit :: Char -> Bool #

Test if a character is a lower-case hexadecimal digit ('0' ... '9' or `a` ... `f`).

isNzLowHexDigit :: Char -> Bool #

Test if a character is a non-zero lower-case hexadecimal digit ('1' ... '9' or `a` ... `f`).

fromLowHexDigit :: Num a => Char -> Maybe a #

Map lower-case hexadecimal digits to the corresponding numbers. Return `Nothing` on other inputs.

fromNzLowHexDigit :: Num a => Char -> Maybe a #

Map non-zero lower-case hexadecimal digits to the corresponding numbers. Return `Nothing` on other inputs.

unsafeFromLowHexDigit :: Num a => Char -> a #

Map lower-case hexadecimal digits to the corresponding numbers. No checks are performed.

isHexDigit :: Char -> Bool #

Test if a character is a hexadecimal digit ('0' ... '9' or `a` ... `f` or `A` ... `F`).

isNzHexDigit :: Char -> Bool #

Test if a character is a non-zero hexadecimal digit ('1' ... '9' or `a` ... `f` or `A` ... `F`).

fromHexDigit :: Num a => Char -> Maybe a #

Map hexadecimal digits to the corresponding numbers. Return `Nothing` on other inputs.

fromNzHexDigit :: Num a => Char -> Maybe a #

Map non-zero hexadecimal digits to the corresponding numbers. Return `Nothing` on other inputs.

unsafeFromHexDigit :: Num a => Char -> a #

Map hexadecimal digits to the corresponding numbers. No checks are performed.

# Byte properties

isControl8 :: Word8 -> Bool #

Test if a byte is the encoding of an ASCII control character.

isPrintable8 :: Word8 -> Bool #

Test if a byte is the encoding of an ASCII printable character.

isWhiteSpace8 :: Word8 -> Bool #

Test if a byte is the encoding of an ASCII whitespace character.

isSpaceOrTab8 :: Word8 -> Bool #

Test if a byte is the encoding of the SPACE or the TAB character.

isLower8 :: Word8 -> Bool #

Test if a byte is the encoding of an ASCII lower-case letter.

isUpper8 :: Word8 -> Bool #

Test if a byte is the encoding of an ASCII upper-case letter.

toLower8 :: Word8 -> Word8 #

Map the encodings of lower-case ASCII letters to the encodings of the corresponding upper-case letters, leaving other bytes as is.

toUpper8 :: Word8 -> Word8 #

Map the encodings of upper-case ASCII letters to the encodings of the corresponding lower-case letters, leaving other bytes as is.

isAlpha8 :: Word8 -> Bool #

Test if a byte is the encoding of an ASCII letter.

isAlphaNum8 :: Word8 -> Bool #

Test if a byte is the encoding of either an ASCII letter or a decimal digit.

isDecDigit8 :: Word8 -> Bool #

Test if a byte is the encoding of a decimal digit ('0' ... '9').

isNzDecDigit8 :: Word8 -> Bool #

Test if a byte is the encoding of a non-zero decimal digit ('1' ... '9').

fromDecDigit8 :: Num a => Word8 -> Maybe a #

Map the encoding of a decimal digit to the corresponding number. Return `Nothing` on other inputs.

fromNzDecDigit8 :: Num a => Word8 -> Maybe a #

Map the encoding of a non-zero decimal digit to the corresponding number. Return `Nothing` on other inputs.

unsafeFromDecDigit8 :: Num a => Word8 -> a #

Map the encoding of a decimal digit to the corresponding number. No checks are performed.

isBinDigit8 :: Word8 -> Bool #

Test if a byte is the encoding of a binary digit ('0' or '1').

isNzBinDigit8 :: Word8 -> Bool #

Test if a byte is the encoding of the non-zero binary digit ('1').

fromBinDigit8 :: Num a => Word8 -> Maybe a #

Map the encoding of a binary digit to the corresponding number. Return `Nothing` on other inputs.

fromNzBinDigit8 :: Num a => Word8 -> Maybe a #

Map the encoding of the digit '1' to the number 1. Return `Nothing` on other inputs.

unsafeFromBinDigit8 :: Num a => Word8 -> a #

Map the encoding of a binary digit to the corresponding number. No checks are performed.

isOctDigit8 :: Word8 -> Bool #

Test if a byte is the encoding of an octal digit ('0' ... '7').

isNzOctDigit8 :: Word8 -> Bool #

Test if a byte is the encoding of a non-zero octal digit ('1' ... '7').

fromOctDigit8 :: Num a => Word8 -> Maybe a #

Map the encoding of an octal digit to the corresponding number. Return `Nothing` on other inputs.

fromNzOctDigit8 :: Num a => Word8 -> Maybe a #

Map the encoding of a non-zero octal digit to the corresponding number. Return `Nothing` on other inputs.

unsafeFromOctDigit8 :: Num a => Word8 -> a #

Map the encoding of an octal digit to the corresponding number. No checks are performed.

isUpHexDigit8 :: Word8 -> Bool #

Test if a byte is the encoding of an upper-case hexadecimal digit ('0' ... '9' or `A` ... `F`).

isNzUpHexDigit8 :: Word8 -> Bool #

Test if a byte is the encoding of a non-zero upper-case hexadecimal digit ('1' ... '9' or `A` ... `F`).

fromUpHexDigit8 :: Num a => Word8 -> Maybe a #

Map the encoding of an upper-case hexadecimal digit to the corresponding number. Return `Nothing` on other inputs.

fromNzUpHexDigit8 :: Num a => Word8 -> Maybe a #

Map the encoding of a non-zero upper-case hexadecimal digit to the corresponding number. Return `Nothing` on other inputs.

unsafeFromUpHexDigit8 :: Num a => Word8 -> a #

Map the encoding of an upper-case hexadecimal digit to the corresponding number. No checks are performed.

isLowHexDigit8 :: Word8 -> Bool #

Test if a byte is the encoding of a lower-case hexadecimal digit ('0' ... '9' or `a` ... `f`).

isNzLowHexDigit8 :: Word8 -> Bool #

Test if a byte is the encoding of a non-zero lower-case hexadecimal digit ('1' ... '9' or `a` ... `f`).

fromLowHexDigit8 :: Num a => Word8 -> Maybe a #

Map the encoding of a lower-case hexadecimal digit to the corresponding number. Return `Nothing` on other inputs.

fromNzLowHexDigit8 :: Num a => Word8 -> Maybe a #

Map the encoding of a non-zero lower-case hexadecimal digit to the corresponding number. Return `Nothing` on other inputs.

unsafeFromLowHexDigit8 :: Num a => Word8 -> a #

Map the encoding of a lower-case hexadecimal digit to the corresponding number. No checks are performed.

isHexDigit8 :: Word8 -> Bool #

Test if a byte is the encoding of a hexadecimal digit ('0' ... '9' or `a` ... `f` or `A` ... `F`).

isNzHexDigit8 :: Word8 -> Bool #

Test if a byte is the encoding of a non-zero hexadecimal digit ('1' ... '9' or `a` ... `f` or `A` ... `F`).

fromHexDigit8 :: Num a => Word8 -> Maybe a #

Map the encoding of a hexadecimal digit to the corresponding number. Return `Nothing` on other inputs.

fromNzHexDigit8 :: Num a => Word8 -> Maybe a #

Map the encoding of a non-zero hexadecimal digit to the corresponding number. Return `Nothing` on other inputs.

unsafeFromHexDigit8 :: Num a => Word8 -> a #

Map the encoding of a hexadecimal digit to the corresponding number. No checks are performed.