StringCollection.st
author Claus Gittinger <cg@exept.de>
Thu, 15 Mar 2007 11:19:06 +0100
changeset 10452 2f486960b688
parent 9161 1ad4d98f8f62
child 10909 5f5e63c29ae2
permissions -rw-r--r--
*** empty log message ***
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     1
"
5
67342904af11 *** empty log message ***
claus
parents: 3
diff changeset
     2
 COPYRIGHT (c) 1989 by Claus Gittinger
160
5dae57a490bd *** empty log message ***
claus
parents: 97
diff changeset
     3
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     4
a27a279701f8 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
"
6561
93afb15812f8 Moved to libbasic
Stefan Vogel <sv@exept.de>
parents: 6176
diff changeset
    12
"{ Package: 'stx:libbasic' }"
6176
ed36e553323f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5251
diff changeset
    13
647
d78d43505b9f eliminated VariableArray
Claus Gittinger <cg@exept.de>
parents: 633
diff changeset
    14
OrderedCollection subclass:#StringCollection
968
58d965d95848 Fix collect:, add expandTabs.
Stefan Vogel <sv@exept.de>
parents: 731
diff changeset
    15
	instanceVariableNames:''
58d965d95848 Fix collect:, add expandTabs.
Stefan Vogel <sv@exept.de>
parents: 731
diff changeset
    16
	classVariableNames:''
58d965d95848 Fix collect:, add expandTabs.
Stefan Vogel <sv@exept.de>
parents: 731
diff changeset
    17
	poolDictionaries:''
58d965d95848 Fix collect:, add expandTabs.
Stefan Vogel <sv@exept.de>
parents: 731
diff changeset
    18
	category:'Collections-Text'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    19
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    20
246
f13be3ba45a0 Text <-> StringCollection
claus
parents: 235
diff changeset
    21
!StringCollection class methodsFor:'documentation'!
89
7be0b86ef80f *** empty log message ***
claus
parents: 87
diff changeset
    22
7be0b86ef80f *** empty log message ***
claus
parents: 87
diff changeset
    23
copyright
7be0b86ef80f *** empty log message ***
claus
parents: 87
diff changeset
    24
"
7be0b86ef80f *** empty log message ***
claus
parents: 87
diff changeset
    25
 COPYRIGHT (c) 1989 by Claus Gittinger
160
5dae57a490bd *** empty log message ***
claus
parents: 97
diff changeset
    26
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    27
89
7be0b86ef80f *** empty log message ***
claus
parents: 87
diff changeset
    28
 This software is furnished under a license and may be used
7be0b86ef80f *** empty log message ***
claus
parents: 87
diff changeset
    29
 only in accordance with the terms of that license and with the
7be0b86ef80f *** empty log message ***
claus
parents: 87
diff changeset
    30
 inclusion of the above copyright notice.   This software may not
7be0b86ef80f *** empty log message ***
claus
parents: 87
diff changeset
    31
 be provided or otherwise made available to, or used by, any
7be0b86ef80f *** empty log message ***
claus
parents: 87
diff changeset
    32
 other person.  No title to or ownership of the software is
7be0b86ef80f *** empty log message ***
claus
parents: 87
diff changeset
    33
 hereby transferred.
7be0b86ef80f *** empty log message ***
claus
parents: 87
diff changeset
    34
"
7be0b86ef80f *** empty log message ***
claus
parents: 87
diff changeset
    35
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    36
89
7be0b86ef80f *** empty log message ***
claus
parents: 87
diff changeset
    37
documentation
7be0b86ef80f *** empty log message ***
claus
parents: 87
diff changeset
    38
"
262
39f91e7b1ab1 *** empty log message ***
claus
parents: 246
diff changeset
    39
    StringCollection is an variable sized array of lines which are strings.
160
5dae57a490bd *** empty log message ***
claus
parents: 97
diff changeset
    40
    WARNING:
