eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'StringCollection':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: StringCollection


Inheritance:

   Object
   |
   +--Collection
      |
      +--SequenceableCollection
         |
         +--OrderedCollection
            |
            +--StringCollection
               |
               +--FileText

Package:
stx:libbasic
Category:
Collections-Text
Version:
rev: 1.58 date: 2018/03/05 13:48:35
user: cg
file: StringCollection.st directory: libbasic
module: stx stc-classLibrary: libbasic
Author:
Claus Gittinger

Description:


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 ...


Class protocol:

instance creation
o  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) **

o  fromArray: anArray
return a new text object with lines taken from the argument, an array
of strings

o  fromString: aString
return a new text object with lines taken from the argument, aString

o  new: size
return a new string collection with size empty lines
usage example(s):
  StringCollection new:10

o  newWithCapacity: size
return a new empty string collection with size capacity
usage example(s):
  StringCollection newWithCapacity:10

o  newWithSize: size
return a new string collection with size empty lines


Instance protocol:

converting
o  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

o  asStringCollection
return the receiver as a stringCollection - that's easy

o  asStringWithoutEmphasis
return myself as a string with embedded cr's, but drop any emphasis

o  asStringWithoutFinalCR
return myself as a string with embedded cr's
but do not add a final CR

o  encodeFrom: oldEncoding into: newEncoding
encode each line

o  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) **

o  fromString: aString
setup my contents from the argument, aString.
AString should be delimited by newline characters

copying
o  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

o  copyEmptyAndGrow: size
performance optimization:
StringCollections are always grown to size after #new: (containing nil elements)
usage example(s):
        #('some' 'text' 'bla') asStringCollection copyEmptyAndGrow:20

o  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       

o  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      

o  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
o  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 ]

o  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]

o  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
o  inspector2TabText
( an extension from the stx:libtool package )

o  inspector2Tabs
( an extension from the stx:libtool package )
(comment from inherited method)
add a graph-tab; but only if all my values are numerical

printing & storing
o  printOn: aStream
print myself on aStream with embedded cr's

o  printString
return the receiver's printString

queries
o  encoding
the encoding; ask my first line

o  stringSize
the size of the string if I was converted

searching
o  indexOfLineStartingWith: aString
return the index of the first line starting with the argument, aString

special converting
o  decodeFrom: encodingSymbol
given the receiver encoded as described by encodingSymbol,
convert it into internal ST/X (unicode) encoding and return a
corresponding StringCollection.

o  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

o  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.

o  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
o  isStringCollection
return true, if the receiver is some kind of stringCollection;
true is returned here - the method is redefined from Object.



ST/X 7.1.0.0; WebServer 1.663 at exept.de:8081; Fri, 22 Mar 2019 10:06:43 GMT