Use `encoding-error' instead of `misc-error' for string encoding errors.
authorLudovic Courtès <ludo@gnu.org>
Wed, 6 Jan 2010 23:37:10 +0000 (00:37 +0100)
committerLudovic Courtès <ludo@gnu.org>
Thu, 7 Jan 2010 10:10:35 +0000 (11:10 +0100)
* libguile/strings.c (scm_encoding_error): New function.
  (scm_from_stringn, scm_to_stringn): Use it instead of `scm_misc_error ()'.

* test-suite/lib.scm (exception:encoding-error): Adjust accordingly.

* test-suite/tests/encoding-escapes.test (exception:conversion):
  Remove.  Use `exception:encoding-error' instead.

* test-suite/tests/encoding-iso88591.test: Likewise.

* test-suite/tests/encoding-iso88597.test: Likewise.

* test-suite/tests/encoding-utf8.test: Likewise.

libguile/strings.c
test-suite/lib.scm
test-suite/tests/encoding-escapes.test
test-suite/tests/encoding-iso88591.test
test-suite/tests/encoding-iso88597.test
test-suite/tests/encoding-utf8.test

index d977655a22fa000ab3526c680354883ef7f78f51..4ae07a2dd5e4e3331873e6e6c7f0809f13a78574 100644 (file)
@@ -35,6 +35,7 @@
 #include "libguile/chars.h"
 #include "libguile/root.h"
 #include "libguile/strings.h"
+#include "libguile/error.h"
 #include "libguile/generalized-vectors.h"
 #include "libguile/deprecation.h"
 #include "libguile/validate.h"
@@ -1386,6 +1387,16 @@ scm_is_string (SCM obj)
   return IS_STRING (obj);
 }
 
+\f
+/* Conversion to/from other encodings.  */
+
+SCM_SYMBOL (scm_encoding_error_key, "encoding-error");
+static void
+scm_encoding_error (const char *subr, const char *message, SCM args)
+{
+  scm_error (scm_encoding_error_key, subr, message, args, SCM_BOOL_F);
+}
+
 SCM
 scm_from_stringn (const char *str, size_t len, const char *encoding,
                   scm_t_string_failed_conversion_handler handler)
@@ -1426,9 +1437,10 @@ scm_from_stringn (const char *str, size_t len, const char *encoding,
           char *dst;
           errstr = scm_i_make_string (len, &dst);
           memcpy (dst, str, len);
-          scm_misc_error (NULL, "input locale conversion error from ~s: ~s",
-                          scm_list_2 (scm_from_locale_string (encoding),
-                                      errstr));
+          scm_encoding_error (NULL,
+                             "input locale conversion error from ~s: ~s",
+                             scm_list_2 (scm_from_locale_string (encoding),
+                                         errstr));
           scm_remember_upto_here_1 (errstr);
         }
     }
@@ -1675,11 +1687,8 @@ scm_to_stringn (SCM str, size_t *lenp, const char *encoding,
         unistring_escapes_to_guile_escapes (&buf, &len);
 
       if (ret != 0)
-        {
-          scm_misc_error (NULL, "cannot convert to output locale ~s: \"~s\"", 
-                          scm_list_2 (scm_from_locale_string (enc),
-                                      str));
-        }
+       scm_encoding_error (NULL, "cannot convert to output locale ~s: \"~s\"",
+                           scm_list_2 (scm_from_locale_string (enc), str));
     }
   else
     {
@@ -1690,11 +1699,9 @@ scm_to_stringn (SCM str, size_t *lenp, const char *encoding,
                                   NULL,
                                   NULL, &len);
       if (buf == NULL)
-        {
-          scm_misc_error (NULL, "cannot convert to output locale ~s: \"~s\"", 
-                          scm_list_2 (scm_from_locale_string (enc),
-                                      str));
-        }
+       scm_encoding_error (NULL, "cannot convert to output locale ~s: \"~s\"",
+                           scm_list_2 (scm_from_locale_string (enc), str));
+
       if (handler == SCM_FAILED_CONVERSION_ESCAPE_SEQUENCE)
         unistring_escapes_to_guile_escapes (&buf, &len);
     }
@@ -1740,6 +1747,9 @@ scm_to_locale_stringbuf (SCM str, char *buf, size_t max_len)
   return len;
 }
 
+\f
+/* Unicode string normalization.  */
+
 /* This function is a partial clone of SCM_STRING_TO_U32_BUF from 
    libguile/i18n.c.  It would be useful to have this factored out into a more
    convenient location, but its use of alloca makes that tricky to do. */
