]> gitweb.factorcode.org Git - factor.git/blob - basis/unicode/case/case.factor
Removing unused private words. See #132.
[factor.git] / basis / unicode / case / case.factor
1 ! Copyright (C) 2008, 2009 Daniel Ehrenberg.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: unicode.data sequences namespaces
4 sbufs make unicode.normalize math hints
5 unicode.categories combinators assocs combinators.short-circuit
6 strings splitting kernel accessors unicode.breaks fry locals ;
7 QUALIFIED: ascii
8 IN: unicode.case
9
10 SYMBOL: locale ! Just casing locale, or overall?
11
12 <PRIVATE
13
14 : split-subseq ( string sep -- strings )
15     [ dup ] swap '[ _ split1-slice swap ] produce nip ;
16
17 : replace ( old new str -- newstr )
18     [ split-subseq ] dip join ; inline
19
20 : i-dot? ( -- ? )
21     locale get { "tr" "az" } member? ;
22
23 : lt? ( -- ? )
24     locale get "lt" = ;
25
26 : lithuanian? ( -- ? ) locale get "lt" = ;
27
28 : lithuanian>upper ( string -- lower )
29     "i\u000307" "i" replace
30     "j\u000307" "j" replace ;
31
32 : mark-above? ( ch -- ? )
33     combining-class 230 = ;
34
35 :: with-rest ( seq quot: ( seq -- seq ) -- seq )
36     seq unclip quot dip prefix ; inline
37
38 : add-dots ( seq -- seq )
39     [ [ { } ] [
40         [
41             dup first
42             { [ mark-above? ] [ CHAR: combining-ogonek = ] } 1||
43             [ CHAR: combining-dot-above prefix ] when
44         ] map
45     ] if-empty ] with-rest ; inline
46
47 : lithuanian>lower ( string -- lower )
48     "I" split add-dots "I" join
49     "J" split add-dots "J" join ; inline
50
51 : turk>upper ( string -- upper-i )
52     "i" "I\u000307" replace ; inline
53
54 : turk>lower ( string -- lower-i )
55     "I\u000307" "i" replace
56     "I" "\u000131" replace ; inline
57
58 : fix-sigma-end ( string -- string )
59     [ "" ] [
60         dup last CHAR: greek-small-letter-sigma =
61         [ 1 head* CHAR: greek-small-letter-final-sigma suffix ] when
62     ] if-empty ; inline
63
64 : sigma-map ( string -- string )
65     { CHAR: greek-capital-letter-sigma } split [ [
66         [ { CHAR: greek-small-letter-sigma } ] [
67             dup first uncased?
68             CHAR: greek-small-letter-final-sigma
69             CHAR: greek-small-letter-sigma ? prefix
70         ] if-empty
71     ] map ] with-rest concat fix-sigma-end ; inline
72
73 : final-sigma ( string -- string )
74     CHAR: greek-capital-letter-sigma
75     over member? [ sigma-map ] when
76     "" like ; inline
77
78 :: map-case ( string string-quot char-quot -- case )
79     string length <sbuf> :> out
80     string [
81         dup special-case
82         [ string-quot call out push-all ]
83         [ char-quot call out push ] ?if
84     ] each out "" like ; inline
85
86 PRIVATE>
87
88 : >lower ( string -- lower )
89     i-dot? [ turk>lower ] when
90     lt? [ lithuanian>lower ] when
91     final-sigma
92     [ lower>> ] [ ch>lower ] map-case ;
93
94 HINTS: >lower string ;
95
96 : >upper ( string -- upper )
97     i-dot? [ turk>upper ] when
98     lt? [ lithuanian>upper ] when
99     [ upper>> ] [ ch>upper ] map-case ;
100
101 HINTS: >upper string ;
102
103 <PRIVATE
104
105 : (>title) ( string -- title )
106     i-dot? [ turk>upper ] when
107     lt? [ lithuanian>upper ] when
108     [ title>> ] [ ch>title ] map-case ; inline
109
110 PRIVATE>
111
112 : capitalize ( string -- title )
113     unclip 1string [ >lower ] [ (>title) ] bi* prepend ; inline
114
115 : >title ( string -- title )
116     final-sigma >words [ capitalize ] map concat ;
117
118 HINTS: >title string ;
119
120 : >case-fold ( string -- fold )
121     >upper >lower ;
122
123 : lower? ( string -- ? ) dup >lower = ;
124
125 : upper? ( string -- ? ) dup >upper = ;
126
127 : title? ( string -- ? ) dup >title = ;
128
129 : case-fold? ( string -- ? ) dup >case-fold = ;