1 ! Copyright (C) 2008, 2009 Daniel Ehrenberg.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: combinators.short-circuit kernel namespaces sbufs
4 sequences splitting unicode.categories unicode.data ;
8 SYMBOL: locale ! Just casing locale, or overall?
12 : i-dot? ( locale -- ? )
13 { "tr" "az" } member? ; inline
15 : lithuanian? ( locale -- ? ) "lt" = ; inline
17 : lithuanian>upper ( string -- lower )
18 "i\u000307" "i" replace
19 "j\u000307" "j" replace ;
21 : mark-above? ( ch -- ? )
22 combining-class 230 = ;
24 :: with-rest ( seq quot: ( seq -- seq ) -- seq )
25 seq unclip quot dip prefix ; inline
27 : add-dots ( seq -- seq )
31 { [ mark-above? ] [ CHAR: combining-ogonek = ] } 1||
32 [ CHAR: combining-dot-above prefix ] when
34 ] if-empty ] with-rest ; inline
36 : lithuanian>lower ( string -- lower )
37 "I" split add-dots "I" join
38 "J" split add-dots "J" join ; inline
40 : turk>upper ( string -- upper-i )
41 "i" "I\u000307" replace ; inline
43 : turk>lower ( string -- lower-i )
44 "I\u000307" "i" replace
45 "I" "\u000131" replace ; inline
47 : fix-sigma-end ( string -- string )
49 dup last CHAR: greek-small-letter-sigma =
50 [ but-last CHAR: greek-small-letter-final-sigma suffix ] when
53 ! this duplicate unicode to prevent dependencies
54 CATEGORY-NOT: (uncased) Lu Ll Lt Lm Mn Me ;
56 : sigma-map ( string -- string )
57 { CHAR: greek-capital-letter-sigma } split [ [
58 [ { CHAR: greek-small-letter-sigma } ] [
60 CHAR: greek-small-letter-final-sigma
61 CHAR: greek-small-letter-sigma ? prefix
63 ] map ] with-rest concat fix-sigma-end ; inline
65 : final-sigma ( string -- string )
66 CHAR: greek-capital-letter-sigma
67 over member? [ sigma-map ] when
70 :: map-case ( string string-quot char-quot -- case )
71 string length <sbuf> :> out
74 [ string-quot call out push-all ]
75 [ char-quot call out push ] ?if
76 ] each out "" like ; inline
78 : locale>lower ( string -- string' )
80 [ i-dot? [ turk>lower ] when ]
81 [ lithuanian? [ lithuanian>lower ] when ] bi ;
83 : locale>upper ( string -- string' )
85 [ i-dot? [ turk>upper ] when ]
86 [ lithuanian? [ lithuanian>upper ] when ] bi ;