git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
extract Unicode replacement into PSString.decodeStringWithReplacement
d1a88d7Michael Ficarra
src/Language/PureScript/Errors.hs+2−2
@@ -33,7 +33,7 @@ import Language.PureScript.Label (Label(..))
33import Language.PureScript.Names
33import Language.PureScript.Names
34import Language.PureScript.Pretty
34import Language.PureScript.Pretty
35import Language.PureScript.Pretty.Common (endWith)
35import Language.PureScript.Pretty.Common (endWith)
36−import Language.PureScript.PSString (PSString, decodeStringEither)
36+import Language.PureScript.PSString (PSString, decodeStringWithReplacement)
37import Language.PureScript.Traversals
37import Language.PureScript.Traversals
38import Language.PureScript.Types
38import Language.PureScript.Types
39import qualified Language.PureScript.Publish.BoxesHelpers as BoxHelpers
39import qualified Language.PureScript.Publish.BoxesHelpers as BoxHelpers
@@ -1266,7 +1266,7 @@ renderBox = unlines
1266 whiteSpace = all isSpace
1266 whiteSpace = all isSpace
1267
1267
1268toTypelevelString :: Type -> Maybe Box.Box
1268toTypelevelString :: Type -> Maybe Box.Box
1269−toTypelevelString t = (Box.text . map (either (const '\xFFFD') id) . decodeStringEither) <$> toTypelevelString' t
1269+toTypelevelString t = (Box.text . decodeStringWithReplacement) <$> toTypelevelString' t
1270 where
1270 where
1271 toTypelevelString' :: Type -> Maybe PSString
1271 toTypelevelString' :: Type -> Maybe PSString
1272 toTypelevelString' (TypeLevelString s) = Just s
1272 toTypelevelString' (TypeLevelString s) = Just s
src/Language/PureScript/PSString.hs+10
@@ -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
54
55
56+-- |
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.
63+--
61codePoints :: PSString -> String
64codePoints :: PSString -> String
62codePoints = map (either (chr . fromIntegral) id) . decodeStringEither
65codePoints = map (either (chr . fromIntegral) id) . decodeStringEither
63
66
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+
64-- |
74-- |
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