X-Git-Url: http://git.kpe.io/?p=uffi.git;a=blobdiff_plain;f=src%2Fi18n.lisp;h=08c16ad0b54eb962721764deaa4eea9c4a34feaa;hp=47a06db565268760cd5e6d3840c4a8683abc4932;hb=3044928889785c0160fd021a51fbf86ad691a3a9;hpb=01066b26a984761a2c9372871bba3697984a4456 diff --git a/src/i18n.lisp b/src/i18n.lisp index 47a06db..08c16ad 100644 --- a/src/i18n.lisp +++ b/src/i18n.lisp @@ -58,7 +58,7 @@ encoding.") (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 @@ -71,3 +71,26 @@ foreign function." *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) + +) +