From f6b384e3c984984d39653dca5cdffc6f19471035 Mon Sep 17 00:00:00 2001
From: Chris Hanson <org/chris-hanson/cph>
Date: Sun, 30 Apr 2017 00:23:14 -0700
Subject: [PATCH] Implement string<->iso8859-1 converters.

---
 src/runtime/bytevector.scm | 19 +++++++++++++++++++
 src/runtime/runtime.pkg    |  2 ++
 2 files changed, 21 insertions(+)

diff --git a/src/runtime/bytevector.scm b/src/runtime/bytevector.scm
index 422f5ae3f..28b792d83 100644
--- a/src/runtime/bytevector.scm
+++ b/src/runtime/bytevector.scm
@@ -397,6 +397,25 @@ USA.
 	 (bytes-decoder bytevector-u32le-ref initial-u32->utf32-char-length
 			decode-utf32le-char 1 "UTF-32LE" 'utf32le->string))
    unspecific))
+
+(define (string->iso8859-1 string #!optional start end)
+  (let* ((end (fix:end-index end (string-length string) 'string->iso8859-1))
+	 (start (fix:start-index start end 'string->iso8859-1))
+	 (result (allocate-bytevector (fix:- end start))))
+    (do ((i start (fix:+ i 1))
+	 (j 0 (fix:+ j 1)))
+	((not (fix:< i end)))
+      (bytevector-u8-set! result j (char->integer (string-ref string i))))
+    result))
+
+(define (iso8859-1->string bytes #!optional start end)
+  (let* ((end (fix:end-index end (bytevector-length bytes) 'iso8859-1->string))
+	 (start (fix:start-index start end 'iso8859-1->string))
+	 (builder (string-builder)))
+    (do ((i start (fix:+ i 1)))
+	((not (fix:< i end)))
+      (builder (integer->char (bytevector-u8-ref bytes i))))
+    (builder)))
 
 (define (bytevector->hexadecimal bytes)
   (define-integrable (hex-char k)
diff --git a/src/runtime/runtime.pkg b/src/runtime/runtime.pkg
index d5f210559..1c44a8add 100644
--- a/src/runtime/runtime.pkg
+++ b/src/runtime/runtime.pkg
@@ -1104,8 +1104,10 @@ USA.
 	  bytevector?
 	  exact-nonnegative-integer->bytevector
 	  hexadecimal->bytevector
+	  iso8859-1->string
 	  list->bytevector
 	  make-bytevector
+	  string->iso8859-1
 	  string->utf16be
 	  string->utf16le
 	  string->utf32be
-- 
2.25.1