@@ -5,6 +5,7 @@ module Language.PureScript.PSString
5 , toUTF16CodeUnits
5 , toUTF16CodeUnits
6 , decodeString
6 , decodeString
7 , decodeStringEither
7 , decodeStringEither
8+ , decodeStringWithReplacement
8 , prettyPrintString
9 , prettyPrintString
9 , prettyPrintStringJS
10 , prettyPrintStringJS
10 , mkString
11 , mkString
@@ -52,15 +53,24 @@ newtype PSString = PSString { toUTF16CodeUnits :: [Word16] }
52instance Show PSString where
53instance Show PSString where
53 show = show . codePoints
54 show = show . codePoints
55-- Decode a PSString to a String, representing any lone surrogates as the
57-- Decode a PSString to a String, representing any lone surrogates as the
56-- reserved code point with that index. Warning: if there are any lone
58-- reserved code point with that index. Warning: if there are any lone
57-- surrogates, converting the result to Text via Data.Text.pack will result in
59-- surrogates, converting the result to Text via Data.Text.pack will result in
58-- loss of information as those lone surrogates will be replaced with U+FFFD
60-- loss of information as those lone surrogates will be replaced with U+FFFD
59-- REPLACEMENT CHARACTER. Because this function requires care to use correctly,
61-- REPLACEMENT CHARACTER. Because this function requires care to use correctly,
60-- we do not export it.
62-- we do not export it.
61codePoints :: PSString -> String
64codePoints :: PSString -> String
62codePoints = map (either (chr . fromIntegral) id) . decodeStringEither
65codePoints = map (either (chr . fromIntegral) id) . decodeStringEither
68+-- Decode a PSString as UTF-16 text. Lone surrogates will be replaced with
69+-- U+FFFD REPLACEMENT CHARACTER
71+decodeStringWithReplacement :: PSString -> String
72+decodeStringWithReplacement = map (either (const '\xFFFD') id) . decodeStringEither
65-- Decode a PSString as UTF-16. Lone surrogates in the input are represented in
75-- Decode a PSString as UTF-16. Lone surrogates in the input are represented in
66-- the output with the Left constructor; characters which were successfully
76-- the output with the Left constructor; characters which were successfully