Created
March 28, 2014 20:19
-
-
Save schell/9842122 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {-# 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