{ $values { "str" "a string" } { "upper" "a string" } }\r
{ $description "Converts an ASCII string to upper case." } ;\r
\r
+HELP: >title\r
+{ $values { "string" "a string" } { "title" "a string" } }\r
+{ $description "Converts a string to title case." } ;\r
+\r
+HELP: >words\r
+{ $values { "str" "a string" } { "words" "an array of strings" } }\r
+{ $description "Divides the string up into words." } ;\r
+\r
ARTICLE: "ascii" "ASCII"\r
"The " { $vocab-link "ascii" } " vocabulary implements support for the legacy ASCII character set. Most applications should use " { $link "unicode" } " instead."\r
$nl\r
ch>upper\r
>lower\r
>upper\r
+ >title\r
} ;\r
\r
ABOUT: "ascii"\r
-USING: ascii tools.test sequences kernel math ;
+USING: ascii tools.test sequences kernel math strings ;
+
IN: ascii.tests
[ t ] [ CHAR: a letter? ] unit-test
[ "HELLO HOW ARE YOU?" ] [ "hellO hOw arE YOU?" >upper ] unit-test
[ "i'm good thx bai" ] [ "I'm Good THX bai" >lower ] unit-test
+[ "Hello How Are You?" ] [ "hEllo how ARE yOU?" >title ] unit-test
+[ { " " "Hello" " " "World" } ] [ " Hello World" >words [ >string ] map ] unit-test
! Copyright (C) 2005, 2009 Slava Pestov.\r
! See http://factorcode.org/license.txt for BSD license.\r
-USING: kernel math math.order sequences strings\r
-combinators.short-circuit hints ;\r
+USING: combinators.short-circuit hints kernel math math.order\r
+sequences splitting.monotonic strings ;\r
IN: ascii\r
\r
: ascii? ( ch -- ? ) 0 127 between? ; inline\r
: >lower ( str -- lower ) [ ch>lower ] map ;\r
: ch>upper ( ch -- upper ) dup letter? [ 0x20 - ] when ; inline\r
: >upper ( str -- upper ) [ ch>upper ] map ;\r
+: >words ( str -- words ) [ [ blank? ] bi@ = ] slice monotonic-slice ;\r
+: capitalize ( str -- title ) unclip [ >lower ] [ ch>upper ] bi* prefix ;\r
+: >title ( str -- title ) >words [ capitalize ] map concat ;\r
\r
HINTS: >lower string ;\r
HINTS: >upper string ;\r
+\r