Skip to content

Instantly share code, notes, and snippets.

@schell
Created March 28, 2014 20:19
Show Gist options
  • Save schell/9842122 to your computer and use it in GitHub Desktop.
Save schell/9842122 to your computer and use it in GitHub Desktop.
{-# LANGUAGE OverloadedStrings #-}
module Web.Parsers where
import Data.Attoparsec.Text as A
import Data.Text
import Control.Applicative
import Data.Char
convertUnicode :: Text -> Either String Text
convertUnicode = parseOnly unicode
unicode :: Parser Text
unicode = pack <$> many' unicodeChar
unicodeChar :: Parser Char
unicodeChar = escapedChar <|> anyChar
escapedChar :: Parser Char
escapedChar = do
_ <- string "\\u"
h <- A.take 4
case chr <$> parseOnly hexadecimal h of
Right c -> return c
Left l -> fail l
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment