diff src/prim.sml @ 1656:3e7c7e200713

Fix handling of quotes in generating C literals
author Adam Chlipala <adam@chlipala.net>
date Mon, 02 Jan 2012 17:08:39 -0500
parents 4d04cb89649b
children 4d64af730e35
line wrap: on
line diff
--- a/src/prim.sml	Mon Jan 02 16:54:18 2012 -0500
+++ b/src/prim.sml	Mon Jan 02 17:08:39 2012 -0500
@@ -70,12 +70,24 @@
     else
         str ch ^ pad (n-1, ch, s)
 
+fun quoteDouble ch =
+    case ch of
+        #"'" => str ch
+      | _ => Char.toCString ch
+
+fun toCChar ch =
+    case ch of
+        #"\"" => str ch
+      | _ => Char.toCString ch
+
+val toCString = String.translate quoteDouble
+
 fun p_t_GCC t =
     case t of
         Int n => string (int2s n)
       | Float n => string (float2s n)
-      | String s => box [string "\"", string (String.toCString s), string "\""]
-      | Char ch => box [string "'", string (Char.toCString ch), string "'"]
+      | String s => box [string "\"", string (toCString s), string "\""]
+      | Char ch => box [string "'", string (toCChar ch), string "'"]
 
 fun equal x =
     case x of