From f4548fa7359aac09f020c37e2a8b8ebfa75c4c36 Mon Sep 17 00:00:00 2001 From: Phil Ruffwind Date: Tue, 19 Jan 2016 11:38:05 -0500 Subject: [PATCH] Warn about potential pitfalls with encodeString and decodeString --- Codec/Binary/UTF8/String.hs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Codec/Binary/UTF8/String.hs b/Codec/Binary/UTF8/String.hs index cf7d30c..878ad66 100644 --- a/Codec/Binary/UTF8/String.hs +++ b/Codec/Binary/UTF8/String.hs @@ -33,11 +33,13 @@ import Data.Char (chr,ord) default(Int) -- | Encode a string using 'encode' and store the result in a 'String'. +-- | Note: prefer 'encode' over this function, as it is easy to mistakenly +-- | encode the same string more than once. encodeString :: String -> String encodeString xs = map (toEnum . fromEnum) (encode xs) -- | Decode a string using 'decode' using a 'String' as input. --- | This is not safe but it is necessary if UTF-8 encoded text +-- | Note: this is not safe but it is necessary if UTF-8 encoded text -- | has been loaded into a 'String' prior to being decoded. decodeString :: String -> String decodeString xs = decode (map (toEnum . fromEnum) xs)