XML character dereferencer
Just in case you ever need one:
xmlCharDeref :: String -> String xmlCharDeref [] = [] xmlCharDeref ('&':'#':'x':r) = let (digits, remainder) = span (/= ';') r c = chr (read ("0x" ++ digits)) in c : xmlCharDeref (tail remainder) xmlCharDeref ('&':'#':r) = let (digits, remainder) = span (/= ';') r c = chr (read digits) in c : xmlCharDeref (tail remainder) xmlCharDeref (c:r) = c : xmlCharDeref r |
In ghci:
*Foo> xmlCharDeref "hello there" "hello there" *Foo> xmlCharDeref "hello there" "hello there" *Foo> xmlCharDeref "hello2there" "hello2there" |
How about:
Now there’s no way you can accidentally encode twice.
@Chris: Except of course that the type would be
In any case it’s hardly worth doing for the particular case where I had use for this function.