|
Class: StringCollection
Object
|
+--Collection
|
+--SequenceableCollection
|
+--OrderedCollection
|
+--StringCollection
|
+--FileText
- Package:
- stx:libbasic
- Category:
- Collections-Text
- Version:
- rev:
1.61
date: 2018/11/07 07:21:21
- user: cg
- file: StringCollection.st directory: libbasic
- module: stx stc-classLibrary: libbasic
- Author:
- Claus Gittinger
StringCollection is a 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 ...
instance creation
-
from: aString
-
return a new text object with lines taken from the argument, aString
** This is an obsolete interface - do not use it (it may vanish in future versions) **
-
fromArray: anArray
-
return a new text object with lines taken from the argument, an array
of strings
-
fromString: aString
-
return a new text object with lines taken from the argument, aString
-
new: size
-
return a new string collection with size empty lines
usage example(s):
-
newWithCapacity: size
-
return a new empty string collection with size capacity
usage example(s):
StringCollection newWithCapacity:10
|
-
newWithSize: size
-
return a new string collection with size empty lines
converting
-
asString
-
return myself as a string with embedded cr's
usage example(s):
#('This' 'is' 'some' 'text') asStringCollection asString
#('This' 22 'some' 'text') asStringCollection asString
|
-
asStringCollection
-
return the receiver as a stringCollection - that's easy
-
asStringWithoutFinalCR
-
return myself as a string with embedded cr's
but do not add a final CR
-
encodeFrom: oldEncoding into: newEncoding
-
encode each line
-
from: aString
-
setup my contents from the argument, aString.
Obsolete, as it conflicts with the from:index
message, as inherited from SeqCollection.
For a migration time, check which interface is wanted here,
and issue an obsoleteMessageWarning as required.
** This is an obsolete interface - do not use it (it may vanish in future versions) **
-
fromString: aString
-
setup my contents from the argument, aString.
AString should be delimited by newline characters
copying
-
copyEmpty: size
-
we have to redefine this, since 'self class new:size'
does allocate size nil lines (it does an implicit #grow: size).
In order to get #collect: working, we should not perform this implicit grow
-
copyEmptyAndGrow: size
-
performance optimization:
StringCollections are always grown to size after #new: (containing nil elements)
usage example(s):
#('some' 'text' 'bla') asStringCollection copyEmptyAndGrow:20
|
-
removeTrailingBlankLines
-
destructive removal of trailing blank lines
usage example(s):
'1
2
3' asStringCollection removeTrailingBlankLines
|
usage example(s):
'
2
3
' asStringCollection removeTrailingBlankLines
|
usage example(s):
'
2
3
' asStringCollection removeTrailingBlankLines
|
usage example(s):
'
' asStringCollection removeTrailingBlankLines
|
-
withoutLeadingAndTrailingBlankLines
-
return a copy of the receiver with leading and trailing blank lines removed.
If there are no trailing blank lines, the original receiver is returned.
If all lines are blank, an empty string collection is returned.
usage example(s):
'1
2
3' asStringCollection withoutLeadingAndTrailingBlankLines
|
usage example(s):
'
2
3
' asStringCollection withoutLeadingAndTrailingBlankLines
|
-
withoutLeadingBlankLines
-
return a copy of the receiver with leading blank lines removed.
If there are no leading blank lines, the original receiver is returned.
If all lines are blank, an empty string collection is returned.
usage example(s):
'1
2
3' asStringCollection withoutLeadingBlankLines
|
usage example(s):
'
2
3' asStringCollection withoutLeadingBlankLines
|
usage example(s):
'
' asStringCollection withoutLeadingBlankLines
|
-
withoutTrailingBlankLines
-
return a copy of the receiver with trailing blank lines removed.
If there are no trailing blank lines, the original receiver is returned.
If all lines are blank, an empty string collection is returned.
usage example(s):
'1
2
3' asStringCollection withoutTrailingBlankLines
|
usage example(s):
'
2
3
' asStringCollection withoutTrailingBlankLines
|
usage example(s):
'
2
3
' asStringCollection withoutTrailingBlankLines
|
usage example(s):
'
' asStringCollection withoutTrailingBlankLines
|
enumerating
-
collect: aBlock
-
evaluate the argument, aBlock for every element in the collection
and return a collection of the results.
Redefined, to change the result collection to an OrderedCollection if
not all elements are valid for a StringCollection (must be string or nil).
usage example(s):
#('this' 'is' 'some' nil 'text') asStringCollection collect:[:i | i]
#('this' true 'some' nil 'text') asStringCollection collect:[:i | i ]
|
-
collect: collectBlock thenSelect: selectBlock
-
combination of collect followed by select;
redefined to avoid the creation of an intermediate (garbage) collection.
Redefined, to change the result collection to an OrderedCollection if
not all elements are valid for a StringCollection (must be string or nil).
usage example(s):
#('this' 'is' 'some' nil 'text') asStringCollection collect:[:i | i] thenSelect:[:e| e notNil]
#('this' true 'some' nil 'text') asStringCollection collect:[:i | i ] thenSelect:[:e| e notNil]
|
-
select: selectBlock thenCollect: collectBlock
-
combination of select followed by collect;
redefined to avoid the creation of an intermediate (garbage) collection.
Redefined, to change the result collection to an OrderedCollection if
not all elements are valid for a StringCollection (must be string or nil).
usage example(s):
#('this' 'is' 'some' nil 'text') asStringCollection select:[:e| e notNil] thenCollect:[:i | i]
#('this' true 'some' nil 'text') asStringCollection select:[:e| e notNil] thenCollect:[:i | i]
|
inspecting
-
inspector2TabText ( an extension from the stx:libtool package )
-
printing & storing
-
printOn: aStream
-
print myself on aStream with embedded cr's
-
printString
-
return the receiver's printString
queries
-
encoding
-
the encoding; ask my first line
-
stringSize
-
the size of the string if I was converted
searching
-
indexOfLineStartingWith: aString
-
return the index of the first line starting with the argument, aString
special converting
-
decodeFrom: encodingSymbol
-
given the receiver encoded as described by encodingSymbol,
convert it into internal ST/X (unicode) encoding and return a
corresponding StringCollection.
-
withTabs
-
return a new stringCollection consisting of the receiver's lines,
where leading spaces are replaced by tabulator characters (assuming 8-col tabs).
Notice: lines which do not contain leading spaces, are copied by reference to the
new stringCollection (i.e. shared);
otherwise new strings is created.
Limitation: only the very first spaces are replaced
usage example(s):
(' abcd ') asStringCollection withTabs
|
-
withTabsExpanded
-
return a new stringCollection consisting of the receiver's lines,
where tabs are replaced by space characters (assuming 8-col tabs).
Notice: lines which do not contain any tab, are copied by reference to the
new stringCollection (i.e. shared);
otherwise new strings is created.
-
withTabsExpanded: n
-
return a new stringCollection consisting of the receiver's lines,
where tabs are replaced by space characters (assuming n-col tabs).
Notice: lines which do not contain any tab, are copied by reference to the
new stringCollection (i.e. shared);
otherwise new strings is created.
testing
-
isStringCollection
-
return true, if the receiver is some kind of stringCollection;
true is returned here - the method is redefined from Object.
|