mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-22 03:30:22 +02:00
Allow decoding of UTF-8 containing U+FFFD, the replacement character.
* libguile/strings.c (scm_from_utf8_stringn): Use 'u8_mbtoucr' and check for a decoding error by its 'nbytes' return value. Previously we used 'u8_mbtouc' and improperly assumed that a U+FFFD character indicated a decoding error. * libguile/symbols.c (utf8_string_equals_wide_string): Likewise. * test-suite/tests/bytevectors.test (exception:decoding-error): New variable. ("2.9 Operations on Strings"): Add tests.
This commit is contained in:
parent
48412395c6
commit
00884bb79f
3 changed files with 21 additions and 8 deletions
|
@ -1,6 +1,6 @@
|
|||
;;;; bytevectors.test --- R6RS bytevectors. -*- mode: scheme; coding: utf-8; -*-
|
||||
;;;;
|
||||
;;;; Copyright (C) 2009-2014 Free Software Foundation, Inc.
|
||||
;;;; Copyright (C) 2009-2015 Free Software Foundation, Inc.
|
||||
;;;;
|
||||
;;;; Ludovic Courtès
|
||||
;;;;
|
||||
|
@ -24,6 +24,9 @@
|
|||
:use-module (rnrs bytevectors)
|
||||
:use-module (srfi srfi-4))
|
||||
|
||||
(define exception:decoding-error
|
||||
(cons 'decoding-error "input (locale conversion|decoding) error"))
|
||||
|
||||
;;; Some of the tests in here are examples taken from the R6RS Standard
|
||||
;;; Libraries document.
|
||||
|
||||
|
@ -501,6 +504,15 @@
|
|||
(= (string-length str)
|
||||
(- (bytevector-length utf8) 2)))))
|
||||
|
||||
(pass-if-equal "utf8->string [replacement character]"
|
||||
'(104 105 65533)
|
||||
(map char->integer
|
||||
(string->list (utf8->string #vu8(104 105 239 191 189)))))
|
||||
|
||||
(pass-if-exception "utf8->string [invalid encoding]"
|
||||
exception:decoding-error
|
||||
(utf8->string #vu8(104 105 239 191 50)))
|
||||
|
||||
(pass-if "utf16->string"
|
||||
(let* ((utf16 (uint-list->bytevector (map char->integer
|
||||
(string->list "hello, world"))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue