diff src/c/urweb.c @ 1286:829da30fb808

Fix C-side jsification of UTF-8 strings
author Adam Chlipala <adam@chlipala.net>
date Tue, 10 Aug 2010 16:02:55 -0400
parents 236dc296c32d
children b4480a56cab7
line wrap: on
line diff
--- a/src/c/urweb.c	Tue Aug 10 15:55:43 2010 -0400
+++ b/src/c/urweb.c	Tue Aug 10 16:02:55 2010 -0400
@@ -1336,7 +1336,7 @@
   *s2++ = '"';
 
   for (; *s; s++) {
-    char c = *s;
+    unsigned char c = *s;
 
     switch (c) {
     case '"':
@@ -1352,7 +1352,7 @@
       s2 += 2;
       break;
     default:
-      if (isprint((int)c))
+      if (isprint((int)c) || c >= 128)
         *s2++ = c;
       else {
         sprintf(s2, "\\%3o", c);
@@ -1366,7 +1366,8 @@
   return r;
 }
 
-uw_Basis_string uw_Basis_jsifyChar(uw_context ctx, uw_Basis_char c) {
+uw_Basis_string uw_Basis_jsifyChar(uw_context ctx, uw_Basis_char c1) {
+  unsigned char c = c1;
   char *r, *s2;
 
   uw_check_heap(ctx, 6);
@@ -1388,10 +1389,10 @@
     s2 += 2;
     break;
   default:
-    if (isprint((int)c))
+    if (isprint((int)c) || c >= 128)
       *s2++ = c;
     else {
-      sprintf(s2, "\\%3o", c);
+      sprintf(s2, "\\%3o", (unsigned char)c);
       s2 += 4;
     }
   }
@@ -1410,7 +1411,7 @@
   *s2++ = '"';
 
   for (; *s; s++) {
-    char c = *s;
+    unsigned char c = *s;
 
     switch (c) {
     case '\'':
@@ -1422,7 +1423,7 @@
       s2 += 2;
       break;
     default:
-      if (isprint((int)c))
+      if (isprint((int)c) || c >= 128)
         *s2++ = c;
       else {
         sprintf(s2, "\\%3o", c);