1 ! Copyright (C) 2008 Daniel Ehrenberg.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: unicode.data sequences sequences.next namespaces
4 sbufs make unicode.syntax unicode.normalize math hints
5 unicode.categories combinators unicode.syntax assocs
6 strings splitting kernel accessors unicode.breaks fry locals ;
11 : ch>lower ( ch -- lower ) simple-lower at-default ; inline
12 : ch>upper ( ch -- upper ) simple-upper at-default ; inline
13 : ch>title ( ch -- title ) simple-title at-default ; inline
16 SYMBOL: locale ! Just casing locale, or overall?
20 : split-subseq ( string sep -- strings )
21 [ dup ] swap '[ _ split1-slice swap ] [ ] produce nip ;
23 : replace ( old new str -- newstr )
24 [ split-subseq ] dip join ; inline
27 locale get { "tr" "az" } member? ;
29 : lithuanian? ( -- ? ) locale get "lt" = ;
31 : dot-over ( -- ch ) HEX: 307 ;
33 : lithuanian>upper ( string -- lower )
34 "i\u000307" "i" replace
35 "j\u000307" "j" replace ;
37 : mark-above? ( ch -- ? )
38 combining-class 230 = ;
40 : with-rest ( seq quot: ( seq -- seq ) -- seq )
41 [ unclip ] dip swap slip prefix ; inline
43 : add-dots ( seq -- seq )
46 [ CHAR: combining-dot-above prefix ] when
47 ] if-empty ] with-rest ; inline
49 : lithuanian>lower ( string -- lower )
50 "i" split add-dots "i" join
51 "j" split add-dots "i" join ; inline
53 : turk>upper ( string -- upper-i )
54 "i" "I\u000307" replace ; inline
56 : turk>lower ( string -- lower-i )
57 "I\u000307" "i" replace
58 "I" "\u000131" replace ; inline
60 : fix-sigma-end ( string -- string )
62 dup peek CHAR: greek-small-letter-sigma =
63 [ 1 head* CHAR: greek-small-letter-final-sigma suffix ] when
66 : sigma-map ( string -- string )
67 { CHAR: greek-capital-letter-sigma } split [ [
68 [ { CHAR: greek-small-letter-sigma } ] [
70 CHAR: greek-small-letter-final-sigma
71 CHAR: greek-small-letter-sigma ? prefix
73 ] map ] with-rest concat fix-sigma-end ; inline
75 : final-sigma ( string -- string )
76 CHAR: greek-capital-letter-sigma
77 over member? [ sigma-map ] when
80 :: map-case ( string string-quot char-quot -- case )
81 string length <sbuf> :> out
84 [ string-quot call out push-all ]
85 [ char-quot call out push ] ?if
86 ] each out "" like ; inline
90 : >lower ( string -- lower )
91 i-dot? [ turk>lower ] when final-sigma
92 [ lower>> ] [ ch>lower ] map-case ;
94 HINTS: >lower string ;
96 : >upper ( string -- upper )
97 i-dot? [ turk>upper ] when
98 [ upper>> ] [ ch>upper ] map-case ;
100 HINTS: >upper string ;
104 : (>title) ( string -- title )
105 i-dot? [ turk>upper ] when
106 [ title>> ] [ ch>title ] map-case ; inline
108 : title-word ( string -- title )
109 unclip 1string [ >lower ] [ (>title) ] bi* prepend ; inline
113 : >title ( string -- title )
114 final-sigma >words [ title-word ] map concat ;
116 HINTS: >title string ;
118 : >case-fold ( string -- fold )
121 : lower? ( string -- ? ) dup >lower = ;
123 : upper? ( string -- ? ) dup >upper = ;
125 : title? ( string -- ? ) dup >title = ;
127 : case-fold? ( string -- ? ) dup >case-fold = ;