1290
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
    41
        This class is temporary (a historic leftover) - it may change or
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
    42
        even vanish in the future. Use OrderedCollections or other standard
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
    43
        classes to represent collections of strings.
89
7be0b86ef80f *** empty log message ***
claus
parents: 87
diff changeset
    44
262
39f91e7b1ab1 *** empty log message ***
claus
parents: 246
diff changeset
    45
    StringCollection used to be called Text, but this is a very bad name
39f91e7b1ab1 *** empty log message ***
claus
parents: 246
diff changeset
    46
     - there is something totally different also named Text in ST-80 ...
1290
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
    47
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
    48
    [author:]
15ba3221b89b documentation
Claus Gittinger <cg@exept.de>
parents: 1064
diff changeset
    49
        Claus Gittinger
89
7be0b86ef80f *** empty log message ***
claus
parents: 87
diff changeset
    50
"
7be0b86ef80f *** empty log message ***
claus
parents: 87
diff changeset
    51
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    52
246
f13be3ba45a0 Text <-> StringCollection
claus
parents: 235
diff changeset
    53
!StringCollection class methodsFor:'instance creation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    54
a27a279701f8 Initial revision
claus
parents:
diff changeset
    55
from:aString
a27a279701f8 Initial revision
claus
parents:
diff changeset
    56
    "return a new text object with lines taken from the argument, aString"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    57
8375
b43b5d1c494d from: is obsoleteed by fromString:
Claus Gittinger <cg@exept.de>
parents: 7982
diff changeset
    58
    self obsoleteMethodWarning:'use #fromString:'.
b43b5d1c494d from: is obsoleteed by fromString:
Claus Gittinger <cg@exept.de>
parents: 7982
diff changeset
    59
    ^ self fromString:aString.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    60
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    61
a27a279701f8 Initial revision
claus
parents:
diff changeset
    62
fromArray:anArray
a27a279701f8 Initial revision
claus
parents:
diff changeset
    63
    "return a new text object with lines taken from the argument, an array
a27a279701f8 Initial revision
claus
parents:
diff changeset
    64
     of strings"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    65
246
f13be3ba45a0 Text <-> StringCollection
claus
parents: 235
diff changeset
    66
    |newStringCollection
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    67
     size "{ Class: SmallInteger }" |
a27a279701f8 Initial revision
claus
parents:
diff changeset
    68
a27a279701f8 Initial revision
claus
parents:
diff changeset
    69
    size := anArray size.
246
f13be3ba45a0 Text <-> StringCollection
claus
parents: 235
diff changeset
    70
    newStringCollection := self new:size.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    71
    1 to:size do:[:line |
246
f13be3ba45a0 Text <-> StringCollection
claus
parents: 235
diff changeset
    72
	newStringCollection at:line put:(anArray at:line)
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    73
    ].
246
f13be3ba45a0 Text <-> StringCollection
claus
parents: 235
diff changeset
    74
    ^ newStringCollection
731
8612922f5b5c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
    75
!
8612922f5b5c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
    76
8375
b43b5d1c494d from: is obsoleteed by fromString:
Claus Gittinger <cg@exept.de>
parents: 7982
diff changeset
    77
fromString:aString
b43b5d1c494d from: is obsoleteed by fromString:
Claus Gittinger <cg@exept.de>
parents: 7982
diff changeset
    78
    "return a new text object with lines taken from the argument, aString"
b43b5d1c494d from: is obsoleteed by fromString:
Claus Gittinger <cg@exept.de>
parents: 7982
diff changeset
    79
b43b5d1c494d from: is obsoleteed by fromString:
Claus Gittinger <cg@exept.de>
parents: 7982
diff changeset
    80
    ^ (self new:1) fromString:aString
b43b5d1c494d from: is obsoleteed by fromString:
Claus Gittinger <cg@exept.de>
parents: 7982
diff changeset
    81
