[Haskell-beginners] Escaping special characters in text
Thomas Koster
tkoster at gmail.com
Thu Jun 11 05:53:41 UTC 2015
Hi list,
My program needs to escape and unescape "special characters" in text
(Data.Text.Text), using my own definition of "special character"
(isSpecial :: Char -> Bool). I am looking for a library that provides
functions that implement or help me implement this functionality. I
don't really care exactly how the special characters are escaped, but
my preference is to prefix them with backslashes.
While "attoparsec" does technically answer my question, it is as
unimpressive an answer as "Prelude" unless the answer comes with a
particularly clever and concise parser that blows my mind (and then
kudos to the author). I am looking for a higher level library where I
don't need to re-invent this wheel. That is, I don't want to write an
unescaping parser if somebody has already published one on Hackage in
a clean, well-tested library.
My searches on Hoogle have turned up only network-uri, which offers
percent-encoding with the definition of "special character" accepted
as an argument [1]. This is the sort of thing I am after, although to
use network-uri I would have to round-trip via String, something that
I feel I should avoid. Functions of text types that return lazy text
builders would be ideal. Also, percent-encoding is not my favourite
encoding scheme.
Thanks in advance.
[1] https://hackage.haskell.org/package/network-uri/docs/Network-URI.html#v:escapeURIString
--
Thomas Koster
More information about the Beginners
mailing list