]> gitweb.factorcode.org Git - factor.git/commitdiff
Case conversion title case fixed
authorDaniel Ehrenberg <littledan@Macintosh-103.local>
Thu, 8 Jan 2009 05:54:19 +0000 (23:54 -0600)
committerDaniel Ehrenberg <littledan@Macintosh-103.local>
Thu, 8 Jan 2009 05:54:19 +0000 (23:54 -0600)
basis/unicode/breaks/breaks.factor
basis/unicode/case/case-tests.factor
basis/unicode/case/case.factor
basis/unicode/collation/collation-tests.factor
basis/unicode/normalize/normalize.factor

index b85e8879e1ce53fd7adb56d68b12527ffa8a4d71..1d2f82175066eab771c8f1c11e11803edd160664 100644 (file)
@@ -3,7 +3,7 @@
 USING: combinators.short-circuit unicode.categories kernel math
 combinators splitting sequences math.parser io.files io assocs
 arrays namespaces make math.ranges unicode.normalize.private values
-io.encodings.ascii unicode.syntax unicode.data compiler.units
+io.encodings.ascii unicode.syntax unicode.data compiler.units fry
 alien.syntax sets accessors interval-maps memoize locals words ;
 IN: unicode.breaks
 
@@ -111,14 +111,9 @@ PRIVATE>
 
 <PRIVATE
 
-:: (>pieces) ( str quot -- )
-    str [
-        dup quot call cut-slice
-        swap , quot (>pieces)
-    ] unless-empty ; inline recursive
-
-: >pieces ( str quot -- graphemes )
-    [ (>pieces) ] { } make ; inline
+: >pieces ( str quot: ( str -- i ) -- graphemes )
+    [ dup empty? not ] swap '[ dup @ cut-slice swap ]
+    [ ] produce nip ; inline
 
 PRIVATE>
 
index 0083e49672f79dfe2bdc76e962e85319aad855b5..f9d304e05c1d79e1e5b2535fd6bc43af5cc1a858 100644 (file)
@@ -4,7 +4,7 @@ USING: unicode.case tools.test namespaces ;
 \ >lower must-infer
 \ >title must-infer
 
-[ "Hello How Are You? I'M Good" ] [ "hEllo how ARE yOU? I'm good" >title ] unit-test
+[ "Hello How Are You? I'm Good" ] [ "hEllo how ARE yOU? I'm good" >title ] unit-test
 [ "FUSS" ] [ "Fu\u0000DF" >upper ] unit-test
 [ "\u0003C3\u0003C2" ] [ "\u0003A3\u0003A3" >lower ] unit-test
 [ t ] [ "hello how are you?" lower? ] unit-test
index 7e61831f36d0ca536839e9ee7205f4affbf72c18..5d103e2dd070244d12bacfd38a4741a36c0e91c2 100644 (file)
@@ -2,7 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: unicode.data sequences sequences.next namespaces make
 unicode.normalize math unicode.categories combinators
-assocs strings splitting kernel accessors ;
+assocs strings splitting kernel accessors unicode.breaks ;
 IN: unicode.case
 
 <PRIVATE
@@ -82,23 +82,30 @@ SYMBOL: locale ! Just casing locale, or overall?
             [ [ % ] compose ] [ [ , ] compose ] bi* ?if
         ] 2curry each
     ] "" make ; inline
+
+: (>lower) ( string -- lower )
+    [ lower>> ] [ ch>lower ] map-case ;
+
+: (>title) ( string -- title )
+    [ title>> ] [ ch>title ] map-case ;
+
+: (>upper) ( string -- upper )
+    [ upper>> ] [ ch>upper ] map-case ;
+
+: title-word ( string -- title )
+    unclip 1string [ (>lower) ] [ (>title) ] bi* prepend ;
+
 PRIVATE>
+
 : >lower ( string -- lower )
     i-dot? [ turk>lower ] when
-    final-sigma [ lower>> ] [ ch>lower ] map-case ;
+    final-sigma (>lower) ;
 
 : >upper ( string -- upper )
-    i-dot? [ turk>upper ] when
-    [ upper>> ] [ ch>upper ] map-case ;
+    i-dot? [ turk>upper ] when (>upper) ;
 
 : >title ( string -- title )
-    final-sigma
-    CHAR: \s swap
-    [ tuck word-boundary swapd
-        [ title>> ] [ lower>> ] if ]
-    [ tuck word-boundary swapd 
-        [ ch>title ] [ ch>lower ] if ]
-    map-case nip ;
+    final-sigma >words [ title-word ] map concat ;
 
 : >case-fold ( string -- fold )
     >upper >lower ;
index be6af2d9207cab624a592765fe4fb5b44e6701e4..d3d0b8199d5f3b1eee0757b6c17d98f4e24fa47c 100644 (file)
@@ -1,6 +1,6 @@
 USING: io io.files splitting grouping unicode.collation\r
 sequences kernel io.encodings.utf8 math.parser math.order\r
-tools.test assocs io.streams.null words ;\r
+tools.test assocs words ;\r
 IN: unicode.collation.tests\r
 \r
 : parse-test ( -- strings )\r
@@ -25,4 +25,4 @@ IN: unicode.collation.tests
 unit-test\r
 \r
 parse-test 2 <clumps>\r
-[ [ test-two ] assoc-each ] with-null-writer\r
+[ test-two ] assoc-each\r
index f13eb0759498ed110a5702a51bebeaba7d6f72e4..58ce412a2e4455f00a16a5349dda0b73ee0a7e4b 100644 (file)
@@ -155,7 +155,7 @@ DEFER: compose-iter
         ] if (compose)
     ] when* ;
 
-: compose ( str -- comp )
+: combine ( str -- comp )
     [
         main-str set
         0 ind set
@@ -166,7 +166,7 @@ DEFER: compose-iter
 PRIVATE>
 
 : nfc ( string -- nfc )
-    nfd compose ;
+    nfd combine ;
 
 : nfkc ( string -- nfkc )
-    nfkd compose ;
+    nfkd combine ;