@@ -5,6 +5,7 @@ module Language.PureScript.PSString
55 , toUTF16CodeUnits
66 , decodeString
77 , decodeStringEither
8+ , decodeStringWithReplacement
89 , prettyPrintString
910 , prettyPrintStringJS
1011 , mkString
@@ -52,15 +53,24 @@ newtype PSString = PSString { toUTF16CodeUnits :: [Word16] }
5253instance Show PSString where
5354 show = show . codePoints
5455
56+-- |
5557-- Decode a PSString to a String, representing any lone surrogates as the
5658-- reserved code point with that index. Warning: if there are any lone
5759-- surrogates, converting the result to Text via Data.Text.pack will result in
5860-- loss of information as those lone surrogates will be replaced with U+FFFD
5961-- REPLACEMENT CHARACTER. Because this function requires care to use correctly,
6062-- we do not export it.
63+--
6164codePoints :: PSString -> String
6265codePoints = map (either (chr . fromIntegral) id) . decodeStringEither
6366
67+-- |
68+-- Decode a PSString as UTF-16 text. Lone surrogates will be replaced with
69+-- U+FFFD REPLACEMENT CHARACTER
70+--
71+decodeStringWithReplacement :: PSString -> String
72+decodeStringWithReplacement = map (either (const '\xFFFD') id) . decodeStringEither
73+
6474-- |
6575-- Decode a PSString as UTF-16. Lone surrogates in the input are represented in
6676-- the output with the Left constructor; characters which were successfully