double-x-encoding-1.2.1: Encoding scheme to encode any Unicode string with only [0-9a-zA-Z_]
Safe HaskellSafe-Inferred
LanguageGHC2021

DoubleXEncoding

Description

Implementation of Double-X-Encoding encoder and decoder in Haskell

Main functions:

Synopsis

Documentation

charEncode :: Char -> Char Source #

Encoder mapping for ASCII characters.

charDecode :: Char -> Char Source #

Decoder mapping for ASCII characters.

hexShiftEncode :: Char -> Char Source #

Map hex characters to an alternative hex alphabet ranging from a to p instead of 0 to f.

hexShiftDecode :: Char -> Char Source #

Map alternative hex alphabet back to the original hex alphabet.

data EncodeOptions Source #

Options for encoding:

encodeLeadingDigit
Encode the leading digit of the input string
encodeDoubleUnderscore
Encode double underscores __ as XXRXXR

Especially relevant for GraphQL, as the spec does not allow leading digits or double underscores for field names.

doubleXEncodeWithOptions :: EncodeOptions -> Text -> Text Source #

Encode a text using the Double-X-Encoding algorithm with provided options.

defaultOptions :: EncodeOptions Source #

Default options with no leading digit encoding and no double underscore encoding.

doubleXEncode :: Text -> Text Source #

Encode a text using the Double-X-Encoding algorithm.

>>> doubleXEncode "id-with.special$chars!"
"idXXDwithXXEspecialXX4charsXX1"

gqlOptions :: EncodeOptions Source #

Default options for GraphQL encoding. Leading digits or double underscores are not allowed for field names.

doubleXEncodeGql :: Text -> Text Source #

Encode a text using the Double-X-Encoding algorithm with GraphQL options.

>>> doubleXEncodeGql "1FileFormat__"
"XXZ1FileFormatXXRXXR"

doubleXDecode :: Text -> Text Source #

Decode a Double-X-Encoding encoded text.

>>> doubleXDecode "idXXDwithXXEspecialXX4charsXX1"
"id-with.special$chars!"