guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Improved string writing


From: Marius Vollmer
Subject: Re: [PATCH] Improved string writing
Date: Mon, 06 Jun 2005 22:51:48 +0300
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

Marius Vollmer <address@hidden> writes:

> I will make that change myself in the next days, but if anyone beats
> me to it...

Here is a patch for what I have in mind.  I have applied it already.

Index: libguile/print.c
===================================================================
RCS file: /cvsroot/guile/guile/guile-core/libguile/print.c,v
retrieving revision 1.179
diff -u -r1.179 print.c
--- libguile/print.c    23 May 2005 19:57:21 -0000      1.179
+++ libguile/print.c    6 Jun 2005 19:45:04 -0000
@@ -506,30 +506,38 @@
        case scm_tc7_string:
          if (SCM_WRITINGP (pstate))
            {
-             size_t i, len;
+             size_t i, j, len;
              const char *data;
 
              scm_putc ('"', port);
              len = scm_i_string_length (exp);
              data = scm_i_string_chars (exp);
-             for (i = 0; i < len; ++i)
+             for (i = 0, j = 0; i < len; ++i)
                {
                  unsigned char ch = data[i];
                  if ((ch < 32 && ch != '\n') || (127 <= ch && ch < 148))
                    {
                      static char const hex[]="0123456789abcdef";
-                     scm_putc ('\\', port);
-                     scm_putc ('x', port);
-                     scm_putc (hex [ch / 16], port);
-                     scm_putc (hex [ch % 16], port);
+                     char buf[4];
+
+                     scm_lfwrite (data+j, i-j, port);
+                     buf[0] = '\\';
+                     buf[1] = 'x';
+                     buf[2] =  hex [ch / 16];
+                     buf[3] = hex [ch % 16];
+                     scm_lfwrite (buf, 4, port);
+                     data = scm_i_string_chars (exp);
+                     j = i+1;
                    }
-                 else
+                 else if (ch == '"' || ch == '\\')
                    {
-                     if (ch == '"' || ch == '\\')
-                       scm_putc ('\\', port);
-                     scm_putc (ch, port);
+                     scm_lfwrite (data+j, i-j, port);
+                     scm_putc ('\\', port);
+                     data = scm_i_string_chars (exp);
+                     j = i;
                    }
                }
+             scm_lfwrite (data+j, i-j, port);
              scm_putc ('"', port);
              scm_remember_upto_here_1 (exp);
            }

-- 
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3  331E FAF8 226A D5D4 E405




reply via email to

[Prev in Thread] Current Thread [Next in Thread]