Copyright | (C) 2021 Koz Ross |
---|---|
License | Apache 2.0 |
Maintainer | Koz Ross <koz.ross@retro-freedom.nz> |
Stability | stable |
Portability | GHC only |
Safe Haskell | Trustworthy |
Language | Haskell2010 |
An implementation of ASCII characters, as bytes restricted to the range 0 - 127 inclusive.
See also: Wikipedia entry for ASCII
Synopsis
- data AsciiChar where
- char :: QuasiQuoter
- fromChar :: Char -> Maybe AsciiChar
- fromByte :: Word8 -> Maybe AsciiChar
- upcase :: AsciiChar -> Maybe AsciiChar
- downcase :: AsciiChar -> Maybe AsciiChar
- data AsciiType where
- charType :: AsciiChar -> AsciiType
- data AsciiCategory where
- pattern Other :: AsciiCategory
- pattern Punctuation :: AsciiCategory
- pattern Letter :: AsciiCategory
- pattern Number :: AsciiCategory
- pattern Symbol :: AsciiCategory
- categorize :: AsciiChar -> AsciiCategory
- categorizeGeneral :: AsciiChar -> GeneralCategory
- data AsciiCase where
- caseOf :: AsciiChar -> Maybe AsciiCase
- charWise :: Prism' Char AsciiChar
- byteWise :: Prism' Word8 AsciiChar
ASCII characters
Type
Represents valid ASCII characters, which are bytes from 0x00
to 0x7f
.
Since: 1.0.0
pattern AsByte :: Word8 -> AsciiChar | View an Since: 1.0.0 |
pattern AsChar :: Char -> AsciiChar | View an Since: 1.0.0 |
Instances
Bounded AsciiChar Source # | Since: 1.0.0 |
Eq AsciiChar Source # | Since: 1.0.0 |
Ord AsciiChar Source # | Since: 1.0.0 |
Defined in Text.Ascii.Internal | |
Show AsciiChar Source # | Since: 1.0.0 |
FoldCase AsciiChar Source # | Since: 1.0.1 |
Defined in Text.Ascii.Internal | |
NFData AsciiChar Source # | Since: 1.0.0 |
Defined in Text.Ascii.Internal | |
Hashable AsciiChar Source # | Since: 1.0.0 |
Defined in Text.Ascii.Internal | |
Enum (Unsafe AsciiChar) Source # | Since: 1.0.1 |
Defined in Text.Ascii.Unsafe succ :: Unsafe AsciiChar -> Unsafe AsciiChar # pred :: Unsafe AsciiChar -> Unsafe AsciiChar # toEnum :: Int -> Unsafe AsciiChar # fromEnum :: Unsafe AsciiChar -> Int # enumFrom :: Unsafe AsciiChar -> [Unsafe AsciiChar] # enumFromThen :: Unsafe AsciiChar -> Unsafe AsciiChar -> [Unsafe AsciiChar] # enumFromTo :: Unsafe AsciiChar -> Unsafe AsciiChar -> [Unsafe AsciiChar] # enumFromThenTo :: Unsafe AsciiChar -> Unsafe AsciiChar -> Unsafe AsciiChar -> [Unsafe AsciiChar] # | |
Read (Unsafe AsciiChar) Source # | Since: 1.0.1 |
Construction
char :: QuasiQuoter Source #
Allows constructing ASCII characters from literals, whose correctness is checked by the compiler.
Currently, accepts literal syntax similar to the Haskell parser, with escape sequences preceded by '\'. In particular, this includes the single quote (see the example below).
>>>
[char| '\'' |]
'0x27'
Since: 1.0.0
Transformation
Categorization
A categorization of ASCII characters based on whether they're meant to be
displayed (Printable
) or for control (Control
).
Since: 1.0.0
pattern Control :: AsciiType | A control character is any of the first 32 bytes (0-31), plus Since: 1.0.0 |
pattern Printable :: AsciiType | All ASCII characters whose byte is above 31 (and not 127) are printable characters. Since: 1.0.0 |
charType :: AsciiChar -> AsciiType Source #
Classify an AsciiChar
according to whether it's a control character or a
printable character.
>>>
charType [char| '\0' |]
Control>>>
charType [char| 'w' |]
Printable
Since: 1.0.0
data AsciiCategory where Source #
A categorization of ASCII characters based on their usage. Based (loosely) on Unicode categories.
Since: 1.0.0
pattern Other :: AsciiCategory | Something which doesn't fit into any of the other categories. Since: 1.0.0 |
pattern Punctuation :: AsciiCategory | A punctuation character. Since: 1.0.0 |
pattern Letter :: AsciiCategory | A letter, either uppercase or lowercase. Since: 1.0.0 |
pattern Number :: AsciiCategory | A numerical digit. Since: 1.0.0 |
pattern Symbol :: AsciiCategory | A symbol whose role isn't (normally) punctuation. Since: 1.0.0 |
Instances
categorize :: AsciiChar -> AsciiCategory Source #
Classify an AsciiChar
based on its category.
>>>
categorize [char| ',' |]
Punctuation>>>
categorize [char| '~' |]
Symbol>>>
categorize [char| 'w' |]
Letter>>>
categorize [char| '2' |]
Number>>>
categorize [char| '\0' |]
Other
Since: 1.0.0
categorizeGeneral :: AsciiChar -> GeneralCategory Source #
Compatibility method for the GeneralCategory
provided by Char
.
>>>
categorizeGeneral [char| ',' |]
OtherPunctuation>>>
categorizeGeneral [char| '~' |]
MathSymbol>>>
categorizeGeneral [char| 'w' |]
LowercaseLetter>>>
categorizeGeneral [char| '2' |]
DecimalNumber>>>
categorizeGeneral [char| '\0' |]
Control
Since: 1.0.0
The case of an ASCII character (if it has one).
Since: 1.0.0
pattern Upper :: AsciiCase | Indicator of an uppercase character. Since: 1.0.0 |
pattern Lower :: AsciiCase | Indicator of a lowercase character. Since: 1.0.0 |