!
b43b5d1c494d from: is obsoleteed by fromString:
Claus Gittinger <cg@exept.de>
parents: 7982
diff changeset
    82
731
8612922f5b5c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
    83
new:size
8612922f5b5c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
    84
    "return a new string collection with size empty lines"
8612922f5b5c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
    85
8612922f5b5c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 647
diff changeset
    86
    ^ (super new:size) grow:size
9161
1ad4d98f8f62 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8375
diff changeset
    87
!
1ad4d98f8f62 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8375
diff changeset
    88
1ad4d98f8f62 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8375
diff changeset
    89
withSize:size
1ad4d98f8f62 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8375
diff changeset
    90
    "return a new string collection with size empty lines"
1ad4d98f8f62 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8375
diff changeset
    91
1ad4d98f8f62 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8375
diff changeset
    92
    ^ (super new:size) grow:size
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    93
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
    94
246
f13be3ba45a0 Text <-> StringCollection
claus
parents: 235
diff changeset
    95
!StringCollection methodsFor:'converting'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    96
a27a279701f8 Initial revision
claus
parents:
diff changeset
    97
asString
a27a279701f8 Initial revision
claus
parents:
diff changeset
    98
    "return myself as a string with embedded cr's"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    99
7829
96a7b0065d77 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6561
diff changeset
   100
    ^ self 
96a7b0065d77 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6561
diff changeset
   101
        asStringWith:Character cr
96a7b0065d77 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6561
diff changeset
   102
        from:1 to:(self size) 
96a7b0065d77 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6561
diff changeset
   103
        compressTabs:false 
96a7b0065d77 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6561
diff changeset
   104
        final:Character cr
87
a0cc38a72871 *** empty log message ***
claus
parents: 10
diff changeset
   105
!
a0cc38a72871 *** empty log message ***
claus
parents: 10
diff changeset
   106
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   107
asStringCollection
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   108
    "return the receiver as a stringCollection - thats easy"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   109
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   110
    ^ self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   111
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   112
3601
c879b9a15f38 added #asStringWithoutEmphasis
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
   113
asStringWithoutEmphasis
c879b9a15f38 added #asStringWithoutEmphasis
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
   114
    "return myself as a string with embedded cr's, but drop any emphasis"
c879b9a15f38 added #asStringWithoutEmphasis
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
   115
c879b9a15f38 added #asStringWithoutEmphasis
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
   116
    ^ self 
c879b9a15f38 added #asStringWithoutEmphasis
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
   117
        asStringWith:Character cr
c879b9a15f38 added #asStringWithoutEmphasis
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
   118
        from:1 to:(self size) 
c879b9a15f38 added #asStringWithoutEmphasis
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
   119
        compressTabs:false 
c879b9a15f38 added #asStringWithoutEmphasis
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
   120
        final:Character cr
c879b9a15f38 added #asStringWithoutEmphasis
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
   121
        withEmphasis:false
c879b9a15f38 added #asStringWithoutEmphasis
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
   122
c879b9a15f38 added #asStringWithoutEmphasis
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
   123
    "Created: / 17.6.1998 / 12:32:48 / cg"
c879b9a15f38 added #asStringWithoutEmphasis
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
   124
!
c879b9a15f38 added #asStringWithoutEmphasis
Claus Gittinger <cg@exept.de>
parents: 1290
diff changeset
   125
7829
96a7b0065d77 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6561
diff changeset
   126
asStringWithoutFinalCR
96a7b0065d77 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6561
diff changeset
   127
    "return myself as a string with embedded cr's
96a7b0065d77 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6561
diff changeset
   128
     but do not add a final CR"
96a7b0065d77 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6561
diff changeset
   129
96a7b0065d77 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6561
diff changeset
   130
    ^ self 
96a7b0065d77 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6561
diff changeset
   131
        asStringWith:Character cr
96a7b0065d77 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6561
diff changeset
   132
        from:1 to:(self size) 
96a7b0065d77 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6561
diff changeset
   133
        compressTabs:false 
96a7b0065d77 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6561
diff changeset
   134
        final:nil
96a7b0065d77 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6561
diff changeset
   135
!
96a7b0065d77 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6561
diff changeset
   136
7899
7577df77ba95 character encodings - first attempt
Claus Gittinger <cg@exept.de>
parents: 7829
diff changeset
   137
encodeFrom:oldEncoding into:newEncoding
7916
55417bd7cc1d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7899
diff changeset
   138
    |enc|
55417bd7cc1d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7899
diff changeset
   139
55417bd7cc1d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7899
diff changeset
   140
    enc := CharacterEncoder encoderToEncodeFrom:oldEncoding into:newEncoding.
7899
7577df77ba95 character encodings - first attempt
Claus Gittinger <cg@exept.de>
parents: 7829
diff changeset
   141
    ^ self collect:[:line |
7577df77ba95 character encodings - first attempt
Claus Gittinger <cg@exept.de>
parents: 7829
diff changeset
   142
        line isNil 
7577df77ba95 character encodings - first attempt
Claus Gittinger <cg@exept.de>
parents: 7829
diff changeset
   143
            ifTrue:[ nil ]
7916
55417bd7cc1d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7899
diff changeset
   144
            ifFalse:[ enc encodeString:line]
7899
7577df77ba95 character encodings - first attempt
Claus Gittinger <cg@exept.de>
parents: 7829
diff changeset
   145
      ]
7577df77ba95 character encodings - first attempt
Claus Gittinger <cg@exept.de>
parents: 7829
diff changeset
   146
!
7577df77ba95 character encodings - first attempt
Claus Gittinger <cg@exept.de>
parents: 7829
diff changeset
   147
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   148
from:aString
a27a279701f8 Initial revision
claus
parents:
diff changeset
   149
    "setup my contents from the argument, aString"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   150
8375
b43b5d1c494d from: is obsoleteed by fromString:
Claus Gittinger <cg@exept.de>
parents: 7982
diff changeset
   151
    self obsoleteMethodWarning:'use #fromString:'.
b43b5d1c494d from: is obsoleteed by fromString:
Claus Gittinger <cg@exept.de>
parents: 7982
diff changeset
   152
    ^ self fromString:aString
b43b5d1c494d from: is obsoleteed by fromString:
Claus Gittinger <cg@exept.de>
parents: 7982
diff changeset
   153
!
b43b5d1c494d from: is obsoleteed by fromString:
Claus Gittinger <cg@exept.de>
parents: 7982
diff changeset
   154
b43b5d1c494d from: is obsoleteed by fromString:
Claus Gittinger <cg@exept.de>
parents: 7982
diff changeset
   155
fromString:aString
b43b5d1c494d from: is obsoleteed by fromString:
Claus Gittinger <cg@exept.de>
parents: 7982
diff changeset
   156
    "setup my contents from the argument, aString"
b43b5d1c494d from: is obsoleteed by fromString:
Claus Gittinger <cg@exept.de>
parents: 7982
diff changeset
   157
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   158
    |numberOfLines "{ Class:SmallInteger }"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   159
     start         "{ Class:SmallInteger }"
6176
ed36e553323f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5251
diff changeset
   160
     stop          "{ Class:SmallInteger }" 
ed36e553323f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5251
diff changeset
   161
    |
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   162
a27a279701f8 Initial revision
claus
parents:
diff changeset
   163
    numberOfLines := aString occurrencesOf:(Character cr).
203
3d88fa870de0 *** empty log message ***
claus
parents: 160
diff changeset
   164
    (aString endsWith:(Character cr)) ifFalse:[
6176
ed36e553323f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5251
diff changeset
   165
        numberOfLines := numberOfLines + 1.
203
3d88fa870de0 *** empty log message ***
claus
parents: 160
diff changeset
   166
    ].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   167
    self grow:numberOfLines.