index a2390da67d29a41f3f688d7289b926b9ec3ad96b..1e78c71cfdc5863c46e1369de2f023468c5cce08 100644 (file)
@@ -269,7 +269,7 @@ with-locale with-locale*
 (define exception:system-error
   (cons 'system-error ".*"))
 (define exception:encoding-error
-  (cons 'misc-error "(cannot convert to output locale|input locale conversion error)"))
+  (cons 'encoding-error "(cannot convert to output locale|input locale conversion error)"))
 (define exception:miscellaneous-error
   (cons 'misc-error "^.*"))
 (define exception:read-error
index 85f613f49a0ac8afb55b41d7b8ab4796125ba4ae..01b2e202bcb6eff4f796407320021c794fa47e14 100644 (file)
@@ -1,6 +1,6 @@
 ;;;; encoding-escapes.test --- test suite for Guile's string encodings -*- mode: scheme; coding: utf-8 -*-
 ;;;;
-;;;; Copyright (C) 2009 Free Software Foundation, Inc.
+;;;; Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 ;;;;
 ;;;; This library is free software; you can redistribute it and/or
 ;;;; modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,6 @@
   #:use-module (test-suite lib)
   #:use-module (srfi srfi-1))
 
-(define exception:conversion
-  (cons 'misc-error "^cannot convert to output locale"))
-
 ;; Create a string from integer char values, eg. (string-ints 65) => "A"
 (define (string-ints . args)
   (apply string (map integer->char args)))
 (with-test-prefix "display output errors"
 
   (pass-if-exception "ultima"
-                    exception:conversion
+                    exception:encoding-error
                     (let ((pt (open-output-string)))
                       (set-port-encoding! pt "ASCII")
                       (set-port-conversion-strategy! pt 'error)
                       (display s1 pt)))
 
   (pass-if-exception "Rashomon"
-                    exception:conversion
+                    exception:encoding-error
                     (let ((pt (open-output-string)))
                       (set-port-encoding! pt "ASCII")
                       (set-port-conversion-strategy! pt 'error)
index 32d2ed5116c49d211975f71775658e98f43cd72c..bcc8aa75ab63193deb25e31d8842ecb33e2b5a7f 100644 (file)
@@ -1,6 +1,6 @@
 ;;;; encoding-iso88591.test --- test suite for Guile's string encodings    -*- mode: scheme; coding: iso-8859-1 -*-
 ;;;;
-;;;; Copyright (C) 2009 Free Software Foundation, Inc.
+;;;; Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 ;;;;
 ;;;; This library is free software; you can redistribute it and/or
 ;;;; modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,6 @@
   #:use-module (test-suite lib)
   #:use-module (srfi srfi-1))
 
-(define exception:conversion
-  (cons 'misc-error "^cannot convert to output locale"))
-
 ;; Create a string from integer char values, eg. (string-ints 65) => "A"
 (define (string-ints . args)
   (apply string (map integer->char args)))
 
 (with-test-prefix "output errors"
 
-  (pass-if-exception "char 256" exception:conversion
+  (pass-if-exception "char 256" exception:encoding-error
                     (let ((pt (open-output-string)))
                       (set-port-encoding! pt "ISO-8859-1")
                       (set-port-conversion-strategy! pt 'error)
index eae3fab4daef98b99a00ebfecca4c2d1da8bdc12..f11619459f6ebf1a863f0e88c547114597a46fc7 100644 (file)
@@ -1,6 +1,6 @@
 ;;;; encoding-iso88697.test --- test suite for Guile's string encodings    -*- mode: scheme; coding: iso-8859-7 -*-
 ;;;;
-;;;; Copyright (C) 2009 Free Software Foundation, Inc.
+;;;; Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 ;;;;
 ;;;; This library is free software; you can redistribute it and/or
 ;;;; modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,6 @@
   #:use-module (test-suite lib)
   #:use-module (srfi srfi-1))
 
-(define exception:conversion
-  (cons 'misc-error "^cannot convert to output locale"))
-
 ;; Create a string from integer char values, eg. (string-ints 65) => "A"
 (define (string-ints . args)
   (apply string (map integer->char args)))
 (with-test-prefix "output errors"
 
   (pass-if-exception "char #x0400"
-                    exception:conversion
+                    exception:encoding-error
                     (let ((pt (open-output-string)))
                       (set-port-encoding! pt "ISO-8859-7")
                       (set-port-conversion-strategy! pt 'error)
index d5e6370482aad2d006a8790e28071f3c03ec6db1..b82994c3a8eb071b54f6d1f6c498f103cb736989 100644 (file)
@@ -1,6 +1,6 @@
 ;;;; encoding-utf8.test --- test suite for Guile's string encodings    -*- mode: scheme; coding: utf-8 -*-
 ;;;;
-;;;; Copyright (C) 2009 Free Software Foundation, Inc.
+;;;; Copyright (C) 2009, 2010 Free Software Foundation, Inc.
 ;;;;
 ;;;; This library is free software; you can redistribute it and/or
 ;;;; modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,6 @@
   #:use-module (test-suite lib)
   #:use-module (srfi srfi-1))
 
-(define exception:conversion
-  (cons 'misc-error "^cannot convert to output locale"))
-
 ;; Create a string from integer char values, eg. (string-ints 65) => "A"
 (define (string-ints . args)
   (apply string (map integer->char args)))