Skip to content

Instantly share code, notes, and snippets.

@dminuoso

dminuoso/f.hs Secret

Created January 27, 2022 09:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dminuoso/3ba87266e2df0729ca575df7132d6d10 to your computer and use it in GitHub Desktop.
Save dminuoso/3ba87266e2df0729ca575df7132d6d10 to your computer and use it in GitHub Desktop.
pprDomain :: Domain -> TL.Text
pprDomain (Domain l) = TB.toLazyText build
where
build :: TB.Builder
build = foldl' (\buf x -> buf <> pprLabel x <> ".") mempty l
pprLabel :: DomainLabel -> TB.Builder
pprLabel (DomainLabel d) = BS.foldl' (\buf x -> buf <> go x) mempty d
go :: Word8 -> TB.Builder
go c | c > 0x20
&& c <= 0x7E = TB.singleton (w2c c)
| otherwise
= "\\x" <> TB.fromString (showHex c "")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment