enum-utf8: An experimental Utf8 parsing toolkit for enumerated types

[ bsd3, library, text ] [ Propose Tags ] [ Report a vulnerability ]

An experimental Utf8 rendering and parsing toolkit for enumerated types based on enum-text and render-utf8. Please see the README on GitHub at https://github.com/cdornan/enum-text#readme


[Skip to Readme]

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.1.0.0
Change log ChangeLog.md
Dependencies array, base (>=4.8.2 && <10), bytestring, hashable, possibly, render-utf8, unordered-containers [details]
License BSD-3-Clause
Copyright 2019 Chris Dornan
Author Chris Dornan
Maintainer chris@chrisdornan.com
Category Text
Home page https://github.com/cdornan/enum-text#readme
Bug tracker https://github.com/cdornan/enum-text/issues
Source repo head: git clone https://github.com/cdornan/enum-text
Uploaded by ChrisDornan at 2019-03-16T01:01:01Z
Distributions
Downloads 605 total (2 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2019-03-16 [all 1 reports]

Readme for enum-utf8-0.1.0.0

[back to package description]

enum-utf8

An experimental toolkit for rendering enumerated types into Utf8 from the render-utf8 package) and parsing them back again with the provided Utf8Parsable type class. It is based on the render-utf8 and enum-text packages.

To get the Buildable and TextParsable instances for an enumerated data type use the following pattern:

import Text.Enum.Utf8
import Text.Utf8

data Foo = FOO_bar | FOO_bar_baz
  deriving (Bounded,Enum,Eq,Ord,Show)

instance EnumUtf8     Foo
instance Renderable   Foo where render    = renderEnumUtf8
instance Utf8Parsable Foo where parseUtf8 = parseEnumUtf8

main :: IO ()
main = mapM_ (cvtLn . render) [minBound..maxBound::Foo]

This will use the default configuration for generating the text of each enumeration from the derived show text, namely:

  • removing the prefix upto and including the first underscore (_);
  • converting each subsequent underscore (_) into a dash (-).

See the Haddocks for details on how to override this default configuration for any given enumeration type.

Functions for generating and parsing UTF-8 encoded ByteStrings (suitable for cassava), as are Hashable functions.