text-ascii-1.0.1: ASCII string and character processing.

Copyright(C) 2021 Koz Ross
LicenseApache 2.0
MaintainerKoz Ross <koz.ross@retro-freedom.nz>
Stabilitystable
PortabilityGHC only
Safe HaskellTrustworthy
LanguageHaskell2010

Text.Ascii.Char

Contents

Description

An implementation of ASCII characters, as bytes restricted to the range 0 - 127 inclusive.

See also: Wikipedia entry for ASCII

Synopsis

ASCII characters

Type

data AsciiChar where Source #

Represents valid ASCII characters, which are bytes from 0x00 to 0x7f.

Since: 1.0.0

Bundled Patterns

pattern AsByte :: Word8 -> AsciiChar

View an AsciiChar as its underlying byte. You can pattern match on this, but since there are more bytes than valid ASCII characters, you cannot use this to construct.

Since: 1.0.0

pattern AsChar :: Char -> AsciiChar

View an AsciiChar as a Char. You can pattern match on this, but since there are more Chars than valid ASCII characters, you cannot use this to construct.

Since: 1.0.0

Instances
Bounded AsciiChar Source #

Since: 1.0.0

Instance details

Defined in Text.Ascii.Internal

Eq AsciiChar Source #

Since: 1.0.0

Instance details

Defined in Text.Ascii.Internal

Ord AsciiChar Source #

Since: 1.0.0

Instance details

Defined in Text.Ascii.Internal

Show AsciiChar Source #

Since: 1.0.0

Instance details

Defined in Text.Ascii.Internal

FoldCase AsciiChar Source #

Since: 1.0.1

Instance details

Defined in Text.Ascii.Internal

NFData AsciiChar Source #

Since: 1.0.0

Instance details

Defined in Text.Ascii.Internal

Methods

rnf :: AsciiChar -> () #

Hashable AsciiChar Source #

Since: 1.0.0

Instance details

Defined in Text.Ascii.Internal

Enum (Unsafe AsciiChar) Source #

Since: 1.0.1

Instance details

Defined in Text.Ascii.Unsafe

Read (Unsafe AsciiChar) Source #

Since: 1.0.1

Instance details

Defined in Text.Ascii.Unsafe

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

fromChar :: Char -> Maybe AsciiChar Source #

Try and turn a Char into the equivalent AsciiChar. Will return Nothing if given a Char that has no ASCII equivalent.

>>> fromChar '0'
Just '0x30'
>>> fromChar '😺'
Nothing

Since: 1.0.0

fromByte :: Word8 -> Maybe AsciiChar Source #

Try to give the AsciiChar corresponding to the given byte. Will return Nothing if given a byte that doesn't correspond to an ASCII character.

>>> fromByte 50
Just '0x32'
>>> fromByte 128
Nothing

Since: 1.0.0

Transformation

upcase :: AsciiChar -> Maybe AsciiChar Source #

Give the AsciiChar corresponding to the uppercase version of the argument. Will give Nothing if given an AsciiChar which has no uppercase version, or is uppercase already.

>>> upcase [char| 'a' |]
Just '0x41'
>>> upcase [char| '0' |]
Nothing

Since: 1.0.0

downcase :: AsciiChar -> Maybe AsciiChar Source #

Give the AsciiChar corresponding to the lowercase version of the argument. Will give Nothing if given an AsciiChar which has no lowercase version, or is lowercase already.

>>> downcase [char| 'C' |]
Just '0x63'
>>> downcase [char| '\\' |]
Nothing

Since: 1.0.0

Categorization

data AsciiType where Source #

A categorization of ASCII characters based on whether they're meant to be displayed (Printable) or for control (Control).

Since: 1.0.0

Bundled Patterns

pattern Control :: AsciiType

A control character is any of the first 32 bytes (0-31), plus DEL (127).

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

Instances
Bounded AsciiType Source #

Since: 1.0.0

Instance details

Defined in Text.Ascii.Char

Eq AsciiType Source # 
Instance details

Defined in Text.Ascii.Char

Ord AsciiType Source # 
Instance details

Defined in Text.Ascii.Char

Show AsciiType Source #

Since: 1.0.0

Instance details

Defined in Text.Ascii.Char

NFData AsciiType Source # 
Instance details

Defined in Text.Ascii.Char

Methods

rnf :: AsciiType -> () #

Hashable AsciiType Source # 
Instance details

Defined in Text.Ascii.Char

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

Bundled Patterns

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

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

data AsciiCase where Source #

The case of an ASCII character (if it has one).

Since: 1.0.0

Bundled Patterns

pattern Upper :: AsciiCase

Indicator of an uppercase character.

Since: 1.0.0

pattern Lower :: AsciiCase

Indicator of a lowercase character.

Since: 1.0.0

Instances
Bounded AsciiCase Source #

Since: 1.0.0

Instance details

Defined in Text.Ascii.Char

Eq AsciiCase Source # 
Instance details

Defined in Text.Ascii.Char

Ord AsciiCase Source # 
Instance details

Defined in Text.Ascii.Char

Show AsciiCase Source #

Since: 1.0.0

Instance details

Defined in Text.Ascii.Char

NFData AsciiCase Source # 
Instance details

Defined in Text.Ascii.Char

Methods

rnf :: AsciiCase -> () #

Hashable AsciiCase Source # 
Instance details

Defined in Text.Ascii.Char

caseOf :: AsciiChar -> Maybe AsciiCase Source #

Determine the case of an AsciiChar. Returns Nothing if the character doesn't have a case.

>>> caseOf [char| 'w' |]
Just Lower
>>> caseOf [char| 'W' |]
Just Upper
>>> caseOf [char| '~' |]
Nothing

Since: 1.0.0

Optics

charWise :: Prism' Char AsciiChar Source #

A representation of the relationship between Char and AsciiChar.

>>> preview charWise 'w'
Just '0x77'
>>> preview charWise '😺'
Nothing
>>> review charWise [char| 'w' |]
'w'

Since: 1.0.0

byteWise :: Prism' Word8 AsciiChar Source #

A representation of the relationship between ASCII characters and bytes.

>>> preview byteWise 0x20
Just '0x20'
>>> preview byteWise 0x81
Nothing
>>> review byteWise [char| 'w' |]
119

Since: 1.0.0