ascii-group (empty) → 1.0.0.0
raw patch · 3 files changed
+167/−0 lines, 3 filesdep +ascii-chardep +basedep +hashable
Dependencies added: ascii-char, base, hashable
Files
- ASCII/Group.hs +113/−0
- ascii-group.cabal +41/−0
- license.txt +13/−0
+ ASCII/Group.hs view
@@ -0,0 +1,113 @@+{- |++ASCII characters are broadly categorized into two groups: /control codes/ and /printable characters/.++-}++module ASCII.Group+ (+ {- * The @Group@ type -} Group (..),+ {- * Functions -} charGroup, inGroup+ {- * Notes -} {- $notes -}+ )+ where++import ASCII.Char ( Char )+import Data.Bool ( Bool )+import Data.Data ( Data )+import Data.Eq ( Eq, (==) )+import Data.Hashable ( Hashable )+import Data.Ord ( Ord, (<) )+import GHC.Generics ( Generic )+import Prelude ( Enum, Bounded )+import Text.Show ( Show )++import qualified ASCII.Char as Char++{- $setup++>>> import Prelude+>>> import ASCII.Char++-}++data Group =+ Control -- ^ 33 of the ASCII characters are /control codes/. A few of these are still in use, but most are obsolete relics of the early days of computing.+ | Printable -- ^ 95 of the ASCII characters are /printable characters/ such as letters and numbers, mostly corresponding to the keys on an American English keyboard.++deriving stock instance Eq Group++deriving stock instance Ord Group++deriving stock instance Enum Group++deriving stock instance Bounded Group++deriving stock instance Show Group++deriving stock instance Data Group++deriving stock instance Generic Group++deriving anyclass instance Hashable Group++{- | Determine which group a particular character belongs to.++>>> map charGroup [CapitalLetterA,EndOfTransmission]+[Printable,Control]++-}++charGroup :: Char -> Group+charGroup x =+ case x of+ _ | (x < Char.Space) -> Control+ Char.Delete -> Control+ _ -> Printable++{- | Test whether a character belongs to a particular group.++>>> inGroup Printable EndOfTransmission+False++>>> inGroup Control EndOfTransmission+True++-}++inGroup :: Group -> Char -> Bool+inGroup g x = charGroup x == g++{- $notes++Space is a printable character (perhaps surprisingly, given that it is invisible).++>>> charGroup Space+Printable++Tab is a control code (perhaps surprisingly, given that space is a printable character).++>>> charGroup HorizontalTab+Control++A few examples of printable characters:++>>> all (inGroup Printable) [CapitalLetterA,SmallLetterZ,Digit4,Tilde]+True++A few examples of control characters:++>>> all (inGroup Control) [Null,Substitute,UnitSeparator,Delete]+True++There are 33 control codes.++>>> length (filter (inGroup Control) allCharacters)+33++There are 95 printable characters.++>>> length (filter (inGroup Printable) allCharacters)+95++-}
+ ascii-group.cabal view
@@ -0,0 +1,41 @@+cabal-version: 2.0++name: ascii-group+version: 1.0.0.0+synopsis: ASCII character groups+category: Data, Text++description: This package defines a @Group@ type that describes the two varieties of ASCII character, and provides some functions for classifying characters by group.++license: Apache-2.0+license-file: license.txt++author: Chris Martin+maintainer: Chris Martin, Julie Moronuki++homepage: https://github.com/typeclasses/ascii+bug-Reports: https://github.com/typeclasses/ascii/issues++build-type: Simple++tested-with: GHC == 8.8.1, GHC == 8.6.5, GHC == 8.4.3++source-repository head+ type: git+ location: git://github.com/typeclasses/ascii.git++library+ default-language: Haskell2010+ default-extensions: NoImplicitPrelude+ default-extensions: StandaloneDeriving+ default-extensions: DeriveAnyClass+ default-extensions: DerivingStrategies+ default-extensions: DeriveDataTypeable+ default-extensions: DeriveGeneric+ ghc-options: -Wall++ build-depends: base >= 4.11 && < 4.14+ build-depends: ascii-char >= 1.0 && < 1.1+ build-depends: hashable >= 1.2 && < 1.4++ exposed-modules: ASCII.Group
+ license.txt view
@@ -0,0 +1,13 @@+Copyright 2020 Typeclass Consulting LLC++Licensed under the Apache License, Version 2.0 (the "License");+you may not use this file except in compliance with the License.+You may obtain a copy of the License at++ http://www.apache.org/licenses/LICENSE-2.0++Unless required by applicable law or agreed to in writing, software+distributed under the License is distributed on an "AS IS" BASIS,+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+See the License for the specific language governing permissions and+limitations under the License.