6176
ed36e553323f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5251
diff changeset
   168
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   169
    start := 1.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   170
    1 to:numberOfLines do:[:lineNr |
6176
ed36e553323f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5251
diff changeset
   171
        stop := aString indexOf:(Character cr) startingAt:start.
ed36e553323f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5251
diff changeset
   172
        stop == 0 ifTrue:[
ed36e553323f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5251
diff changeset
   173
            self at:lineNr put:(aString copyFrom:start).
ed36e553323f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5251
diff changeset
   174
            self from:lineNr+1 to:numberOfLines put:''.
ed36e553323f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5251
diff changeset
   175
            ^ self.
ed36e553323f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5251
diff changeset
   176
        ].
10
claus
parents: 5
diff changeset
   177
6176
ed36e553323f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5251
diff changeset
   178
        self at:lineNr put:(aString copyFrom:start to:stop-1).
ed36e553323f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5251
diff changeset
   179
        start := stop + 1
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   180
    ]
6176
ed36e553323f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5251
diff changeset
   181
ed36e553323f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5251
diff changeset
   182
    "Modified: / 12.11.2001 / 18:18:42 / cg"
968
58d965d95848 Fix collect:, add expandTabs.
Stefan Vogel <sv@exept.de>
parents: 731
diff changeset
   183
! !
58d965d95848 Fix collect:, add expandTabs.
Stefan Vogel <sv@exept.de>
parents: 731
diff changeset
   184
58d965d95848 Fix collect:, add expandTabs.
Stefan Vogel <sv@exept.de>
parents: 731
diff changeset
   185
!StringCollection methodsFor:'copying'!
58d965d95848 Fix collect:, add expandTabs.
Stefan Vogel <sv@exept.de>
parents: 731
diff changeset
   186
58d965d95848 Fix collect:, add expandTabs.
Stefan Vogel <sv@exept.de>
parents: 731
diff changeset
   187
copyEmpty:size
58d965d95848 Fix collect:, add expandTabs.
Stefan Vogel <sv@exept.de>
parents: 731
diff changeset
   188
    "we have to redefine this, since 'self class new:size' does allocate size nil lines.
58d965d95848 Fix collect:, add expandTabs.
Stefan Vogel <sv@exept.de>
parents: 731
diff changeset
   189
     In order to get collect working, we have to undo this allocation"
58d965d95848 Fix collect:, add expandTabs.
Stefan Vogel <sv@exept.de>
parents: 731
diff changeset
   190
58d965d95848 Fix collect:, add expandTabs.
Stefan Vogel <sv@exept.de>
parents: 731
diff changeset
   191
    ^ (super copyEmpty:size) grow:0.
58d965d95848 Fix collect:, add expandTabs.
Stefan Vogel <sv@exept.de>
parents: 731
diff changeset
   192
58d965d95848 Fix collect:, add expandTabs.
Stefan Vogel <sv@exept.de>
parents: 731
diff changeset
   193
    "Created: 14.2.1996 / 11:05:47 / stefan"
10452
2f486960b688 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9161
diff changeset
   194
!
2f486960b688 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9161
diff changeset
   195
2f486960b688 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9161
diff changeset
   196
withoutLeadingBlankLines
2f486960b688 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9161
diff changeset
   197
    "return a copy of the receiver with leading blank lines removed.
2f486960b688 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9161
diff changeset
   198
     If there are no leading blank lines, the original receiver is returned.
2f486960b688 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9161
diff changeset
   199
     If all lines are blank, an empty string collection is returned."
2f486960b688 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9161
diff changeset
   200
2f486960b688 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9161
diff changeset
   201
    |indexOfFirstNonBlankLine|
2f486960b688 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9161
diff changeset
   202
