Module
Data.ByteString.Encoding
- Package
- purescript-bytestrings
- Repository
- f-f/purescript-bytestrings
Conversions between String and ByteString using different encodings
#fromString Source
fromString :: Encoding -> String -> Maybe ByteStringEncode a string to bytes under the given encoding, failing on unrepresentable
inputs. Use fromStringLossy for a lenient decoder that doesn't fail.
Per encoding, the input is rejected when:
UTF8: it contains an unpaired surrogateUTF16LE: never failsLatin1: a UTF-16 code unit is above0xFFHex: the length is odd, or a character is not a hex digitBase64: anything but a canonically padded RFC 4648 encoding, e.g. a length not a multiple of four, a character outside the standard and URL-safe alphabets,=other than as final padding (at most two), or nonzero unused bits in the final data character.
#fromStringLossy Source
fromStringLossy :: Encoding -> String -> ByteStringEncode a string to bytes under the given encoding, lossily. Substitutions per encoding:
UTF8: substitutes U+FFFD for an unpaired surrogateUTF16LE: exactLatin1: masks each code unit to its low byteHex: stops at the first non-hex character or a trailing lone digitBase64: skips any character outside the alphabet (whitespace,=, anything else)
#toString Source
toString :: Encoding -> ByteString -> Maybe StringDecode bytes to a string under the given encoding, returning Nothing
when a strict UTF decoder rejects the input (invalid UTF-8, or an
odd-length UTF-16 buffer)
#toStringLossy Source
toStringLossy :: Encoding -> ByteString -> StringDecode bytes to a string under the given encoding, total in every case. Per encoding:
UTF8: substitutes U+FFFD for invalid bytesUTF16LE: drops a trailing odd byte and decodes the even prefixLatin1,Hex,Base64: never fail