2008-10-05 19:36:56 -04:00
|
|
|
! Copyright (C) 2008 Daniel Ehrenberg.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2009-01-08 23:49:24 -05:00
|
|
|
USING: unicode.data sequences sequences.next namespaces make unicode.syntax
|
2009-01-08 16:00:59 -05:00
|
|
|
unicode.normalize math unicode.categories combinators unicode.syntax
|
|
|
|
assocs strings splitting kernel accessors unicode.breaks fry ;
|
2008-01-09 14:44:07 -05:00
|
|
|
IN: unicode.case
|
|
|
|
|
2009-01-07 18:59:01 -05:00
|
|
|
<PRIVATE
|
2008-12-03 09:46:16 -05:00
|
|
|
: at-default ( key assoc -- value/key ) [ at ] [ drop ] 2bi or ;
|
2008-04-05 08:57:26 -04:00
|
|
|
|
2008-01-09 14:44:07 -05:00
|
|
|
: ch>lower ( ch -- lower ) simple-lower at-default ;
|
|
|
|
: ch>upper ( ch -- upper ) simple-upper at-default ;
|
|
|
|
: ch>title ( ch -- title ) simple-title at-default ;
|
2009-01-08 20:07:46 -05:00
|
|
|
PRIVATE>
|
2009-01-07 22:45:33 -05:00
|
|
|
|
2008-01-09 14:44:07 -05:00
|
|
|
SYMBOL: locale ! Just casing locale, or overall?
|
2009-01-07 22:45:33 -05:00
|
|
|
|
2009-01-07 18:59:01 -05:00
|
|
|
<PRIVATE
|
2009-01-08 16:00:59 -05:00
|
|
|
|
|
|
|
: split-subseq ( string sep -- strings )
|
2009-01-08 18:56:52 -05:00
|
|
|
[ dup ] swap '[ _ split1-slice swap ] [ ] produce nip ;
|
2009-01-08 16:00:59 -05:00
|
|
|
|
|
|
|
: replace ( old new str -- newstr )
|
|
|
|
[ split-subseq ] dip join ;
|
|
|
|
|
2008-01-09 14:44:07 -05:00
|
|
|
: i-dot? ( -- ? )
|
|
|
|
locale get { "tr" "az" } member? ;
|
|
|
|
|
|
|
|
: lithuanian? ( -- ? ) locale get "lt" = ;
|
|
|
|
|
2008-02-01 16:00:02 -05:00
|
|
|
: dot-over ( -- ch ) HEX: 307 ;
|
2008-01-09 14:44:07 -05:00
|
|
|
|
|
|
|
: lithuanian>upper ( string -- lower )
|
2009-01-08 16:00:59 -05:00
|
|
|
"i\u000307" "i" replace
|
|
|
|
"j\u000307" "j" replace ;
|
2008-01-09 14:44:07 -05:00
|
|
|
|
|
|
|
: mark-above? ( ch -- ? )
|
|
|
|
combining-class 230 = ;
|
|
|
|
|
2009-01-08 16:00:59 -05:00
|
|
|
: with-rest ( seq quot: ( seq -- seq ) -- seq )
|
|
|
|
[ unclip ] dip swap slip prefix ; inline
|
2008-01-09 14:44:07 -05:00
|
|
|
|
2009-01-08 16:00:59 -05:00
|
|
|
: add-dots ( seq -- seq )
|
|
|
|
[ [ "" ] [
|
|
|
|
dup first mark-above?
|
|
|
|
[ CHAR: combining-dot-above prefix ] when
|
|
|
|
] if-empty ] with-rest ;
|
2008-01-09 14:44:07 -05:00
|
|
|
|
2009-01-08 16:00:59 -05:00
|
|
|
: lithuanian>lower ( string -- lower )
|
|
|
|
"i" split add-dots "i" join
|
|
|
|
"j" split add-dots "i" join ;
|
2008-01-09 14:44:07 -05:00
|
|
|
|
|
|
|
: turk>upper ( string -- upper-i )
|
2009-01-08 16:00:59 -05:00
|
|
|
"i" "I\u000307" replace ;
|
2008-01-09 14:44:07 -05:00
|
|
|
|
|
|
|
: turk>lower ( string -- lower-i )
|
2009-01-08 16:00:59 -05:00
|
|
|
"I\u000307" "i" replace
|
|
|
|
"I" "\u000131" replace ;
|
2008-01-09 14:44:07 -05:00
|
|
|
|
2009-01-08 16:00:59 -05:00
|
|
|
: fix-sigma-end ( string -- string )
|
|
|
|
[ "" ] [
|
|
|
|
dup peek CHAR: greek-small-letter-sigma =
|
|
|
|
[ 1 head* CHAR: greek-small-letter-final-sigma suffix ] when
|
|
|
|
] if-empty ;
|
2008-01-09 14:44:07 -05:00
|
|
|
|
|
|
|
: sigma-map ( string -- string )
|
2009-01-08 16:00:59 -05:00
|
|
|
{ CHAR: greek-capital-letter-sigma } split [ [
|
|
|
|
[ { CHAR: greek-small-letter-sigma } ] [
|
|
|
|
dup first uncased?
|
|
|
|
CHAR: greek-small-letter-final-sigma
|
|
|
|
CHAR: greek-small-letter-sigma ? prefix
|
|
|
|
] if-empty
|
|
|
|
] map ] with-rest concat fix-sigma-end ;
|
2008-01-09 14:44:07 -05:00
|
|
|
|
|
|
|
: final-sigma ( string -- string )
|
2009-01-08 16:00:59 -05:00
|
|
|
CHAR: greek-capital-letter-sigma
|
|
|
|
over member? [ sigma-map ] when ;
|
2008-01-09 14:44:07 -05:00
|
|
|
|
|
|
|
: map-case ( string string-quot char-quot -- case )
|
|
|
|
[
|
2008-08-23 23:35:29 -04:00
|
|
|
[
|
|
|
|
[ dup special-casing at ] 2dip
|
|
|
|
[ [ % ] compose ] [ [ , ] compose ] bi* ?if
|
|
|
|
] 2curry each
|
2008-02-01 19:36:20 -05:00
|
|
|
] "" make ; inline
|
2009-01-08 00:54:19 -05:00
|
|
|
|
2009-01-08 16:00:59 -05:00
|
|
|
PRIVATE>
|
|
|
|
|
|
|
|
: >lower ( string -- lower )
|
|
|
|
i-dot? [ turk>lower ] when final-sigma
|
2009-01-08 00:54:19 -05:00
|
|
|
[ lower>> ] [ ch>lower ] map-case ;
|
|
|
|
|
2009-01-08 16:00:59 -05:00
|
|
|
: >upper ( string -- upper )
|
|
|
|
i-dot? [ turk>upper ] when
|
|
|
|
[ upper>> ] [ ch>upper ] map-case ;
|
|
|
|
|
|
|
|
<PRIVATE
|
|
|
|
|
2009-01-08 00:54:19 -05:00
|
|
|
: (>title) ( string -- title )
|
2009-01-08 16:00:59 -05:00
|
|
|
i-dot? [ turk>upper ] when
|
2009-01-08 00:54:19 -05:00
|
|
|
[ title>> ] [ ch>title ] map-case ;
|
|
|
|
|
|
|
|
: title-word ( string -- title )
|
2009-01-08 16:00:59 -05:00
|
|
|
unclip 1string [ >lower ] [ (>title) ] bi* prepend ;
|
2009-01-08 00:54:19 -05:00
|
|
|
|
2009-01-07 18:59:01 -05:00
|
|
|
PRIVATE>
|
2009-01-08 00:54:19 -05:00
|
|
|
|
2008-01-09 14:44:07 -05:00
|
|
|
: >title ( string -- title )
|
2009-01-08 00:54:19 -05:00
|
|
|
final-sigma >words [ title-word ] map concat ;
|
2008-01-09 14:44:07 -05:00
|
|
|
|
|
|
|
: >case-fold ( string -- fold )
|
|
|
|
>upper >lower ;
|
|
|
|
|
2008-12-07 02:36:10 -05:00
|
|
|
: lower? ( string -- ? ) dup >lower = ;
|
|
|
|
|
|
|
|
: upper? ( string -- ? ) dup >upper = ;
|
|
|
|
|
|
|
|
: title? ( string -- ? ) dup >title = ;
|
|
|
|
|
|
|
|
: case-fold? ( string -- ? ) dup >case-fold = ;
|