2f486960b688 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9161
diff changeset
   203
    self first isBlank ifTrue:[
2f486960b688 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9161
diff changeset
   204
        indexOfFirstNonBlankLine := self findFirst:[:line | line notNil and:[line isBlank not]].
2f486960b688 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9161
diff changeset
   205
        indexOfFirstNonBlankLine == 0 ifTrue:[ ^ self copyEmpty ].
2f486960b688 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9161
diff changeset
   206
        ^ self copyFrom:indexOfFirstNonBlankLine
2f486960b688 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9161
diff changeset
   207
    ].
2f486960b688 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9161
diff changeset
   208
    ^ self.
2f486960b688 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9161
diff changeset
   209
2f486960b688 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9161
diff changeset
   210
    "
2f486960b688 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9161
diff changeset
   211
'1
2f486960b688 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9161
diff changeset
   212
2
2f486960b688 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9161
diff changeset
   213
3' asStringCollection withoutLeadingBlankLines     
2f486960b688 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9161
diff changeset
   214
    "
2f486960b688 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9161
diff changeset
   215
2f486960b688 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9161
diff changeset
   216
    "
2f486960b688 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9161
diff changeset
   217
'
2f486960b688 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9161
diff changeset
   218
2
2f486960b688 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9161
diff changeset
   219
3' asStringCollection withoutLeadingBlankLines       
2f486960b688 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9161
diff changeset
   220
    "
2f486960b688 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9161
diff changeset
   221
2f486960b688 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9161
diff changeset
   222
    "
2f486960b688 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9161
diff changeset
   223
'
2f486960b688 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9161
diff changeset
   224
2f486960b688 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9161
diff changeset
   225
' asStringCollection withoutLeadingBlankLines  
2f486960b688 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9161
diff changeset
   226
    "
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   227
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   228
5251
35a8e9579e60 category renamed
Claus Gittinger <cg@exept.de>
parents: 4007
diff changeset
   229
!StringCollection methodsFor:'printing & storing'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   230
a27a279701f8 Initial revision
claus
parents:
diff changeset
   231
printString
284
af1f7d255587 *** empty log message ***
claus
parents: 262
diff changeset
   232
    "return the receivers printString"
af1f7d255587 *** empty log message ***
claus
parents: 262
diff changeset
   233
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   234
    ^ self asString
a27a279701f8 Initial revision
claus
parents:
diff changeset
   235
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   236
7899
7577df77ba95 character encodings - first attempt
Claus Gittinger <cg@exept.de>
parents: 7829
diff changeset
   237
!StringCollection methodsFor:'queries'!
7577df77ba95 character encodings - first attempt
Claus Gittinger <cg@exept.de>
parents: 7829
diff changeset
   238
7577df77ba95 character encodings - first attempt
Claus Gittinger <cg@exept.de>
parents: 7829
diff changeset
   239
encoding
7577df77ba95 character encodings - first attempt
Claus Gittinger <cg@exept.de>
parents: 7829
diff changeset
   240
    self do:[:l | l notNil ifTrue:[^ l encoding]].
7577df77ba95 character encodings - first attempt
Claus Gittinger <cg@exept.de>
parents: 7829
diff changeset
   241
    "/ sigh
7982
0412a26c4621 encoding now unicode
Claus Gittinger <cg@exept.de>
parents: 7916
diff changeset
   242
    ^ #'unicode'
7899
7577df77ba95 character encodings - first attempt
Claus Gittinger <cg@exept.de>
parents: 7829
diff changeset
   243
! !
7577df77ba95 character encodings - first attempt
Claus Gittinger <cg@exept.de>
parents: 7829
diff changeset
   244
246
f13be3ba45a0 Text <-> StringCollection
claus
parents: 235
diff changeset
   245
!StringCollection methodsFor:'searching'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   246
a27a279701f8 Initial revision
claus
parents:
diff changeset
   247
indexOfLineStartingWith:aString
a27a279701f8 Initial revision
claus
parents:
diff changeset
   248
    "return the index of the first line starting with the argument, aString"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   249
