(defun implementation-foreign-encoding (normalized)
(cdr (assoc normalized *foreign-encoding-mapping* :test 'eql)))
-(defun foreign-encoded-string-octets (str &optional foreign-encoding)
+(defun foreign-encoded-string-octets (str &key foreign-encoding)
"Returns the octets required to represent the string when passed to a ~
foreign function."
;; AllegroCL, CCL, and Lispworks give correct value without converting
*default-foreign-encoding*
:utf-8))
#-(and sbcl sb-unicode) str))
+
+(defun string-to-octets (str &key foreign-encoding)
+ "Converts a Lisp string to a vector of octets."
+ #-(or allegro lispworks openmcl sbcl)
+ (declare (ignore foreign-encoding))
+ #-(or allegro lispworks openmcl sbcl)
+ (map-into (make-array len :element-type '(unsigned-byte 8))
+ #'char-code str)
+
+ #+allegro
+ (excl:string-to-native str :external-format foreign-encoding :null-terminate nil)
+
+ #+(or lispworks openmcl)
+ ;; simply reading each char-code from the LENGTH of string handles multibyte characters
+ ;; just fine in testing LW 6.0 and CCL 1.4
+ (map-into (make-array len :element-type '(unsigned-byte 8))
+ #'char-code str)
+
+ #+sbcl
+ (sb-ext:string-to-native str :external-format foreign-encoding)
+
+)
+