Skip to content

Commit

Permalink
[#334] resolved issue with escaping regular unescaped chars
Browse files Browse the repository at this point in the history
  • Loading branch information
dariodsa committed Dec 9, 2020
1 parent 7587a21 commit 0349ff4
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions src/Toml/Type/Printer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -178,21 +178,16 @@ prettyKeyValue options i = mapOrdered (\kv -> [kvText kv]) options . HashMap.toL
showTextUnicode :: Text -> Text
showTextUnicode text = Text.pack quotedText
where
quotedText = finalText
quotedText = show finalText
finalText = foldl (\acc (ch, asciiCh) -> acc ++ getCh ch asciiCh) "" asciiArr
xss = unicodeEscape $ show $ Text.unpack text
xss = Text.unpack text
asciiArr = zip xss $ asciiStatus xss
getCh ch True = [ch]
getCh ch False = printf "\\\\U%08x" ordChr :: String
getCh ch False = printf "\\U%08x" ordChr :: String
where
ordChr = ord ch
asciiStatus = map isAscii

unicodeEscape "" = ""
unicodeEscape ('\\':'\\':'u':xs) = '\\':'\\':'u': unicodeEscape xs
unicodeEscape ('\\':'\\':'U':xs) = '\\':'\\':'U': unicodeEscape xs
unicodeEscape (x:xs) = x : unicodeEscape xs

showDouble :: Double -> Text
showDouble d | isInfinite d && d < 0 = "-inf"
| isInfinite d = "inf"
Expand Down

0 comments on commit 0349ff4

Please sign in to comment.