diff --git a/pkgs/racket-test-core/tests/racket/unicode.rktl b/pkgs/racket-test-core/tests/racket/unicode.rktl index 95b2a29ec5..eb2aa1c6de 100644 --- a/pkgs/racket-test-core/tests/racket/unicode.rktl +++ b/pkgs/racket-test-core/tests/racket/unicode.rktl @@ -628,25 +628,39 @@ [s (apply bytes (caddr p))]) (if (and (positive? (vector-length code-points)) (vector-ref code-points 0)) - (begin - (test (vector-length code-points) bytes-utf-8-length s) + (let ([len (vector-length code-points)] + [c0 (integer->char (vector-ref code-points 0))]) + (test len bytes-utf-8-length s) + (test len bytes-utf-8-length s #f) + (test len bytes-utf-8-length s #\x) + (test len bytes-utf-8-length s #f 0) + (test len bytes-utf-8-length s #f 0 (bytes-length s)) + (test (sub1 len) bytes-utf-8-length s #f (char-utf-8-length c0) (bytes-length s)) + (test (sub1 len) bytes-utf-8-length s #f 0 (- (bytes-length s) + (char-utf-8-length + (integer->char + (vector-ref code-points (sub1 len)))))) (test code-points bytes->unicode-vector s) (test code-points bytes-any->unicode-vector s #f) (test s unicode-vector->bytes code-points) (test 0 bytes-utf-8-index s 0) - (test (bytes-length s) bytes-utf-8-index - (bytes-append s #"x") - (vector-length code-points)) - (if ((vector-length code-points) . > . 1) + (test 0 bytes-utf-8-index s 0 #f) + (test 0 bytes-utf-8-index s 0 #\x) + (test 0 bytes-utf-8-index s 0 #f 0) + (when (len . > . 1) + (test (char-utf-8-length c0) bytes-utf-8-index s 1 #f 0) + (test (char-utf-8-length c0) bytes-utf-8-index s 0 #f (char-utf-8-length c0))) + (test (char-utf-8-length c0) bytes-utf-8-index (bytes-append s #"x") 1 #f 0) + (test (char-utf-8-length c0) bytes-utf-8-index (bytes-append s #"x") 0 #f (char-utf-8-length c0)) + (test 0 bytes-utf-8-index s 0 #f 0 (bytes-length s)) + (test #f bytes-utf-8-index s 0 #f (bytes-length s)) + (test (bytes-length s) bytes-utf-8-index (bytes-append s #"x") len) + (if (len . > . 1) (begin - (test (integer->char (vector-ref code-points 0)) - bytes-utf-8-ref s 0) - (test (integer->char (vector-ref code-points 0)) - bytes-utf-8-ref s 0 #f) - (test (integer->char (vector-ref code-points 0)) - bytes-utf-8-ref s 0 #f 0) - (test (integer->char (vector-ref code-points 0)) - bytes-utf-8-ref s 0 #f 0 (bytes-length s)) + (test c0 bytes-utf-8-ref s 0) + (test c0 bytes-utf-8-ref s 0 #f) + (test c0 bytes-utf-8-ref s 0 #f 0) + (test c0 bytes-utf-8-ref s 0 #f 0 (bytes-length s)) (test (integer->char (vector-ref code-points (sub1 (vector-length code-points)))) bytes-utf-8-ref s (sub1 (vector-length code-points))) diff --git a/racket/src/io/string/convert.rkt b/racket/src/io/string/convert.rkt index df61d52d3e..df698e16b1 100644 --- a/racket/src/io/string/convert.rkt +++ b/racket/src/io/string/convert.rkt @@ -83,7 +83,7 @@ [(eq? state 'continues) (cond [(and get-index? ((+ start initial-used-bytes) . < . end)) - initial-used-bytes] + (+ initial-used-bytes start)] [else ;; Get one more byte (define str (and (not get-index?) (make-string 1))) @@ -98,7 +98,7 @@ (or (and (eq? state 'complete) (= got-chars 1)))) (if get-index? - initial-used-bytes + (+ initial-used-bytes start) (string-ref str 0))] [else #f])])] [else #f])) diff --git a/racket/src/racket/src/string.c b/racket/src/racket/src/string.c index 48a3ce1645..9ffd8d2091 100644 --- a/racket/src/racket/src/string.c +++ b/racket/src/racket/src/string.c @@ -664,7 +664,7 @@ scheme_init_string (Scheme_Startup_Env *env) SCHEME_PRIM_PROC_FLAGS(p) |= scheme_intern_prim_opt_flags(SCHEME_PRIM_AD_HOC_OPT); scheme_addto_prim_instance("bytes->immutable-bytes", p, env); - p = scheme_make_immed_prim(byte_string_utf8_index, "bytes-utf-8-index", 2, 4); + p = scheme_make_immed_prim(byte_string_utf8_index, "bytes-utf-8-index", 2, 5); /* Incorrect, since the result can be #f: SCHEME_PRIM_PROC_FLAGS(p) |= scheme_intern_prim_opt_flags(SCHEME_PRIM_PRODUCES_FIXNUM); */ scheme_addto_prim_instance("bytes-utf-8-index", p, env);