* Added utf8->string and string->utf8
This commit is contained in:
parent
63975eba38
commit
5f19e802f6
BIN
src/ikarus.boot
BIN
src/ikarus.boot
Binary file not shown.
|
@ -1,10 +1,12 @@
|
||||||
|
|
||||||
(library (ikarus date-string)
|
(library (ikarus date-string)
|
||||||
(export date-string)
|
(export date-string)
|
||||||
(import (except (ikarus) date-string))
|
(import
|
||||||
|
(rnrs bytevectors)
|
||||||
|
(except (ikarus) date-string))
|
||||||
(define date-string
|
(define date-string
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(let ([s (make-bytevector 10)])
|
(let ([s (make-bytevector 10)])
|
||||||
(foreign-call "ikrt_bvftime" s
|
(foreign-call "ikrt_bvftime" s
|
||||||
(string->utf8-bytevector "%F"))
|
(string->utf8 "%F"))
|
||||||
(utf8-bytevector->string s)))))
|
(utf8->string s)))))
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
(export assemble-sources code-entry-adjustment)
|
(export assemble-sources code-entry-adjustment)
|
||||||
(import
|
(import
|
||||||
(ikarus)
|
(ikarus)
|
||||||
|
(rnrs bytevectors)
|
||||||
(except (ikarus code-objects) procedure-annotation)
|
(except (ikarus code-objects) procedure-annotation)
|
||||||
(ikarus system $pairs))
|
(ikarus system $pairs))
|
||||||
|
|
||||||
|
@ -903,7 +904,7 @@
|
||||||
(let f ([ls mem])
|
(let f ([ls mem])
|
||||||
(cond
|
(cond
|
||||||
[(null? ls)
|
[(null? ls)
|
||||||
(let ([bv (string->utf8-bytevector x)])
|
(let ([bv (string->utf8 x)])
|
||||||
(set! mem (cons (cons x bv) mem))
|
(set! mem (cons (cons x bv) mem))
|
||||||
bv)]
|
bv)]
|
||||||
[(string=? x (caar ls)) (cdar ls)]
|
[(string=? x (caar ls)) (cdar ls)]
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
(ikarus system $strings)
|
(ikarus system $strings)
|
||||||
(ikarus system $bytevectors)
|
(ikarus system $bytevectors)
|
||||||
(ikarus system $chars)
|
(ikarus system $chars)
|
||||||
|
(rnrs bytevectors)
|
||||||
(except (ikarus)
|
(except (ikarus)
|
||||||
open-input-file current-input-port console-input-port
|
open-input-file current-input-port console-input-port
|
||||||
with-input-from-file call-with-input-file
|
with-input-from-file call-with-input-file
|
||||||
|
@ -165,7 +166,7 @@
|
||||||
(lambda (filename)
|
(lambda (filename)
|
||||||
(close-ports)
|
(close-ports)
|
||||||
(let ([fd/error (foreign-call "ikrt_open_input_file"
|
(let ([fd/error (foreign-call "ikrt_open_input_file"
|
||||||
(string->utf8-bytevector filename))])
|
(string->utf8 filename))])
|
||||||
(if (fixnum? fd/error)
|
(if (fixnum? fd/error)
|
||||||
(let ([port (make-input-port
|
(let ([port (make-input-port
|
||||||
(make-input-file-handler fd/error filename)
|
(make-input-file-handler fd/error filename)
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
(ikarus system $chars)
|
(ikarus system $chars)
|
||||||
(ikarus system $bytevectors)
|
(ikarus system $bytevectors)
|
||||||
(ikarus system $fx)
|
(ikarus system $fx)
|
||||||
|
(rnrs bytevectors)
|
||||||
(except (ikarus)
|
(except (ikarus)
|
||||||
standard-output-port standard-error-port
|
standard-output-port standard-error-port
|
||||||
console-output-port current-output-port
|
console-output-port current-output-port
|
||||||
|
@ -132,7 +133,7 @@
|
||||||
(close-ports)
|
(close-ports)
|
||||||
(let ([fd/error
|
(let ([fd/error
|
||||||
(foreign-call "ikrt_open_output_file"
|
(foreign-call "ikrt_open_output_file"
|
||||||
(string->utf8-bytevector filename)
|
(string->utf8 filename)
|
||||||
(option-id options))])
|
(option-id options))])
|
||||||
(if (fixnum? fd/error)
|
(if (fixnum? fd/error)
|
||||||
(let ([port
|
(let ([port
|
||||||
|
|
|
@ -138,7 +138,7 @@
|
||||||
(set! open? #f)]
|
(set! open? #f)]
|
||||||
[(port-name p) 'string-port]
|
[(port-name p) 'string-port]
|
||||||
[(get-output-string p)
|
[(get-output-string p)
|
||||||
(utf8-bytevector->string
|
(utf8->string
|
||||||
(concat
|
(concat
|
||||||
($port-buffer p)
|
($port-buffer p)
|
||||||
($port-index p)
|
($port-index p)
|
||||||
|
|
|
@ -1177,7 +1177,7 @@
|
||||||
|
|
||||||
(define bignum->string
|
(define bignum->string
|
||||||
(lambda (x)
|
(lambda (x)
|
||||||
(utf8-bytevector->string
|
(utf8->string
|
||||||
(foreign-call "ikrt_bignum_to_bytevector" x))))
|
(foreign-call "ikrt_bignum_to_bytevector" x))))
|
||||||
|
|
||||||
(define ratnum->string
|
(define ratnum->string
|
||||||
|
@ -2278,6 +2278,7 @@
|
||||||
(library (ikarus flonum-conversion)
|
(library (ikarus flonum-conversion)
|
||||||
(export string->flonum flonum->string)
|
(export string->flonum flonum->string)
|
||||||
(import
|
(import
|
||||||
|
(rnrs bytevectors)
|
||||||
(ikarus system $bytevectors)
|
(ikarus system $bytevectors)
|
||||||
(ikarus system $flonums)
|
(ikarus system $flonums)
|
||||||
(except (ikarus) flonum->string string->flonum ))
|
(except (ikarus) flonum->string string->flonum ))
|
||||||
|
@ -2422,7 +2423,7 @@
|
||||||
(cond
|
(cond
|
||||||
[(string? x)
|
[(string? x)
|
||||||
(foreign-call "ikrt_bytevector_to_flonum"
|
(foreign-call "ikrt_bytevector_to_flonum"
|
||||||
(string->utf8-bytevector x))]
|
(string->utf8 x))]
|
||||||
[else
|
[else
|
||||||
(error 'string->flonum "~s is not a string" x)])) )
|
(error 'string->flonum "~s is not a string" x)])) )
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
(export posix-fork fork waitpid system file-exists? delete-file
|
(export posix-fork fork waitpid system file-exists? delete-file
|
||||||
env environ)
|
env environ)
|
||||||
(import
|
(import
|
||||||
|
(rnrs bytevectors)
|
||||||
(except (ikarus)
|
(except (ikarus)
|
||||||
posix-fork fork waitpid system file-exists? delete-file
|
posix-fork fork waitpid system file-exists? delete-file
|
||||||
env environ))
|
env environ))
|
||||||
|
@ -31,7 +32,7 @@
|
||||||
(unless (string? x)
|
(unless (string? x)
|
||||||
(error 'system "~s is not a string" x))
|
(error 'system "~s is not a string" x))
|
||||||
(let ([rv (foreign-call "ik_system"
|
(let ([rv (foreign-call "ik_system"
|
||||||
(string->utf8-bytevector x))])
|
(string->utf8 x))])
|
||||||
(if (fx= rv -1)
|
(if (fx= rv -1)
|
||||||
(error 'system "failed")
|
(error 'system "failed")
|
||||||
rv))))
|
rv))))
|
||||||
|
@ -41,7 +42,7 @@
|
||||||
(unless (string? x)
|
(unless (string? x)
|
||||||
(error 'file-exists? "filename ~s is not a string" x))
|
(error 'file-exists? "filename ~s is not a string" x))
|
||||||
(let ([v (foreign-call "ikrt_file_exists"
|
(let ([v (foreign-call "ikrt_file_exists"
|
||||||
(string->utf8-bytevector x))])
|
(string->utf8 x))])
|
||||||
(cond
|
(cond
|
||||||
[(boolean? v) v]
|
[(boolean? v) v]
|
||||||
[else
|
[else
|
||||||
|
@ -61,7 +62,7 @@
|
||||||
(unless (string? x)
|
(unless (string? x)
|
||||||
(error 'delete-file "filename ~s is not a string" x))
|
(error 'delete-file "filename ~s is not a string" x))
|
||||||
(let ([v (foreign-call "ikrt_delete_file"
|
(let ([v (foreign-call "ikrt_delete_file"
|
||||||
(string->utf8-bytevector x))])
|
(string->utf8 x))])
|
||||||
(case v
|
(case v
|
||||||
[(0) (void)]
|
[(0) (void)]
|
||||||
[else
|
[else
|
||||||
|
|
|
@ -439,7 +439,7 @@
|
||||||
(define uuid
|
(define uuid
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(let ([s ($make-bytevector 16)])
|
(let ([s ($make-bytevector 16)])
|
||||||
(utf8-bytevector->string
|
(utf8->string
|
||||||
(or (foreign-call "ik_uuid" s)
|
(or (foreign-call "ik_uuid" s)
|
||||||
(error 'uuid "failed!"))))))
|
(error 'uuid "failed!"))))))
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
|
|
||||||
(library (ikarus transcoders)
|
(library (ikarus transcoders)
|
||||||
(export string->utf8-bytevector
|
(export string->utf8 utf8->string)
|
||||||
utf8-bytevector->string)
|
(import (except (ikarus) string->utf8 utf8->string)
|
||||||
(import (except (ikarus) string->utf8-bytevector utf8-bytevector->string)
|
|
||||||
(ikarus system $strings)
|
(ikarus system $strings)
|
||||||
(ikarus system $bytevectors)
|
(ikarus system $bytevectors)
|
||||||
(ikarus system $fx)
|
(ikarus system $fx)
|
||||||
|
@ -22,7 +21,7 @@
|
||||||
;;; replace: places a U+FFFD in place of the malformed bytes
|
;;; replace: places a U+FFFD in place of the malformed bytes
|
||||||
;;; raise: raises an error
|
;;; raise: raises an error
|
||||||
|
|
||||||
(define string->utf8-bytevector
|
(define string->utf8
|
||||||
(lambda (str)
|
(lambda (str)
|
||||||
(define (utf8-string-size str)
|
(define (utf8-string-size str)
|
||||||
(let f ([str str] [i 0] [j ($string-length str)] [n 0])
|
(let f ([str str] [i 0] [j ($string-length str)] [n 0])
|
||||||
|
@ -74,14 +73,16 @@
|
||||||
($fxlogor #b10000000 ($fxlogand b #b111111)))
|
($fxlogor #b10000000 ($fxlogand b #b111111)))
|
||||||
(f bv str ($fxadd1 i) ($fx+ j 4) n)])))])))
|
(f bv str ($fxadd1 i) ($fx+ j 4) n)])))])))
|
||||||
(unless (string? str)
|
(unless (string? str)
|
||||||
(error 'string->utf8-bytevector "~s is not a string" str))
|
(error 'string->utf8 "~s is not a string" str))
|
||||||
(fill-utf8-bytevector
|
(fill-utf8-bytevector
|
||||||
($make-bytevector (utf8-string-size str))
|
($make-bytevector (utf8-string-size str))
|
||||||
str)))
|
str)))
|
||||||
|
|
||||||
(define utf8-bytevector->string
|
(define (utf8->string x) (decode-utf8-bytevector x 'replace))
|
||||||
|
|
||||||
|
(define decode-utf8-bytevector
|
||||||
(let ()
|
(let ()
|
||||||
(define who 'utf8-bytevector->string)
|
(define who 'decode-utf8-bytevector)
|
||||||
(define (count bv mode)
|
(define (count bv mode)
|
||||||
(let f ([x bv] [i 0] [j ($bytevector-length bv)] [n 0] [mode mode])
|
(let f ([x bv] [i 0] [j ($bytevector-length bv)] [n 0] [mode mode])
|
||||||
(cond
|
(cond
|
||||||
|
@ -241,7 +242,7 @@
|
||||||
[(bv) (convert bv 'raise)]
|
[(bv) (convert bv 'raise)]
|
||||||
[(bv handling-mode)
|
[(bv handling-mode)
|
||||||
(unless (memq handling-mode '(ignore replace raise))
|
(unless (memq handling-mode '(ignore replace raise))
|
||||||
(error 'utf8-bytevector->string
|
(error 'decode-utf8-bytevector
|
||||||
"~s is not a valid handling mode"
|
"~s is not a valid handling mode"
|
||||||
handling-mode))
|
handling-mode))
|
||||||
(convert bv handling-mode)])))
|
(convert bv handling-mode)])))
|
||||||
|
|
|
@ -214,9 +214,6 @@
|
||||||
[weak-pair? i]
|
[weak-pair? i]
|
||||||
[uuid i]
|
[uuid i]
|
||||||
[date-string i]
|
[date-string i]
|
||||||
[string->utf8-bytevector i]
|
|
||||||
[utf8-bytevector->string i]
|
|
||||||
[$two-bignums i]
|
|
||||||
[andmap i]
|
[andmap i]
|
||||||
[ormap i]
|
[ormap i]
|
||||||
[fx< i]
|
[fx< i]
|
||||||
|
@ -843,10 +840,10 @@
|
||||||
[sint-list->bytevector i r bv]
|
[sint-list->bytevector i r bv]
|
||||||
[string->utf16 r bv]
|
[string->utf16 r bv]
|
||||||
[string->utf32 r bv]
|
[string->utf32 r bv]
|
||||||
[string->utf8 r bv]
|
[string->utf8 i r bv]
|
||||||
[u8-list->bytevector i r bv]
|
[u8-list->bytevector i r bv]
|
||||||
[uint-list->bytevector i r bv]
|
[uint-list->bytevector i r bv]
|
||||||
[utf8->string r bv]
|
[utf8->string i r bv]
|
||||||
[utf16->string r bv]
|
[utf16->string r bv]
|
||||||
[utf32->string r bv]
|
[utf32->string r bv]
|
||||||
[condition? r co]
|
[condition? r co]
|
||||||
|
|
|
@ -407,10 +407,10 @@
|
||||||
[sint-list->bytevector C bv]
|
[sint-list->bytevector C bv]
|
||||||
[string->utf16 S bv]
|
[string->utf16 S bv]
|
||||||
[string->utf32 S bv]
|
[string->utf32 S bv]
|
||||||
[string->utf8 S bv]
|
[string->utf8 C bv]
|
||||||
[u8-list->bytevector C bv]
|
[u8-list->bytevector C bv]
|
||||||
[uint-list->bytevector C bv]
|
[uint-list->bytevector C bv]
|
||||||
[utf8->string S bv]
|
[utf8->string C bv]
|
||||||
[utf16->string S bv]
|
[utf16->string S bv]
|
||||||
[utf32->string S bv]
|
[utf32->string S bv]
|
||||||
;;;
|
;;;
|
||||||
|
|
Loading…
Reference in New Issue