1009
a0354f2fea61 care for nil-lines when searching
Claus Gittinger <cg@exept.de>
parents: 968
diff changeset
   250
    |index "{ Class:SmallInteger }" 
a0354f2fea61 care for nil-lines when searching
Claus Gittinger <cg@exept.de>
parents: 968
diff changeset
   251
     l|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   252
a27a279701f8 Initial revision
claus
parents:
diff changeset
   253
    index := 1.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   254
    [index <= self size] whileTrue:[
1009
a0354f2fea61 care for nil-lines when searching
Claus Gittinger <cg@exept.de>
parents: 968
diff changeset
   255
        l := self at:index.
a0354f2fea61 care for nil-lines when searching
Claus Gittinger <cg@exept.de>
parents: 968
diff changeset
   256
        (l notNil and:[l startsWith:aString]) ifTrue:[
a0354f2fea61 care for nil-lines when searching
Claus Gittinger <cg@exept.de>
parents: 968
diff changeset
   257
            ^ index
a0354f2fea61 care for nil-lines when searching
Claus Gittinger <cg@exept.de>
parents: 968
diff changeset
   258
        ].
a0354f2fea61 care for nil-lines when searching
Claus Gittinger <cg@exept.de>
parents: 968
diff changeset
   259
        index := index + 1
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   260
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   261
    ^ 0
1009
a0354f2fea61 care for nil-lines when searching
Claus Gittinger <cg@exept.de>
parents: 968
diff changeset
   262
a0354f2fea61 care for nil-lines when searching
Claus Gittinger <cg@exept.de>
parents: 968
diff changeset
   263
    "Modified: 24.2.1996 / 19:08:47 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   264
! !
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   265
1064
f7a06e0ca253 added #withTabs
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
   266
!StringCollection methodsFor:'special converting'!
f7a06e0ca253 added #withTabs
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
   267
f7a06e0ca253 added #withTabs
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
   268
withTabs
f7a06e0ca253 added #withTabs
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
   269
    "return a new stringCollection consisting of the receivers lines,
f7a06e0ca253 added #withTabs
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
   270
     where leading spaces are replaced by tabulator characters (assuming 8-col tabs).
f7a06e0ca253 added #withTabs
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
   271
     Notice: lines which do not contain leading spaces, are copied by reference to the
f7a06e0ca253 added #withTabs
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
   272
             new stringCollection (i.e. shared);
f7a06e0ca253 added #withTabs
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
   273
             otherwise new strings is created.
f7a06e0ca253 added #withTabs
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
   274
     Limitation: only the very first spaces are replaced"
f7a06e0ca253 added #withTabs
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
   275
f7a06e0ca253 added #withTabs
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
   276
    ^ self collect:[:string|
f7a06e0ca253 added #withTabs
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
   277
        string notNil ifTrue:[
f7a06e0ca253 added #withTabs
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
   278
            string withTabs     
f7a06e0ca253 added #withTabs
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
   279
        ] ifFalse:[
f7a06e0ca253 added #withTabs
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
   280
            string
f7a06e0ca253 added #withTabs
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
   281
        ]
f7a06e0ca253 added #withTabs
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
   282
    ]
f7a06e0ca253 added #withTabs
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
   283
f7a06e0ca253 added #withTabs
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
   284
    "
f7a06e0ca253 added #withTabs
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
   285
       ('        abcd            ') asStringCollection withTabs
f7a06e0ca253 added #withTabs
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
   286
    "
f7a06e0ca253 added #withTabs
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
   287
f7a06e0ca253 added #withTabs
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
   288
    "Created: 4.3.1996 / 17:09:07 / cg"
f7a06e0ca253 added #withTabs
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
   289
    "Modified: 4.3.1996 / 17:10:37 / cg"
f7a06e0ca253 added #withTabs
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
   290
!
f7a06e0ca253 added #withTabs
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
   291
f7a06e0ca253 added #withTabs
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
   292
withTabsExpanded
f7a06e0ca253 added #withTabs
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
   293
    "return a new stringCollection consisting of the receivers lines,
f7a06e0ca253 added #withTabs
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
   294
     where tabs are replaced by space characters (assuming 8-col tabs).
f7a06e0ca253 added #withTabs
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
   295
     Notice: lines which do not contain any tab, are copied by reference to the
f7a06e0ca253 added #withTabs
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
   296
             new stringCollection (i.e. shared);
f7a06e0ca253 added #withTabs
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
   297
             otherwise new strings is created."
f7a06e0ca253 added #withTabs
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
   298
f7a06e0ca253 added #withTabs
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
   299
    ^ self collect:[:string|
f7a06e0ca253 added #withTabs
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
   300
        string notNil ifTrue:[
f7a06e0ca253 added #withTabs
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
   301
            string withTabsExpanded     
f7a06e0ca253 added #withTabs
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
   302
        ] ifFalse:[
f7a06e0ca253 added #withTabs
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
   303
            string
f7a06e0ca253 added #withTabs
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
   304
        ]
f7a06e0ca253 added #withTabs
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
   305
    ]
f7a06e0ca253 added #withTabs
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
   306
f7a06e0ca253 added #withTabs
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
   307
    "
f7a06e0ca253 added #withTabs
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
   308
       |tab|
f7a06e0ca253 added #withTabs
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
   309
       tab := String with:Character tab.
f7a06e0ca253 added #withTabs
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
   310
       ('abcd', tab, 'tef', tab, 'tgh') asStringCollection withTabsExpanded
f7a06e0ca253 added #withTabs
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
   311
    "
f7a06e0ca253 added #withTabs
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
   312
f7a06e0ca253 added #withTabs
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
   313
    "Created: 12.2.1996 / 22:25:56 / stefan"
f7a06e0ca253 added #withTabs
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
   314
    "Modified: 14.2.1996 / 11:13:01 / stefan"
f7a06e0ca253 added #withTabs
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
   315
    "Modified: 4.3.1996 / 17:10:22 / cg"
f7a06e0ca253 added #withTabs
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
   316
! !
f7a06e0ca253 added #withTabs
Claus Gittinger <cg@exept.de>
parents: 1009
diff changeset
   317
4007
561d175af944 added #isStringCollection
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   318
!StringCollection methodsFor:'testing'!
561d175af944 added #isStringCollection
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   319
561d175af944 added #isStringCollection
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   320
isStringCollection
561d175af944 added #isStringCollection
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   321
    "return true, if the receiver is some kind of stringCollection;
561d175af944 added #isStringCollection
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   322
     true is returned here - the method is redefined from Object."
561d175af944 added #isStringCollection
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   323
561d175af944 added #isStringCollection
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   324
    ^ true
561d175af944 added #isStringCollection
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   325
561d175af944 added #isStringCollection
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   326
561d175af944 added #isStringCollection
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   327
! !
561d175af944 added #isStringCollection
Claus Gittinger <cg@exept.de>
parents: 3601
diff changeset
   328
633
46e996b3c18f version at the end
Claus Gittinger <cg@exept.de>
parents: 608
diff changeset
   329
!StringCollection class methodsFor:'documentation'!
46e996b3c18f version at the end
Claus Gittinger <cg@exept.de>
parents: 608
diff changeset
   330
46e996b3c18f version at the end
Claus Gittinger <cg@exept.de>
parents: 608
diff changeset
   331
version
10452
2f486960b688 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9161
diff changeset
   332
    ^ '$Header: /cvs/stx/stx/libbasic/StringCollection.st,v 1.37 2007-03-15 10:19:06 cg Exp $'
633
46e996b3c18f version at the end
Claus Gittinger <cg@exept.de>
parents: 608
diff changeset
   333
! !