asTitlecase
authorClaus Gittinger <cg@exept.de>
Mon, 01 Mar 2004 22:17:55 +0100
changeset 8027 4536f92bdbb4
parent 8026 96cc838078ba
child 8028 4fecc8242a64
asTitlecase
CharacterArray.st
--- a/CharacterArray.st	Mon Mar 01 22:13:53 2004 +0100
+++ b/CharacterArray.st	Mon Mar 01 22:17:55 2004 +0100
@@ -3577,6 +3577,39 @@
     "Created: 12.5.1996 / 10:41:14 / cg"
 !
 
+asTitlecase
+    "return a version of the receiver, where the first character is converted to titlecase,
+     and everything else to lowercase.
+     See the comment in Character on what titlecase is."
+
+    |newStr c bitsPerCharacter
+     mySize "{ Class: SmallInteger }" |
+
+    mySize := self size.
+    newStr := self species new:mySize.
+    bitsPerCharacter := newStr bitsPerCharacter.
+
+    1 to:mySize do:[:i |
+        i == 1 ifTrue:[
+            c := (self at:i) asTitlecase.
+        ] ifFalse:[
+            c := (self at:i) asLowercase.
+        ].
+        c bitsPerCharacter > bitsPerCharacter ifTrue:[
+            newStr := c stringSpecies fromString:newStr.    
+        ].
+        newStr at:i put:c
+    ].
+    ^ newStr
+
+    "
+     'helloWorld' asTitlecase    
+     'HelloWorld' asTitlecase   
+     'HELLOWORLD' asTitlecase   
+     'helloworld' asTitlecase   
+    "
+!
+
 asTitlecaseFirst
     "return a version of the receiver, where the first character is converted to titlecase.
      Titlecase is much like uppercase for most characters, with the exception of some combined
@@ -6298,7 +6331,7 @@
 !CharacterArray class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.290 2004-03-01 21:13:46 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.291 2004-03-01 21:17:55 cg Exp $'
 ! !
 
 CharacterArray initialize!