"
COPYRIGHT (c) 1989 by Claus Gittinger
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
"
OrderedCollection subclass:#StringCollection
instanceVariableNames:''
classVariableNames:''
poolDictionaries:''
category:'Collections-Text'
!
!StringCollection class methodsFor:'documentation'!
copyright
"
COPYRIGHT (c) 1989 by Claus Gittinger
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
"
!
documentation
"
StringCollection is an variable sized array of lines which are strings.
WARNING:
This class is temporary (a historic leftover) - it may change or
even vanish in the future. Use OrderedCollections or other standard
classes to represent collections of strings.
StringCollection used to be called Text, but this is a very bad name
- there is something totally different also named Text in ST-80 ...
"
! !
!StringCollection class methodsFor:'instance creation'!
from:aString
"return a new text object with lines taken from the argument, aString"
^ (self new:1) from:aString
!
fromArray:anArray
"return a new text object with lines taken from the argument, an array
of strings"
|newStringCollection
size "{ Class: SmallInteger }" |
size := anArray size.
newStringCollection := self new:size.
1 to:size do:[:line |
newStringCollection at:line put:(anArray at:line)
].
^ newStringCollection
!
new:size
"return a new string collection with size empty lines"
^ (super new:size) grow:size
! !
!StringCollection methodsFor:'converting'!
asString
"return myself as a string with embedded cr's"
^ self asStringWith:Character cr
from:1 to:(self size)
compressTabs:false
final:Character cr
!
asStringCollection
"return the receiver as a stringCollection - thats easy"
^ self
!
from:aString
"setup my contents from the argument, aString"
|numberOfLines "{ Class:SmallInteger }"
start "{ Class:SmallInteger }"
stop "{ Class:SmallInteger }" |
numberOfLines := aString occurrencesOf:(Character cr).
(aString endsWith:(Character cr)) ifFalse:[
numberOfLines := numberOfLines + 1.
].
self grow:numberOfLines.
start := 1.
1 to:numberOfLines do:[:lineNr |
stop := aString indexOf:(Character cr) startingAt:start.
stop == 0 ifTrue:[
stop := aString size
] ifFalse: [
stop := stop - 1.
].
(stop < start) ifTrue: [
self at:lineNr put:(String new:0)
] ifFalse: [
self at:lineNr put:(aString copyFrom:start to:stop)
].
start := stop + 2
]
! !
!StringCollection methodsFor:'printing'!
printString
"return the receivers printString"
^ self asString
! !
!StringCollection methodsFor:'searching'!
indexOfLineStartingWith:aString
"return the index of the first line starting with the argument, aString"
|index "{ Class:SmallInteger }" |
index := 1.
[index <= self size] whileTrue:[
((self at:index) startsWith:aString) ifTrue:[
^ index
].
index := index + 1
].
^ 0
! !
!StringCollection class methodsFor:'documentation'!
version
^ '$Header: /cvs/stx/stx/libbasic/StringCollection.st,v 1.21 1995-12-10 00:40:53 cg Exp $'
! !