Version 1.8.6: Standardize on :encoding keyword
[uffi.git] / src / i18n.lisp
index 1f2bb1ad9a33286fd402304d0a0f8357e7b81458..ca2c1b439f392b176012041e730bbc7dce339689 100644 (file)
@@ -58,10 +58,8 @@ encoding.")
 (defun lookup-foreign-encoding (normalized)
   (cdr (assoc normalized *foreign-encoding-mapping* :test 'eql)))
 
-(defmacro string-to-octets (str &key (encoding *default-foreign-encoding*))
-  "Converts a Lisp string to a vector of octets."
-  #-(or allegro lispworks openmcl sbcl)
-  (declare (ignore encoding))
+(defmacro string-to-octets (str &key encoding)
+  (declare (ignorable encoding))
   #-(or allegro lispworks openmcl sbcl)
   (map-into (make-array (length str) :element-type '(unsigned-byte 8))
             #'char-code str)
@@ -70,7 +68,7 @@ encoding.")
   (let ((fe (gensym "FE-"))
         (ife (gensym "IFE-"))
         (s (gensym "STR-")))
-    `(let* ((,fe ,encoding)
+    `(let* ((,fe (or ,encoding *default-foreign-encoding*))
             (,ife (when ,fe (lookup-foreign-encoding ,fe)))
             (,s ,str))
        (values
@@ -88,7 +86,7 @@ encoding.")
   (let ((fe (gensym "FE-"))
         (ife (gensym "IFE-"))
         (s (gensym "STR-")))
-    `(let* ((,fe ,encoding)
+    `(let* ((,fe (or ,encoding *default-foreign-encoding*))
             (,ife (when ,fe (lookup-foreign-encoding ,fe)))
             (,s ,str))
        (if ,ife
@@ -97,10 +95,9 @@ encoding.")
 
 )
 
-(defmacro octets-to-string (octets &key (encoding *default-foreign-encoding*))
+(defmacro octets-to-string (octets &key encoding)
   "Converts a vector of octets to a Lisp string."
-  #-(or allegro lispworks openmcl sbcl)
-  (declare (ignore encoding))
+  (declare (ignorable encoding))
   #-(or allegro lispworks openmcl sbcl)
   (let ((out (gensym "OUT-"))
         (code (gensym "CODE-")))
@@ -112,7 +109,7 @@ encoding.")
   (let ((fe (gensym "FE-"))
         (ife (gensym "IFE-"))
         (oct (gensym "OCTETS-")))
-    `(let* ((,fe ,encoding)
+    `(let* ((,fe (or ,encoding *default-foreign-encoding*))
             (,ife (when ,fe (lookup-foreign-encoding ,fe)))
             (,oct ,octets))
        (values
@@ -132,7 +129,7 @@ encoding.")
   (let ((fe (gensym "FE-"))
         (ife (gensym "IFE-"))
         (oct (gensym "OCTETS-")))
-    `(let* ((,fe ,encoding)
+    `(let* ((,fe (or ,encoding *default-foreign-encoding*))
             (,ife (when ,fe (lookup-foreign-encoding ,fe)))
             (,oct ,octets))
        (if ,ife
@@ -141,18 +138,18 @@ encoding.")
 
 )
 
-(defun foreign-encoded-octet-count (str &key (encoding *default-foreign-encoding*))
+(defun foreign-encoded-octet-count (str &key encoding)
   "Returns the octets required to represent the string when passed to a ~
 foreign function."
+  (declare (ignorable encoding))
   ;; AllegroCL 8-bit, CCL, and Lispworks give correct value without converting
   ;; to external-format. AllegroCL 16-bit, SBCL, and CLISP requires conversion
   ;; with external-format
 
   #+(or (and allegro ics) (and sbcl sb-unicode) (and clisp i18n))
-  (length (string-to-octets str :encoding encoding))
+  (length (string-to-octets str :encoding
+                            (or encoding *default-foreign-encoding*)))
 
-  #-(or (and allegro ics) (and sbcl sb-unicode) (and clisp i18n))
-  (declare (ignore encoding))
   #-(or (and allegro ics) (and sbcl sb-unicode) (and clisp i18n))
   (length str)