From db876598ed41d39d1c33db967aa9db520cdad651 Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Thu, 19 Mar 2009 17:42:38 -0500 Subject: [PATCH] Fixing code-point-length --- core/io/encodings/utf8/utf8.factor | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/core/io/encodings/utf8/utf8.factor b/core/io/encodings/utf8/utf8.factor index 83ecc33b8e..4846b06f32 100755 --- a/core/io/encodings/utf8/utf8.factor +++ b/core/io/encodings/utf8/utf8.factor @@ -73,12 +73,14 @@ M: utf8 encode-char PRIVATE> : code-point-length ( n -- x ) - next-power-of-2 log2 { - { [ dup 0 7 between? ] [ 1 ] } - { [ dup 8 11 between? ] [ 2 ] } - { [ dup 12 16 between? ] [ 3 ] } - { [ dup 17 21 between? ] [ 4 ] } - } cond nip ; + dup zero? [ drop 1 ] [ + log2 { + { [ dup 0 6 between? ] [ 1 ] } + { [ dup 7 10 between? ] [ 2 ] } + { [ dup 11 15 between? ] [ 3 ] } + { [ dup 16 20 between? ] [ 4 ] } + } cond nip + ] if ; : code-point-offsets ( string -- indices ) 0 [ code-point-length + ] accumulate swap suffix ;