From e565ae841fa735a1361712eac06cc7ae9be098dc Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Wed, 10 Jul 2013 14:01:19 -0400 Subject: [PATCH] Add missing Html.hs from previous commit. --- src/Html.hs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/Html.hs diff --git a/src/Html.hs b/src/Html.hs new file mode 100644 index 0000000..1c9a428 --- /dev/null +++ b/src/Html.hs @@ -0,0 +1,34 @@ +module Html +where + +import Test.HUnit +import Text.HTML.TagSoup.Entity (lookupEntity) + +replace_entities :: String -> String +replace_entities [] = [] +replace_entities ('&':xs) = + let (b, a) = break (== ';') xs in + case (lookupEntity b, a) of + (Just c, ';':as) -> c : replace_entities as + _ -> '&' : replace_entities xs +replace_entities (x:xs) = x : replace_entities xs + + +html_tests :: [Test] +html_tests = [ test_replace_entities ] + +test_replace_entities :: Test +test_replace_entities = + TestCase $ assertEqual description expected_text actual_text + where + description = "All entities are replaced correctly." + actual_text = + replace_entities $ + ""The moon is gay……" " ++ + "said <insert the current president of the " ++ + "United States of America>. “It’s " ++ + "OK—–he’s not a real doctor.”" + expected_text = + "\"The moon is gay……\" said . " ++ + "“It’s OK—–he’s not a real doctor.”" -- 2.43.2