[ { BIN: 11110101 BIN: 10111111 BIN: 10000000 BIN: 10111111 BIN: 11101111 BIN: 10000000 BIN: 10111111 BIN: 11011111 BIN: 10000000 CHAR: x } ]
[ { BIN: 101111111000000111111 BIN: 1111000000111111 BIN: 11111000000 CHAR: x } encode-utf8-w/stream ] unit-test
+
+[ 3 ] [ 1 "日本語" >utf8-index ] unit-test
+[ 3 ] [ 9 "日本語" utf8-index> ] unit-test
! Copyright (C) 2006, 2008 Daniel Ehrenberg.
! See http://factorcode.org/license.txt for BSD license.
USING: math math.order kernel sequences sbufs vectors growable io
-continuations namespaces io.encodings combinators strings
-binary-search ;
+continuations namespaces io.encodings combinators strings ;
IN: io.encodings.utf8
! Decoding UTF-8
0 [ code-point-length + ] accumulate swap suffix ;
: utf8-index> ( n string -- n' )
- code-point-offsets natural-search drop ;
+ code-point-offsets [ <= ] with find drop ;
: >utf8-index ( n string -- n' )
code-point-offsets nth ;
\ No newline at end of file