CharacterArray.st
changeset 11525 d76e654e24bd
parent 11524 8742d67d9296
child 11565 71a4edaa21e9
--- a/CharacterArray.st	Mon Feb 09 00:48:17 2009 +0100
+++ b/CharacterArray.st	Wed Feb 11 12:24:41 2009 +0100
@@ -674,6 +674,199 @@
     ^ self == CharacterArray
 ! !
 
+!CharacterArray methodsFor:'AEG-Extensions'!
+
+asCollectionOfSubstringsSeparatedBy:aCharacter exceptIn:ch
+    "return a collection containing the lines (separated by aCharacter) 
+     of the receiver. If aCharacter occurs multiple times in a row, 
+     the result will contain empty strings."
+
+    |lines myClass except i c
+     startIndex    "{ Class:SmallInteger }"
+     stopIndex     "{ Class:SmallInteger }" |
+
+    lines := OrderedCollection new.
+    myClass := self species.
+
+    startIndex := 1.
+    except := false.
+    [
+	i := startIndex-1.
+	[
+	    i := i+1.
+	    c := self at:i.
+	    c = ch ifTrue:[ except := except not. ].
+	    i < self size and:[except or:[c ~= aCharacter]]
+	]whileTrue.
+
+	c = aCharacter ifTrue:[
+	    stopIndex := i -1.
+	] ifFalse: [
+	    stopIndex := i.
+	].
+	(stopIndex < startIndex) ifTrue: [
+	    lines add:(myClass new:0)
+	] ifFalse: [
+	    lines add:(self copyFrom:startIndex to:stopIndex)
+	].
+	startIndex := stopIndex + 2.
+	startIndex <= self size
+    ]whileTrue.
+    ^ lines
+
+    "
+     'asd''f;d''dd;s' asCollectionOfSubstringsSeparatedBy:$; exceptIn:$' 
+    "
+!
+
+asLowercaseLast
+    "return a copy of myself where the last character is
+     converted to lowercase."
+
+    |newString sz|
+
+    sz := self size.
+    newString := self copyFrom:1 to:sz.
+    sz > 0 ifTrue:[
+	newString at:sz put:(newString at:sz) asLowercase
+    ].
+    ^ newString
+
+    "
+     'HelloWorld' asLowercase   
+     'HelloWorlD' asLowercaseLast   
+    "
+!
+
+asNegNumber
+
+
+    (self size == 1 and:[self first == $-]) ifTrue:[
+	^0
+    ].
+!
+
+asStringsWidth:aInteger for:aFont
+"^<OrderedCollection of:String>"
+"simple formating to the column width 'aInteger'"
+
+    |lines strings start lastSeparator width width2|
+
+    (aFont widthOf:self) > aInteger ifFalse:[^OrderedCollection with:self].
+    strings := OrderedCollection new.
+    lastSeparator := 0.
+    start := 1.
+    width := width2 := 0.
+    self keysAndValuesDo:[:pos :ch|
+	width := width + (aFont widthOf:ch).
+	(width > aInteger and:[start<=lastSeparator]) ifTrue:[
+	    strings add:(self copyFrom: start to:lastSeparator).
+	    start := lastSeparator+1.
+	    width := width-width2.
+	].
+	ch isSeparator ifTrue:[
+	    lastSeparator := pos.
+	    width2 := width.
+	].
+    ].
+    strings add:(self copyFrom: start).    
+    ^strings
+
+"
+'This class is provided to make porting of existing ST-80 applications easier. Instances can be used to control the geometry of a subview, within its superview. Like a layoutOrigin, it controls the origin of a component by given fraction and offset dimensions; in addition, the bottom-right corner is also controlled by corresponding values. Therefore, the components preferredExtent is ignored.'
+asStringsWidth:120 for:DPUDisplayObject nameFont
+
+"
+!
+
+isLowercaseFirst
+
+
+    self size = 0 ifTrue:[^false].
+    ^self first isLowercase
+
+    "
+     'helloWorld' isLowercaseFirst    
+     'HelloWorld' isLowercaseFirst    
+    "
+
+
+!
+
+isUppercaseFirst
+
+
+    self size = 0 ifTrue:[^false].
+    ^self first isUppercase
+
+    "
+     'helloWorld' isUppercaseFirst 
+     'HelloWorld' isUppercaseFirst    
+    "
+
+!
+
+withQuotesDoubled
+    "return the raw storeString of myself"
+
+
+    |s|
+    s := OrderedCollection new.
+    self do:[:thisChar |
+	(thisChar == $') ifTrue:[
+	    s add: thisChar
+	].
+	s add: thisChar
+    ].
+    ^s asString
+
+
+
+!
+
+withQuotesReduced
+
+
+    |s found|
+    found := false.
+    s := OrderedCollection new.   
+    self do:[:thisChar |
+	(thisChar == $') ifTrue:[
+	    found ifFalse:[
+	       s add: thisChar.
+	       found := true.
+	    ]
+	] ifFalse:[
+	    s add: thisChar.
+	    found := false.
+	].
+    ].
+    ^s asString
+
+
+"
+'e''f' withQuotesReduced  
+"
+!
+
+withoutAllSpaces
+
+    |col string|
+
+    col := self asCollectionOfWords.
+    string := String new.
+    col do:[:el|
+       string := string,el
+    ].
+    ^string
+
+    "
+     'hello wwww'  withoutAllSpaces   
+    "
+
+    "Modified: / 18.7.1998 / 22:53:08 / cg"
+! !
+
 !CharacterArray methodsFor:'Compatibility-ANSI'!
 
 addLineDelimiters
