diff options
| author | Mirek Kratochvil <exa.exa@gmail.com> | 2023-05-27 20:20:43 +0200 |
|---|---|---|
| committer | Mirek Kratochvil <exa.exa@gmail.com> | 2023-05-27 20:20:43 +0200 |
| commit | 73498534cfdccab95e580f8d6b121655d00e7578 (patch) | |
| tree | f1160d0c93833cbf668700a096e2bf4a2b7ff4ea /mustache/src/Text/Mustache/Internal.hs | |
| parent | 35837f5607986b18746590c1611927d59cbe8c87 (diff) | |
| download | reploy-73498534cfdccab95e580f8d6b121655d00e7578.tar.gz reploy-73498534cfdccab95e580f8d6b121655d00e7578.tar.bz2 | |
fork mustache
Diffstat (limited to 'mustache/src/Text/Mustache/Internal.hs')
| -rw-r--r-- | mustache/src/Text/Mustache/Internal.hs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/mustache/src/Text/Mustache/Internal.hs b/mustache/src/Text/Mustache/Internal.hs new file mode 100644 index 0000000..c1bf8b7 --- /dev/null +++ b/mustache/src/Text/Mustache/Internal.hs @@ -0,0 +1,41 @@ +{-| +Module : $Header$ +Description : Types and conversions +Copyright : (c) Justus Adam, 2015 +License : BSD3 +Maintainer : dev@justus.science +Stability : experimental +Portability : POSIX + +escapeXML and xmlEntities curtesy to the tagsoup library. +-} +module Text.Mustache.Internal (uncons, escapeXMLText) where + + +import Data.Char (ord) +import qualified Data.IntMap as IntMap +import qualified Data.Text as T + + +uncons :: [α] -> Maybe (α, [α]) +uncons [] = Nothing +uncons (x:xs) = return (x, xs) + + +escapeXMLText :: T.Text -> T.Text +escapeXMLText = T.pack . escapeXML . T.unpack + + +escapeXML :: String -> String +escapeXML = concatMap $ \x -> IntMap.findWithDefault [x] (ord x) mp + where mp = IntMap.fromList [(ord b, "&"++a++";") | (a,[b]) <- xmlEntities] + + +xmlEntities :: [(String, String)] +xmlEntities = + [ ("quot", "\"") + , ("#39", "'") + , ("amp" , "&") + , ("lt" , "<") + , ("gt" , ">") + ] |
