! Copyright (C) 2008 Daniel Ehrenberg.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays ascii combinators
-combinators.short-circuit hints kernel locals make math
+combinators.short-circuit hints kernel make math
math.order sbufs sequences sorting.insertion strings
unicode.data vectors ;
IN: unicode.normalize
: --final? ( str i -- ? )
2 + swap ?nth final? ;
-: imf, ( str i -- str i )
+: imf% ( str i -- str i )
[ tail-slice first3 jamo>hangul , ]
[ 3 + ] 2bi ;
-: im, ( str i -- str i )
+: im% ( str i -- str i )
[ tail-slice first2 final-base jamo>hangul , ]
[ 2 + ] 2bi ;
: compose-jamo ( str i -- str i )
2dup initial-medial? [
- 2dup --final? [ imf, ] [ im, ] if
+ 2dup --final? [ imf% ] [ im% ] if
] [ 2dup swap nth , 1 + ] if ;
: pass-combining ( str -- str i )
: try-noncombining ( state char -- state )
[ drop ] [ [ char>> ] dip combine-chars ] 2bi
- [ >>char to f >>last-class compose-iter ] when* ; inline
+ [ >>char to f >>last-class compose-iter ] when* ; inline recursive
: compose-iter ( state -- state )
dup current [