From 8de7a000299f9bfaba54a718ec264f6d0dafdfed Mon Sep 17 00:00:00 2001 From: Thayne McCombs Date: Sat, 17 Oct 2015 11:38:46 -0600 Subject: [PATCH] Add a find-string-mapping function. Provide a way for user code to access mappings in *string-vector-mappings* without having to use an non-exported symbol. --- src/packages.lisp | 2 ++ src/strings.lisp | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/packages.lisp b/src/packages.lisp index ace36e8..19d97d0 100644 --- a/src/packages.lisp +++ b/src/packages.lisp @@ -83,6 +83,8 @@ ;; fixed sharp-backslash reader #:enable-sharp-backslash-syntax #:set-sharp-backslash-syntax-in-readtable + ;; mappings + #:find-string-mapping ;; external formats #:external-format #:make-external-format diff --git a/src/strings.lisp b/src/strings.lisp index ba02089..e852d39 100644 --- a/src/strings.lisp +++ b/src/strings.lisp @@ -129,6 +129,11 @@ are less than UNICODE-CHAR-CODE-LIMIT." :code-point-seq-getter string-get :code-point-seq-type simple-base-string)) +(declaim (inline find-string-mapping)) +(defun find-string-mapping (encoding) + "Find the mapping for an encoding and a simple-unicode-string." + (lookup-mapping *string-vector-mappings* encoding)) + ;;; Do we want a more a specific error condition here? (defun check-vector-bounds (vector start end) (unless (<= 0 start end (length vector)) @@ -225,7 +230,7 @@ shouldn't attempt to modify V." (with-checked-simple-vector ((vector vector) (start start) (end end)) (declare (type (simple-array (unsigned-byte 8) (*)) vector)) (let ((*suppress-character-coding-errors* (not errorp)) - (mapping (lookup-mapping *string-vector-mappings* encoding))) + (mapping (find-string-mapping encoding))) (multiple-value-bind (size new-end) (funcall (code-point-counter mapping) vector start end -1) ;; TODO we could optimize ASCII here: the result should @@ -286,7 +291,7 @@ shouldn't attempt to modify V." (with-checked-simple-vector ((string (coerce string 'unicode-string)) (start start) (end end)) (declare (type simple-unicode-string string)) - (let* ((mapping (lookup-mapping *string-vector-mappings* encoding)) + (let* ((mapping (find-string-mapping encoding)) (bom (bom-vector encoding use-bom)) (bom-length (length bom)) (result (make-array