Merge branch 'master' of git://factorcode.org/git/factor

db4
Doug Coleman 2009-01-08 19:58:29 -06:00
commit 527fa0e484
3 changed files with 42 additions and 25 deletions

View File

@ -18,7 +18,7 @@ SYMBOL: locale ! Just casing locale, or overall?
<PRIVATE <PRIVATE
: split-subseq ( string sep -- strings ) : split-subseq ( string sep -- strings )
[ dup ] swap '[ _ split1 swap ] [ ] produce nip ; [ dup ] swap '[ _ split1-slice swap ] [ ] produce nip ;
: replace ( old new str -- newstr ) : replace ( old new str -- newstr )
[ split-subseq ] dip join ; [ split-subseq ] dip join ;

View File

@ -23,7 +23,7 @@ VALUE: properties
: combine-chars ( a b -- char/f ) combine-map hash2 ; : combine-chars ( a b -- char/f ) combine-map hash2 ;
: compatibility-entry ( char -- seq ) compatibility-map at ; : compatibility-entry ( char -- seq ) compatibility-map at ;
: combining-class ( char -- n ) class-map at ; : combining-class ( char -- n ) class-map at ;
: non-starter? ( char -- ? ) class-map key? ; : non-starter? ( char -- ? ) combining-class { 0 f } member? not ;
: name>char ( name -- char ) name-map at ; : name>char ( name -- char ) name-map at ;
: char>name ( char -- name ) name-map value-at ; : char>name ( char -- name ) name-map value-at ;
: property? ( char property -- ? ) properties at interval-key? ; : property? ( char property -- ? ) properties at interval-key? ;
@ -183,6 +183,13 @@ load-data {
[ process-category to: category-map ] [ process-category to: category-map ]
} cleave } cleave
: postprocess-class ( -- )
combine-map [ [ second ] map ] map concat
[ combining-class not ] filter
[ 0 swap class-map set-at ] each ;
postprocess-class
load-special-casing to: special-casing load-special-casing to: special-casing
load-properties to: properties load-properties to: properties

View File

@ -1,7 +1,7 @@
! Copyright (C) 2008 Daniel Ehrenberg. ! Copyright (C) 2008 Daniel Ehrenberg.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: sequences namespaces make unicode.data kernel math arrays USING: sequences namespaces make unicode.data kernel math arrays
locals sorting.insertion accessors assocs math.order ; locals sorting.insertion accessors assocs math.order combinators ;
IN: unicode.normalize IN: unicode.normalize
<PRIVATE <PRIVATE
@ -65,26 +65,30 @@ CONSTANT: final-count 28
over [ non-starter? not ] find-last-from drop ?1+ reorder-next 2drop ; over [ non-starter? not ] find-last-from drop ?1+ reorder-next 2drop ;
:: decompose ( string quot -- decomposed ) :: decompose ( string quot -- decomposed )
! When there are 8 and 32-bit strings, this'll be [
! equivalent to clone on 8 and the contents of the last string [
! main quotation on 32. dup hangul? [ hangul>jamo % ]
string [ 127 < ] all? [ string ] [ [ dup quot call [ % ] [ , ] ?if ] if
[ ] each
string [ ] "" make
dup hangul? [ hangul>jamo % ] dup reorder ;
[ dup quot call [ % ] [ , ] ?if ] if
] each : with-string ( str quot -- str )
] "" make over aux>> [ call ] [ drop ] if ; inline
dup reorder
] if ; inline : (nfd) ( string -- nfd )
[ canonical-entry ] decompose ;
: (nfkd) ( string -- nfkd )
[ compatibility-entry ] decompose ;
PRIVATE> PRIVATE>
: nfd ( string -- nfd ) : nfd ( string -- nfd )
[ canonical-entry ] decompose ; [ (nfd) ] with-string ;
: nfkd ( string -- nfkd ) : nfkd ( string -- nfkd )
[ compatibility-entry ] decompose ; [ (nfkd) ] with-string ;
: string-append ( s1 s2 -- string ) : string-append ( s1 s2 -- string )
[ append ] keep [ append ] keep
@ -138,20 +142,26 @@ DEFER: compose-iter
: compose-iter ( last-class -- ) : compose-iter ( last-class -- )
current [ current [
dup combining-class dup combining-class {
[ try-compose to compose-iter ] { f [ 2drop ] }
[ swap [ drop ] [ try-noncombining ] if ] if* { 0 [ swap [ drop ] [ try-noncombining ] if ] }
[ try-compose to compose-iter ]
} case
] [ drop ] if* ; ] [ drop ] if* ;
: ?new-after ( -- ) : ?new-after ( -- )
after [ dup empty? [ drop SBUF" " clone ] unless ] change ; after [ dup empty? [ drop SBUF" " clone ] unless ] change ;
: compose-combining ( ch -- )
char set to ?new-after
f compose-iter
char get , after get % ;
: (compose) ( -- ) : (compose) ( -- )
current [ current [
dup jamo? [ drop compose-jamo ] [ dup jamo? [ drop compose-jamo ] [
char set to ?new-after 1 get-str combining-class
f compose-iter [ compose-combining ] [ , to ] if
char get , after get %
] if (compose) ] if (compose)
] when* ; ] when* ;
@ -166,7 +176,7 @@ DEFER: compose-iter
PRIVATE> PRIVATE>
: nfc ( string -- nfc ) : nfc ( string -- nfc )
nfd combine ; [ (nfd) combine ] with-string ;
: nfkc ( string -- nfkc ) : nfkc ( string -- nfkc )
nfkd combine ; [ (nfkd) combine ] with-string ;