git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Clean up string literal rendering
commitac0782e345240cd8cbb085246f9f63c50e55252d authorAndy Arvanitis <andyarvanitis@gmail.com> dateMon 13 Aug 2018, 18:03 (8 years ago) parent0adcaae
1 file changed+5−6
src/CodeGen/Cpp/Printer.hs+5−6
src/CodeGen/Cpp/Printer.hs+5−6
@@ -44,13 +44,9 @@ literals = mkPattern' match'
4444
4545 match :: (Emit gen) => AST -> StateT PrinterState Maybe gen
4646 match (NumericLiteral _ n) = return $ emit $ T.pack $ either show show n
47− match (StringLiteral _ s)
48− | Just s' <- decodeString s
49− , T.all isAscii s' = return $ emit $ stringLiteral s
50− match (StringLiteral _ s) = return $ emit $ "u8" <> stringLiteral s
47+ match (StringLiteral _ s) = return $ emit $ stringLiteral s
5148 match (BooleanLiteral _ True) = return $ emit "true"
5249 match (BooleanLiteral _ False) = return $ emit "false"
53− -- match (ArrayLiteral _ []) = return $ emit "std::initializer_list<boxed>{}"
5450 match (ArrayLiteral _ xs) = mconcat <$> sequence
5551 [ return $ emit "array_t{"
5652 , intercalate (emit ", ") <$> forM xs prettyPrintCpp'
@@ -387,7 +383,10 @@ prettyPrintCpp1 :: AST -> Text
387383prettyPrintCpp1 = maybe (internalError "Incomplete pattern") runPlainString . flip evalStateT (PrinterState 0) . prettyPrintCpp'
388384
389385stringLiteral :: PSString -> Text
390−stringLiteral pss | Just s <- decodeString pss = stringLiteral' s
386+stringLiteral pss | Just s <- decodeString pss =
387+ if T.all isAscii s
388+ then ""
389+ else ("u8") <> stringLiteral' s
391390 where
392391 stringLiteral' :: Text -> Text
393392 stringLiteral' s = "\"" <> T.concatMap encodeChar s <> "\""