0

Suppose I need to unescape XML escaped characters in a given string: e.g. I need to replace &amp; with &, &quot; with ", &lt; with < etc. I would prefer a purely functional solution.

Does it make sense to do it with scalaz.Zipper ? Zipper allows checking the characters to the right of the focus and skipping them while moving forward. Won't it be an overkill ? Would you suggest a simpler solution ?

Michael
  • 41,026
  • 70
  • 193
  • 341

1 Answers1

1

Zipper is better at dealing with 1:1 character-character mapping that needs access to the characters on either side, not a mapping that changes the number of characters in the string.

I'd recommend either using an XML parsing library (scala has a reasonable built-in-ish one in the form of scala-xml), a string escaping/unescaping utility function (there's one in apache commons that handles xml entities IIRC) or if you really want a fancy solution then maybe parsing your string with scala-parser-combinators.

lmm
  • 17,386
  • 3
  • 26
  • 37
  • Thanks. I probably should write the `unescape` function and see how it goes. I still thinks that such a function might be a good case for `Zipper`. – Michael Jan 14 '15 at 11:44
  • Yes, I can use unescape from Apache. I've looked at the code. It took dozens lines of code to implement this function. – Michael Jan 14 '15 at 12:05