From: Chris Hanson Date: Sun, 30 Apr 2017 07:23:14 +0000 (-0700) Subject: Implement string<->iso8859-1 converters. X-Git-Tag: mit-scheme-pucked-9.2.12~14^2~104 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=f6b384e3c984984d39653dca5cdffc6f19471035;p=mit-scheme.git Implement string<->iso8859-1 converters. --- 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