Implement converters between utf8-string and ustring.
authorChris Hanson <org/chris-hanson/cph>
Fri, 27 Jan 2017 06:08:09 +0000 (22:08 -0800)
committerChris Hanson <org/chris-hanson/cph>
Fri, 27 Jan 2017 06:08:09 +0000 (22:08 -0800)
These are temporary: both utf8-string and wide-string are going to be
eliminated.  Until then, we need some scaffolding to incrementally rewrite code
that uses them.

src/runtime/runtime.pkg
src/runtime/ustring.scm

index 836ce2b1693ec7cdaac333b6a9856cff9e555a15..a01d66384d0a20191e5d476c5ec74892140e8a46 100644 (file)
@@ -1172,6 +1172,7 @@ USA.
          ustring*
          ustring->ascii
          ustring->list
+         ustring->utf8-string          ;temporary scaffolding
          ustring->vector
          ustring-any
          ustring-append
@@ -1213,6 +1214,7 @@ USA.
          ustring>=?
          ustring>?
          ustring?
+         utf8-string->ustring          ;temporary scaffolding
          ;; vector->ustring
          )
   (export (runtime predicate-metadata)
index 1edfc87713b5c585b9605bfb0131d4be3305d0d6..8937d66f089f45e8be961240d353d7e258777e4d 100644 (file)
@@ -702,4 +702,27 @@ USA.
 
 (define (string-for-primitive string)
   (or (ustring->ascii string)
-      (string->utf8 string)))
\ No newline at end of file
+      (string->utf8 string)))
+
+;; temporary scaffolding
+(define (ustring->utf8-string string #!optional start end)
+  (let* ((caller 'ustring->utf8-string)
+        (end (fix:end-index end (ustring-length string) caller))
+        (start (fix:start-index start end caller)))
+    (cond ((legacy-string? string)
+          (if (%legacy-string-ascii? string start end)
+              (legacy-string-copy string start end)
+              (%string->utf8-string string start end)))
+         ((utf32-string? string)
+          (if (%utf32-string-ascii? string start end)
+              (%utf32-string->ascii string start end)
+              (%string->utf8-string string start end)))
+         (else
+          (error:not-a ustring? string caller)))))
+
+(define (%string->utf8-string string start end)
+  (object-new-type (ucode-type string) (string->utf8 string start end)))
+
+;; temporary scaffolding
+(define (utf8-string->ustring string #!optional start end)
+  (utf8->string (legacy-string->bytevector string) start end))
\ No newline at end of file