[uim-commit] r898 - trunk/scm

tkng at freedesktop.org tkng at freedesktop.org
Mon Jun 20 10:27:03 PDT 2005


Author: tkng
Date: 2005-06-20 10:27:00 -0700 (Mon, 20 Jun 2005)
New Revision: 898

Modified:
   trunk/scm/util.scm
Log:
* scm/util.scm:
 -(ucs-to-utf8-string): New function. Thanks to Park Jae-hyeon.

Modified: trunk/scm/util.scm
===================================================================
--- trunk/scm/util.scm	2005-06-20 01:35:48 UTC (rev 897)
+++ trunk/scm/util.scm	2005-06-20 17:27:00 UTC (rev 898)
@@ -670,3 +670,18 @@
       multi-segment-type-hiragana)
      ((= kana multi-segment-type-hankana)
       multi-segment-type-hiragana))))
+
+
+;; FIXME: write test.
+(define (ucs-to-utf8-string ucs)
+  (let ((utf-8
+	 (if (< ucs 128)
+	     (list ucs)		; ASCII
+	     (let enc ((to-be-split ucs)
+		       (threshold 64))
+	       (if (< to-be-split threshold)
+		   (list (bit-or to-be-split
+				 (bit-xor 255 (- (* 2 threshold) 1))))
+		   (cons (bit-or 128 (bit-and 63 to-be-split))
+			 (enc (/ to-be-split 64) (/ threshold 2))))))))
+    (string-append-map charcode->string (reverse utf-8))))
\ No newline at end of file



More information about the uim-commit mailing list