@@ -1459,7 +1652,6 @@
     ^ true
 ! !
 
-
 !CharacterArray methodsFor:'character searching'!
 
 includesMatchCharacters
@@ -2270,14 +2462,15 @@
 
     |newString firstChar firstCharAsLowercase|
 
+    self isEmpty ifTrue:[^ self].
     firstChar := (self at:1).
     firstCharAsLowercase := firstChar asLowercase.
     firstChar == firstCharAsLowercase ifTrue:[ ^ self].
 
     firstCharAsLowercase bitsPerCharacter > self bitsPerCharacter ifTrue:[
-	newString := firstCharAsLowercase stringSpecies fromString:self.
+        newString := firstCharAsLowercase stringSpecies fromString:self.
     ] ifFalse:[
-	newString := self stringSpecies fromString:self.
+        newString := self stringSpecies fromString:self.
     ].
     newString at:1 put:firstCharAsLowercase.
     ^ newString
@@ -4110,7 +4303,6 @@
     "Modified: 17.4.1997 / 12:50:23 / cg"
 ! !
 
-
 !CharacterArray methodsFor:'special string converting'!
 
 expandPlaceholdersWith:argArrayOrDictionary
@@ -5225,23 +5417,6 @@
     "Modified: / 13-09-2006 / 11:35:15 / cg"
 !
 
-isUppercaseFirst
-    "true if my first character is uppercase"
-
-    self isEmpty ifTrue:[^ false].
-    ^ self first isUppercase
-
-    "
-     '' isUppercaseFirst
-     'a' isUppercaseFirst
-     'A' isUppercaseFirst
-     'aaaaa' isUppercaseFirst
-     'Aaaaa' isUppercaseFirst
-     'aaaaAaaaa' isUppercaseFirst
-     '12345' isUppercaseFirst
-    "
-!
-
 isValidSmalltalkIdentifier
     "return true, if the receivers characters make up a valid smalltalk identifier"
 
@@ -5535,7 +5710,7 @@
 !CharacterArray class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.390 2009-02-08 23:48:17 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.391 2009-02-11 11:24:41 cg Exp $'
 ! !
 
 CharacterArray initialize!