[slime-cvs] CVS slime

CVS User heller heller at common-lisp.net
Sun Nov 6 17:04:10 UTC 2011


Update of /project/slime/cvsroot/slime
In directory tiger.common-lisp.net:/tmp/cvs-serv10844

Modified Files:
	ChangeLog swank-abcl.lisp 
Log Message:
* swank-abcl.lisp (string-to-utf8, string-to-utf8): Implemented.
(octets-to-jbytes, jbytes-to-octets): New helpers.

--- /project/slime/cvsroot/slime/ChangeLog	2011/11/06 17:03:59	1.2223
+++ /project/slime/cvsroot/slime/ChangeLog	2011/11/06 17:04:10	1.2224
@@ -1,5 +1,10 @@
 2011-11-06  Helmut Eller  <heller at common-lisp.net>
 
+	* swank-abcl.lisp (string-to-utf8, string-to-utf8): Implemented.
+	(octets-to-jbytes, jbytes-to-octets): New helpers.
+
+2011-11-06  Helmut Eller  <heller at common-lisp.net>
+
 	* swank-backend.lisp (utf8-to-string, string-to-utf8): New.
 
 2011-11-03  Helmut Eller  <heller at common-lisp.net>
--- /project/slime/cvsroot/slime/swank-abcl.lisp	2011/09/27 06:06:28	1.87
+++ /project/slime/cvsroot/slime/swank-abcl.lisp	2011/11/06 17:04:10	1.88
@@ -146,6 +146,44 @@
   (ext:get-socket-stream (ext:socket-accept socket)
                          :external-format external-format))
 
+;;;; UTF8 
+
+;; faster please!
+(defimplementation string-to-utf8 (s)
+  (jbytes-to-octets
+   (java:jcall 
+    (java:jmethod "java.lang.String" "getBytes" "java.lang.String")
+    s
+    "UTF8")))
+
+(defimplementation utf8-to-string (u)
+  (java:jnew 
+   (java:jconstructor "org.armedbear.lisp.SimpleString" 
+                      "java.lang.String")
+   (java:jnew (java:jconstructor "java.lang.String" "[B" "java.lang.String")
+              (octets-to-jbytes u)
+              "UTF8")))
+
+(defun octets-to-jbytes (octets)
+  (declare (type octets (simple-array (unsigned-byte 8) (*))))
+  (let* ((len (length octets))
+         (bytes (java:jnew-array "byte" len)))
+    (loop for byte across octets
+          for i from 0
+          do (java:jstatic (java:jmethod "java.lang.reflect.Array"  "setByte" 
+                            "java.lang.Object" "int" "byte")
+                           "java.lang.relect.Array"
+                           bytes i byte))
+    bytes))
+
+(defun jbytes-to-octets (jbytes)
+  (let* ((len (java:jarray-length jbytes))
+         (octets (make-array len :element-type '(unsigned-byte 8))))
+    (loop for i from 0 below len
+          for jbyte = (java:jarray-ref jbytes i)
+          do (setf (aref octets i) jbyte))
+    octets))
+
 ;;;; External formats
 
 (defvar *external-format-to-coding-system*





More information about the slime-cvs mailing list