willow- An implementation of the web Document Object Model, and its rendering.
Copyright(c) 2020 Sam May
Safe HaskellTrustworthy



The Encoding spec uses a conceptual model of an "encoding" as being the function between Unicode values and bytes. As this is a bit more complex than any content author wants to specify every document, HTML (and other interfaces) represent them as semi-standardized but freeform text strings; the standard document then collects the various strings authors have used across the web and associates the most common as "labels" of those abstract encodings.

To refer to them internally, however, it also promotes one of the labels of each encoding as the canonical form; this library implements that set (with modifications to fit Haskell identifiers) in Encoding. The labels are described via a reversible many-to-one mapping with those names, which as the reverse is rarely used, lends itself well to being adapted as a lookup table. This then is a machine-readable formatting of that table.


lookupEncoding :: Text -> Maybe Encoding #

Encoding: get an encoding

Given an encoding's case-insensitive label, try to retrieve an appropriate Encoding. The set prescribed by the HTML specification is smaller than that used by other registries for security and interoperability reasons, and may not always return the expected Encoding if an alternate one has been determined to be more internet-compatible.