CharacterArray.st
author Claus Gittinger <cg@exept.de>
Sat, 25 Nov 1995 11:06:58 +0100
changeset 651 2093b018dc3a
parent 650 9aef9de12f65
child 652 b2212c748f24
permissions -rw-r--r--
added restAfter:withoutSeparators:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
     1
"
af7aeb79b25e Initial revision
claus
parents:
diff changeset
     2
 COPYRIGHT (c) 1994 by Claus Gittinger
154
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
     3
	      All Rights Reserved
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
     4
af7aeb79b25e Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
af7aeb79b25e Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
af7aeb79b25e Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
af7aeb79b25e Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
af7aeb79b25e Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    11
"
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    12
255
2b2c5c0facab *** empty log message ***
claus
parents: 247
diff changeset
    13
ByteArray subclass:#CharacterArray
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
    14
	 instanceVariableNames:''
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
    15
	 classVariableNames:'PreviousMatch'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
    16
	 poolDictionaries:''
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
    17
	 category:'Collections-Text'
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    18
!
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    19
255
2b2c5c0facab *** empty log message ***
claus
parents: 247
diff changeset
    20
!CharacterArray class methodsFor:'documentation'!
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    21
82
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    22
copyright
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    23
"
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    24
 COPYRIGHT (c) 1994 by Claus Gittinger
154
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
    25
	      All Rights Reserved
82
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    26
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    27
 This software is furnished under a license and may be used
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    28
 only in accordance with the terms of that license and with the
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    29
 inclusion of the above copyright notice.   This software may not
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    30
 be provided or otherwise made available to, or used by, any
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    31
 other person.  No title to or ownership of the software is
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    32
 hereby transferred.
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    33
"
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    34
!
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    35
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    36
documentation
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    37
"
255
2b2c5c0facab *** empty log message ***
claus
parents: 247
diff changeset
    38
    CharacterArray is a superclass for all kinds of Strings (i.e.
68
59faa75185ba *** empty log message ***
claus
parents: 64
diff changeset
    39
    (singleByte-)Strings, TwoByteStrings and whatever comes in the future.
154
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
    40
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
    41
    As the name already implies, this class is abstract, meaning that there are
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
    42
    no instances of it. All this class does is provide common protocol for 
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
    43
    concrete subclasses.
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    44
"
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    45
! !
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    46
255
2b2c5c0facab *** empty log message ***
claus
parents: 247
diff changeset
    47
!CharacterArray class methodsFor:'instance creation'!
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    48
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    49
basicNew
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    50
    "return a new empty string"
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    51
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    52
    ^ self basicNew:0
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    53
!
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    54
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    55
fromString:aString
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    56
    "return a copy of the argument, aString"
af7aeb79b25e Initial revision
claus
parents:
diff changeset
    57
68
59faa75185ba *** empty log message ***
claus
parents: 64
diff changeset
    58
    ^ (self basicNew:(aString size)) replaceFrom:1 with:aString
59faa75185ba *** empty log message ***
claus
parents: 64
diff changeset
    59
59faa75185ba *** empty log message ***
claus
parents: 64
diff changeset
    60
    "TwoByteString fromString:'hello'"
581
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    61
!
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    62
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    63
fromStringCollection:aCollectionOfStrings
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    64
    "return new string formed by concatenating a copy of the argument, aString"
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    65
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    66
    ^ self fromStringCollection:aCollectionOfStrings separatedBy:''
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    67
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    68
    "
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    69
     String fromStringCollection:#('hello' 'world' 'how' 'about' 'this')
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    70
    "
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    71
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    72
    "Created: 20.11.1995 / 15:26:59 / cg"
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    73
!
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    74
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    75
fromStringCollection:aCollectionOfStrings separatedBy:aSeparatorString
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    76
    "return new string formed by concatenating a copy of the argument, aString"
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    77
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    78
    |newString first|
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    79
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    80
    newString := ''.
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    81
    first := true.
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    82
    aCollectionOfStrings do:[:s | 
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    83
	first ifFalse:[
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    84
	    newString := newString , aSeparatorString
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    85
	] ifTrue:[
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    86
	    first := false
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    87
	].
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    88
	newString := newString , s
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    89
    ].
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    90
    ^ newString
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    91
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    92
    "
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    93
     String fromStringCollection:#('hello' 'world' 'how' 'about' 'this') separatedBy:' '
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    94
    "
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    95
8a991a4cb738 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    96
    "Created: 20.11.1995 / 15:32:17 / cg"
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
    97
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
    98
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
    99
new
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   100
    "return a new empty string"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   101
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   102
    ^ self basicNew:0
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
   103
! !
af7aeb79b25e Initial revision
claus
parents:
diff changeset
   104
443
Claus Gittinger <cg@exept.de>
parents: 428
diff changeset
   105
!CharacterArray class methodsFor:'code tables'!
Claus Gittinger <cg@exept.de>
parents: 428
diff changeset
   106
Claus Gittinger <cg@exept.de>
parents: 428
diff changeset
   107
decoderTableFor:encoding
Claus Gittinger <cg@exept.de>
parents: 428
diff changeset
   108
    "this is an experimental interface - unfinished"
Claus Gittinger <cg@exept.de>
parents: 428
diff changeset
   109
Claus Gittinger <cg@exept.de>
parents: 428
diff changeset
   110
    |table|
Claus Gittinger <cg@exept.de>
parents: 428
diff changeset
   111
Claus Gittinger <cg@exept.de>
parents: 428
diff changeset
   112
    table := (0 to:255) asByteArray.
Claus Gittinger <cg@exept.de>
parents: 428
diff changeset
   113
    encoding == #mac ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 428
diff changeset
   114
	table at:8r232+1 put:246. "/ german umlaut o
Claus Gittinger <cg@exept.de>
parents: 428
diff changeset
   115
	table at:8r212+1 put:228. "/ german umlaut a
Claus Gittinger <cg@exept.de>
parents: 428
diff changeset
   116
	table at:8r237+1 put:252. "/ german umlaut u
Claus Gittinger <cg@exept.de>
parents: 428
diff changeset
   117
	table at:8r206+1 put:220. "/ german umlaut U
Claus Gittinger <cg@exept.de>
parents: 428
diff changeset
   118
	"/ more needed here - need info to do it ....
Claus Gittinger <cg@exept.de>
parents: 428
diff changeset
   119
    ].
Claus Gittinger <cg@exept.de>
parents: 428
diff changeset
   120
    "/ more encodings needed here ....
Claus Gittinger <cg@exept.de>
parents: 428
diff changeset
   121
Claus Gittinger <cg@exept.de>
parents: 428
diff changeset
   122
    ^ table
Claus Gittinger <cg@exept.de>
parents: 428
diff changeset
   123
Claus Gittinger <cg@exept.de>
parents: 428
diff changeset
   124
    "Created: 20.10.1995 / 23:04:43 / cg"
Claus Gittinger <cg@exept.de>
parents: 428
diff changeset
   125
! !
Claus Gittinger <cg@exept.de>
parents: 428
diff changeset
   126
328
claus
parents: 327
diff changeset
   127
!CharacterArray class methodsFor:'pattern matching'!
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
   128
327
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   129
matchScan:matchScanArray from:matchStart to:matchStop with:aString from:start to:stop ignoreCase:ignoreCase
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   130
    "helper for match; return true if the characters from start to stop in
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   131
     aString are matching the scan in matchScan from matchStart to matchStop.
328
claus
parents: 327
diff changeset
   132
     The matchScan is as created by asMatchScanArray.
327
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   133
328
claus
parents: 327
diff changeset
   134
     This algorithm is not at all the most efficient; 
claus
parents: 327
diff changeset
   135
     for heavy duty pattern matching, an interface (primitive) to the regex 
claus
parents: 327
diff changeset
   136
     pattern matching package should be added."
327
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   137
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   138
    |matchEntry 
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   139
     mStart "{ Class: SmallInteger }"
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   140
     mStop  "{ Class: SmallInteger }"
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   141
     sStart "{ Class: SmallInteger }"
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   142
     sStop  "{ Class: SmallInteger }"
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   143
     mSize  "{ Class: SmallInteger }"
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   144
     sSize  "{ Class: SmallInteger }"
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   145
     index  "{ Class: SmallInteger }"
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   146
     quickCheck matchLast
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   147
     matchSet checkChar included|
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   148
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   149
    mStart := matchStart.
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   150
    mStop := matchStop.
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   151
    sStart := start.
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   152
    sStop := stop.
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   153
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   154
    [true] whileTrue:[
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   155
	mSize := mStop - mStart + 1.
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   156
	sSize := sStop - sStart + 1.
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   157
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   158
	"empty strings match"
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   159
	(mSize == 0) ifTrue:[^ (sSize == 0)].
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   160
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   161
	matchEntry := matchScanArray at:mStart.
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   162
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   163
	"/ the most common case first:
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   164
	(sSize ~~ 0 
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   165
	and:[(checkChar := (aString at:sStart)) == matchEntry]) ifTrue:[
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   166
	    "advance by one and continue"
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   167
	    mStart := mStart + 1.
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   168
	    sStart := sStart + 1
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   169
	] ifFalse:[
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   170
	    (matchEntry == #any) ifTrue:[
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   171
		"restString empty -> no match"
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   172
		(sSize == 0) ifTrue:[^ false].
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   173
		"# matches single character"
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   174
		((sSize == 1) and:[mSize == 1]) ifTrue:[^ true].
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   175
		"advance by one and continue"
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   176
		mStart := mStart + 1.
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   177
		sStart := sStart + 1
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   178
	    ] ifFalse:[
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   179
		(matchEntry == #anyString) ifTrue:[
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   180
		    "* alone matches anything"
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   181
		    (mSize == 1) ifTrue:[^ true].
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   182
		    "restString empty & matchString not empty -> no match"
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   183
		    (sSize == 0) ifTrue:[^ false].
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   184
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   185
		    "
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   186
		     try to avoid some of the recursion by checking last
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   187
		     character and continue with shortened strings if possible
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   188
		    "
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   189
		    quickCheck := false.
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   190
		    (mStop >= mStart) ifTrue:[
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   191
			matchLast := matchScanArray at:mStop.
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   192
			(matchLast ~~ #anyString) ifTrue:[
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   193
			    (matchLast == #any) ifTrue:[
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   194
				quickCheck := true
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   195
			    ] ifFalse:[
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   196
				matchLast == (aString at:sStop) ifTrue:[
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   197
				    quickCheck := true
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   198
				] ifFalse:[
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   199
				    matchLast isString ifTrue:[
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   200
					quickCheck := matchLast includes:(aString at:sStop)
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   201
				    ]
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   202
				]
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   203
			    ]
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   204
			]
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   205
		    ].
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   206
		    quickCheck ifFalse:[
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   207
			"
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   208
			 no quick check possible;
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   209
			 loop over all possible substrings
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   210
			"
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   211
			index := sStart.
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   212
			[index <= sStop] whileTrue:[
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   213
			    (self matchScan:matchScanArray 
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   214
				  from:(mStart + 1) 
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   215
				  to:mStop 
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   216
				  with:aString 
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   217
				  from:index 
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   218
				  to:stop 
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   219
				  ignoreCase:ignoreCase) ifTrue:[
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   220
				^ true
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   221
			    ].
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   222
			    index := index + 1
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   223
			].
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   224
			^ false
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   225
		    ].
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   226
		    "
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   227
		     quickCheck ok, advance from the right
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   228
		    "
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   229
		    mStop := mStop - 1.
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   230
		    sStop := sStop - 1
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   231
		] ifFalse:[
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   232
		    (matchEntry isString) ifTrue:[
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   233
			"testString empty -> no match"
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   234
			(sSize == 0) ifTrue:[^ false].
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   235
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   236
			included := false.
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   237
			"/ checkChar := aString at:sStart.
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   238
			included := matchEntry includes:checkChar.
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   239
			included ifFalse:[
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   240
			    ignoreCase ifTrue:[
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   241
				checkChar isUppercase ifTrue:[
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   242
				    included := matchEntry includes:checkChar asLowercase.
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   243
				] ifFalse:[
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   244
				    included := matchEntry includes:checkChar asUppercase.
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   245
				]
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   246
			    ].
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   247
			].
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   248
			mStart := mStart + 1.
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   249
			mSize := mSize - 1.
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   250
			included ifFalse:[^ false].
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   251
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   252
			((sSize == 1) and:[mSize == 0]) ifTrue:[^ true].
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   253
			"cut off 1st char and continue"
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   254
			sStart := sStart + 1
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   255
		    ] ifFalse:[
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   256
			"/ must be single character
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   257
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   258
			"testString empty ?"
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   259
			(sSize == 0) ifTrue:[^ false].
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   260
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   261
			"first characters equal ?"
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   262
			"/ checkChar := aString at:sStart.
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   263
			ignoreCase ifFalse:[^ false].
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   264
			(checkChar asUppercase ~~ matchEntry asUppercase) ifTrue:[^ false].
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   265
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   266
			"advance and continue"
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   267
			mStart := mStart + 1.
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   268
			sStart := sStart + 1
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   269
		    ]
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   270
		]
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   271
	    ]
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   272
	]
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
   273
    ]
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   274
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   275
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   276
matchScanArrayFrom:aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   277
    "scan a pattern string and decompose it into a scanArray.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   278
     This is processed faster (especially with character ranges), and
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   279
     can also be reused later. (if the same pattern is to be searched again)"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   280
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   281
    |coll 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   282
     idx "{ Class: SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   283
     end c1 c2 matchSet previous|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   284
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   285
    coll := OrderedCollection new.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   286
    idx := 1. end := aString size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   287
    [idx <= end] whileTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   288
	|char this|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   289
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   290
	char := aString at:idx.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   291
	char == $* ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   292
	    previous ~~ #anyString ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   293
		this := #anyString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   294
	    ]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   295
	] ifFalse:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   296
	    char == $# ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   297
		previous ~~ #anyString ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   298
		    this := #any
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   299
		]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   300
	    ] ifFalse:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   301
		char == $[ ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   302
		    matchSet := IdentitySet new.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   303
		    idx := idx + 1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   304
		    idx > end ifTrue:[^ nil].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   305
		    char := aString at:idx.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   306
		    c1 := nil.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   307
		    [char ~~ $]] whileTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   308
			((char == $-) and:[c1 notNil]) ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   309
			    idx := idx + 1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   310
			    idx > end ifTrue:[^ nil].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   311
			    c2 := aString at:idx.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   312
			    (c1 to:c2) do:[:c | matchSet add:c].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   313
			    c1 := nil.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   314
			    idx := idx + 1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   315
			] ifFalse:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   316
			    (char ~~ $]) ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   317
				matchSet add:char.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   318
				c1 := char.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   319
				idx := idx + 1
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   320
			    ]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   321
			].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   322
			idx > end ifTrue:[^ nil].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   323
			char := aString at:idx
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   324
		    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   325
		    this := matchSet asString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   326
		] ifFalse:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   327
		    this := char
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   328
		]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   329
	    ]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   330
	].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   331
	this notNil ifTrue:[coll add:this. previous := this].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   332
	idx := idx + 1
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   333
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   334
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   335
    ^ coll asArray
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   336
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   337
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   338
     String matchScanArrayFrom:'*ute*'  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   339
     String matchScanArrayFrom:'**ute**'  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   340
     String matchScanArrayFrom:'*uter'   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   341
     String matchScanArrayFrom:'[cC]#mpute[rR]'  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   342
     String matchScanArrayFrom:'[abcd]*'      
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   343
     String matchScanArrayFrom:'[a-k]*'      
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   344
     String matchScanArrayFrom:'*some*compl*ern*' 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   345
     String matchScanArrayFrom:'[a-'  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   346
     String matchScanArrayFrom:'[a-zA-Z]'  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   347
     String matchScanArrayFrom:'[a-z01234A-Z]'  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   348
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   349
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   350
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   351
!CharacterArray methodsFor:'Compatibility - ST/V'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   352
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   353
byteAt:index put:aByte
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   354
    "store a byte at given index.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   355
     This is an ST/V compatibility method."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   356
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   357
    (aByte == 0) ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   358
	"store a space instead"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   359
	^ super basicAt:index put:(Character space)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   360
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   361
    ^ super at:index put:(Character value:aByte)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   362
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   363
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   364
replChar:oldChar with:newChar
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   365
    "return a copy of the receiver, with all oldChars replaced
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   366
     by newChar.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   367
     This is an ST/V compatibility method."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   368
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   369
    ^ self copy replaceAll:oldChar by:newChar
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   370
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   371
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   372
     '12345678901234567890' replChar:$0 with:$* 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   373
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   374
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   375
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   376
replChar:oldChar withString:newString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   377
    "return a copy of the receiver, with all oldChars replaced
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   378
     by newString (i.e. slice in the newString in place of the oldChar).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   379
     This is an ST/V compatibility method."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   380
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   381
    |tmpStream|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   382
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   383
    tmpStream := WriteStream on:(self class new).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   384
    self do:[:element |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   385
	element = oldChar ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   386
	    tmpStream nextPutAll:newString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   387
	] ifFalse:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   388
	    tmpStream nextPut:element 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   389
	].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   390
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   391
    ^ tmpStream contents
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   392
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   393
   "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   394
     '12345678901234567890' replChar:$0 withString:'foo' 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   395
     'a string with spaces' replChar:$  withString:' foo '  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   396
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   397
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   398
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   399
trimBlanks
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   400
    "return a copy of the receiver without leading
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   401
     and trailing spaces.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   402
     This is an ST/V compatibility method."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   403
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   404
    ^ self withoutSpaces
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   405
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   406
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   407
     '    spaces at beginning' trimBlanks     
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   408
     'spaces at end    ' trimBlanks           
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   409
     '    spaces at beginning and end     ' trimBlanks    
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   410
     'no spaces' trimBlanks              
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   411
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   412
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   413
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   414
!CharacterArray methodsFor:'Compatibility - VisualAge'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   415
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   416
addLineDelimiter
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   417
    "replace all '\'-characters by line delimiter (cr) - characters.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   418
     This has been added for VisualAge compatibility."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   419
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   420
    ^ self withCRs
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   421
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   422
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   423
bindWith:aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   424
    "return a copy of the receiver, where a '%1' escape is
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   425
     replaced by aString.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   426
     This has been added for VisualAge compatibility."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   427
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   428
    ^ self expandPlaceholdersWith:(Array with:aString)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   429
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   430
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   431
     'do you like %1 ?' bindWith:'smalltalk'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   432
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   433
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   434
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   435
bindWith:string1 with:string2
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   436
    "return a copy of the receiver, where a '%1' escape is
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   437
     replaced by string1 and '%2' is replaced by string2.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   438
     This has been added for VisualAge compatibility."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   439
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   440
    ^ self expandPlaceholdersWith:(Array with:string1 with:string2)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   441
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   442
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   443
     'do you prefer %1 or rather %2 ?'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   444
	bindWith:'smalltalk' with:'c++'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   445
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   446
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   447
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   448
bindWith:str1 with:str2 with:str3
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   449
    "return a copy of the receiver, where a '%1', '%2' and '%3' escapes
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   450
     are replaced by str1, str2 and str3 respectively.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   451
     This has been added for VisualAge compatibility."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   452
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   453
    ^ self expandPlaceholdersWith:(Array with:str1 with:str2 with:str3)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   454
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   455
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   456
     'do you prefer %1 or rather %2 (not talking about %3) ?'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   457
	bindWith:'smalltalk' with:'c++' with:'c'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   458
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   459
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   460
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   461
bindWith:str1 with:str2 with:str3 with:str4
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   462
    "return a copy of the receiver, where a '%1', '%2', '%3' and '%4' escapes
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   463
     are replaced by str1, str2, str3 and str4 respectively.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   464
     This has been added for VisualAge compatibility."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   465
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   466
    ^ self expandPlaceholdersWith:(Array with:str1 with:str2 with:str3 with:str4)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   467
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   468
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   469
     'do you prefer %1 or rather %2 (not talking about %3 or even %4) ?'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   470
	bindWith:'smalltalk' with:'c++' with:'c' with:'assembler'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   471
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   472
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   473
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   474
bindWithArguments:anArrayOfStrings
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   475
    "return a copy of the receiver, where a '%i' escape
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   476
     is replaced by the coresponding string from the argument array.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   477
     'i' may be between 1 and 9 (i.e. a maximum of 9 placeholders is allowed).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   478
     This has been added for VisualAge compatibility."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   479
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   480
    ^ self expandPlaceholdersWith:anArrayOfStrings
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   481
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   482
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   483
     'do you prefer %1 or rather %2 (not talking about %3) ?'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   484
	bindWithArguments:#('smalltalk' 'c++' 'c')
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   485
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   486
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   487
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   488
subStrings
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   489
    "return an array consisting of all words contained in the receiver.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   490
     Words are separated by whitespace.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   491
     This has been added for VisualAge compatibility."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   492
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   493
    ^ self asCollectionOfWords
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   494
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   495
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   496
     'hello world, this is smalltalk' subStrings
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   497
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   498
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   499
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   500
subStrings:separatorCharacter
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   501
    "return an array consisting of all words contained in the receiver.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   502
     Words are separated by separatorCharacter.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   503
     This has been added for VisualAge compatibility."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   504
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   505
    ^ self asCollectionOfSubstringsSeparatedBy:separatorCharacter
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   506
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   507
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   508
     'foo:bar:baz:smalltalk' subStrings:$:
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   509
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   510
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   511
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   512
trimSeparators
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   513
    "return a copy of the receiver without leading and trailing whiteSpace"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   514
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   515
    ^ self withoutSeparators
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   516
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   517
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   518
!CharacterArray methodsFor:'character searching'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   519
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   520
includesMatchCharacters
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   521
    "return true if the receiver includes any meta characters (i.e. $* or $#) 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   522
     for match operations; false if not"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   523
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   524
    ^ self includesAny:'*#['
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   525
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   526
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   527
indexOfNonSeparatorStartingAt:startIndex
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   528
    "return the index of the next non-whitespace character"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   529
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   530
    |start  "{ Class: SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   531
     mySize "{ Class: SmallInteger }"|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   532
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   533
    start := startIndex.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   534
    mySize := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   535
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   536
    start to:mySize do:[:index |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   537
	(self at:index) isSeparator ifFalse:[^ index]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   538
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   539
    ^ 0
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   540
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   541
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   542
     '    hello world' indexOfNonSeparatorStartingAt:1 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   543
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   544
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   545
     |s index1 index2|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   546
     s := '   foo    bar      baz'.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   547
     index1 := s indexOfNonSeparatorStartingAt:1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   548
     index2 := s indexOfSeparatorStartingAt:index1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   549
     s copyFrom:index1 to:index2 - 1
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   550
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   551
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   552
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   553
indexOfSeparator
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   554
    "return the index of the first whitespace character"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   555
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   556
    ^ self indexOfSeparatorStartingAt:1
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   557
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   558
    "'hello world' indexOfSeparator"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   559
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   560
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   561
indexOfSeparatorStartingAt:startIndex
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   562
    "return the index of the next whitespace character"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   563
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   564
    |start  "{ Class: SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   565
     mySize "{ Class: SmallInteger }"|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   566
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   567
    start := startIndex.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   568
    mySize := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   569
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   570
    start to:mySize do:[:index |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   571
	(self at:index) isSeparator ifTrue:[^ index]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   572
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   573
    ^ 0
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   574
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   575
    "'hello world' indexOfSeparatorStartingAt:3"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   576
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   577
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   578
!CharacterArray methodsFor:'comparing'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   579
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   580
< something
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   581
    "Compare the receiver with the argument and return true if the
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   582
     receiver is less than the argument. Otherwise return false."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   583
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   584
    ^ (something > self)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   585
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   586
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   587
<= something
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   588
    "Compare the receiver with the argument and return true if the
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   589
     receiver is less than or equal to the argument. Otherwise return false."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   590
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   591
    ^ (self > something) not
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   592
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   593
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   594
= aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   595
    "Compare the receiver with the argument and return true if the
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   596
     receiver is equal to the argument. Otherwise return false.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   597
     This compare does NOT ignore case differences, 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   598
     therefore 'foo' = 'Foo' will return false.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   599
     Since this is incompatible to ST-80 (at least, V2.x) , this may change."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   600
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   601
    |mySize    "{ Class: SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   602
     otherSize |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   603
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   604
    aString species == self species ifFalse:[^ false].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   605
    mySize := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   606
    otherSize := aString size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   607
    mySize == otherSize ifFalse:[^ false].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   609
    1 to:mySize do:[:index |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   610
	(self at:index) = (aString at:index) ifFalse:[^ false].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   611
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   612
    ^ true
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   613
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   614
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   615
     'foo' = 'Foo'  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   616
     'foo' = 'bar'  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   617
     'foo' = 'foo'   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   618
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   619
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   620
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   621
> aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   622
    "Compare the receiver with the argument and return true if the
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   623
     receiver is greater than the argument. Otherwise return false.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   624
     In contrast to ST-80, case differences are NOT ignored, thus
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   625
     'foo' > 'Foo' will return true; use #sameAs: to compare ignoring cases.. 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   626
     Since this is incompatible to ST-80, this may change."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   627
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   628
    |mySize    "{ Class: SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   629
     otherSize "{ Class: SmallInteger }" 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   630
     n         "{ Class: SmallInteger }" 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   631
     c1 c2|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   632
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   633
    mySize := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   634
    otherSize := aString size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   635
    n := mySize min:otherSize.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   636
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   637
    1 to:n do:[:index |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   638
	c1 := self at:index.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   639
	c2 := aString at:index.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   640
	c1 > c2 ifTrue:[^ true].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   641
	c1 < c2 ifTrue:[^ false].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   642
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   643
    ^ mySize > otherSize
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   644
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   645
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   646
>= something
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   647
    "Compare the receiver with the argument and return true if the
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   648
     receiver is greater than or equal to the argument.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   649
     Otherwise return false."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   650
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   651
    ^ (something > self) not
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   652
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   653
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   654
compareWith:aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   655
    "Compare the receiver with the argument and return 1 if the receiver is
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   656
     greater, 0 if equal and -1 if less than the argument. 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   657
     Case differences are NOT ignored, thus
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   658
     'foo' compareWith: 'Foo' will return 1."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   659
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   660
    |mySize    "{ Class: SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   661
     otherSize "{ Class: SmallInteger }" 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   662
     n         "{ Class: SmallInteger }" 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   663
     c1 c2|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   664
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   665
    mySize := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   666
    otherSize := aString size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   667
    n := mySize min:otherSize.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   668
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   669
    1 to:n do:[:index |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   670
	c1 := self at:index.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   671
	c2 := aString at:index.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   672
	c1 > c2 ifTrue:[^ 1].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   673
	c1 < c2 ifTrue:[^ -1].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   674
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   675
    mySize > otherSize ifTrue:[^ 1].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   676
    mySize < otherSize ifTrue:[^ -1].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   677
    ^ 0
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   678
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   679
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   680
hash
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   681
    "return an integer useful as a hash-key"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   682
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   683
%{  /* NOCONTEXT */
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   684
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   685
    REGISTER int g, val;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   686
    REGISTER unsigned char *cp, *cp0;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   687
    int l;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   688
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   689
    cp = _stringVal(self);
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   690
    l = _stringSize(self);
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   691
    if (__qClass(self) != String) {
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   692
	int n = __OBJS2BYTES__(_intVal(_ClassInstPtr(__qClass(self))->c_ninstvars));
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   693
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   694
	cp += n;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   695
	l -= n;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   696
    }
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   697
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   698
    /*
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   699
     * this is the dragon-book algorithm with a funny start
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   700
     * value (to give short strings a number above 8192)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   701
     */
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   702
    val = 12345;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   703
    for (cp0 = cp, cp += l - 1; cp >= cp0; cp--) {
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   704
	val = (val << 5) + (*cp & 0x1F);
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   705
	if (g = (val & 0x3E000000))
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   706
	    val ^= g >> 25 /* 23 */ /* 25 */;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   707
	val &= 0x3FFFFFFF;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   708
    }
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   709
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   710
    if (l) {
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   711
	l |= 1; 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   712
	val = (val * l) & 0x3FFFFFFF;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   713
    }
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   714
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   715
    RETURN ( _MKSMALLINT(val) );
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   716
%}
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   717
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   718
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   719
sameAs:aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   720
    "Compare the receiver with the argument like =, but ignore
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   721
     case differences. Return true or false."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   722
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   723
    |mySize "{ Class: SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   724
     otherSize c1 c2|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   725
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   726
    mySize := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   727
    otherSize := aString size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   728
    mySize == otherSize ifFalse:[^ false].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   729
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   730
    1 to:mySize do:[:index |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   731
	c1 := self at:index.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   732
	c2 := aString at:index.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   733
	c1 == c2 ifFalse:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   734
	    c1 asLowercase = c2 asLowercase ifFalse:[^ false].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   735
	]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   736
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   737
    ^ true
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   738
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   739
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   740
     'foo' sameAs: 'Foo'   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   741
     'foo' sameAs: 'bar' 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   742
     'foo' sameAs: 'foo'   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   743
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   744
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   745
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   746
sameCharacters:aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   747
    "count & return the number of characters which are the same
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   748
     (ignoring case) in the receiver and the argument, aString."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   749
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   750
    |n "{ Class: SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   751
     otherSize c1 c2 cnt|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   752
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   753
    n := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   754
    n := n min:(aString size).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   755
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   756
    cnt := 0.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   757
    1 to:n do:[:index |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   758
	c1 := self at:index.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   759
	c2 := aString at:index.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   760
	((c1 == c2)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   761
	or:[c1 asLowercase = c2 asLowercase]) ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   762
	    cnt := cnt + 1
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   763
	]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   764
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   765
    ^ cnt
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   766
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   767
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   768
     'foobarbaz' sameCharacters: 'foo'   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   769
     'foobarbaz' sameCharacters: 'Foo'   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   770
     'foobarbaz' sameCharacters: 'baz'   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   771
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   772
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   773
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   774
!CharacterArray methodsFor:'converting'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   775
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   776
asArrayOfSubstrings
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   777
    "return an array of substrings from the receiver, interpreting
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   778
     separators (i.e. spaces & newlines) as word-delimiters.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   779
     This is a compatibility method - the actual work is done in
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   780
     asCollectionOfWords."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   781
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   782
    ^ self asCollectionOfWords asArray
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   783
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   784
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   785
     '1 one two three four 5 five' asArrayOfSubstrings  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   786
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   787
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   788
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   789
asCollectionOfLines
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   790
    "return a collection containing the lines (separated by cr) 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   791
     of the receiver. If multiple cr's occur in a row, the result will
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   792
     contain empty strings."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   793
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   794
    ^ self asCollectionOfSubstringsSeparatedBy:Character cr
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   795
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   796
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   797
     '1 one\2 two\3 three\4 four\5 five' withCRs asCollectionOfLines
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   798
     '1 one\\\\2 two\3 three' withCRs asCollectionOfLines  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   799
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   800
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   801
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   802
asCollectionOfSubstringsSeparatedBy:aCharacter
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   803
    "return a collection containing the lines (separated by aCharacter) 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   804
     of the receiver. If aCharacter occurs multiple times in a row, 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   805
     the result will contain empty strings."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   806
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   807
    |lines myClass
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   808
     numberOfLines "{ Class:SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   809
     startIndex    "{ Class:SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   810
     stopIndex     "{ Class:SmallInteger }" |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   811
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   812
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   813
     count first, to avoid regrowing of the OC
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   814
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   815
    numberOfLines := (self occurrencesOf:aCharacter) + 1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   816
    lines := OrderedCollection new:numberOfLines.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   817
    myClass := self species.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   818
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   819
    startIndex := 1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   820
    1 to:numberOfLines do:[:lineNr |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   821
	stopIndex := self indexOf:aCharacter startingAt:startIndex.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   822
	stopIndex == 0 ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   823
	    stopIndex := self size
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   824
	] ifFalse: [
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   825
	    stopIndex := stopIndex - 1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   826
	].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   827
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   828
	(stopIndex < startIndex) ifTrue: [
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   829
	    lines add:(myClass new:0)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   830
	] ifFalse: [
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   831
	    lines add:(self copyFrom:startIndex to:stopIndex)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   832
	].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   833
	startIndex := stopIndex + 2
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   834
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   835
    ^ lines
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   836
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   837
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   838
     '1 one:2 two:3 three:4 four:5 five' withCRs asCollectionOfSubstringsSeparatedBy:$: 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   839
     '1 one 2 two 3 three 4 four 5 five' withCRs asCollectionOfSubstringsSeparatedBy:Character space
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   840
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   841
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   842
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   843
asCollectionOfSubstringsSeparatedByAny:aCollectionOfSeparators
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   844
    "return a collection containing the words (separated by any character
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   845
     from aCollectionOfSeparators) of the receiver.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   846
     This allows breaking up strings using any character as separator."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   847
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   848
    |words
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   849
     start  "{ Class:SmallInteger }" 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   850
     stop   "{ Class:SmallInteger }" 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   851
     mySize "{ Class:SmallInteger }"|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   852
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   853
    words := OrderedCollection new.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   854
    start := 1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   855
    mySize := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   856
    [start <= mySize] whileTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   857
	"skip multiple separators"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   858
	[aCollectionOfSeparators includes:(self at:start)] whileTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   859
	    start := start + 1 .
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   860
	    start > mySize ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   861
		^ words
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   862
	    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   863
	].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   864
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   865
	stop := self indexOfAny:aCollectionOfSeparators startingAt:start.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   866
	stop == 0 ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   867
	    words add:(self copyFrom:start to:mySize).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   868
	    ^ words
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   869
	].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   870
	words add:(self copyFrom:start to:(stop - 1)).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   871
	start := stop
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   872
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   873
    ^ words
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   874
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   875
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   876
     'hello:world:isnt:this nice' asCollectionOfSubstringsSeparatedByAny:#($:)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   877
     'hello:world:isnt:this nice' asCollectionOfSubstringsSeparatedByAny:':' 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   878
     'hello:world:isnt:this nice' asCollectionOfSubstringsSeparatedByAny:(Array with:$: with:Character space) 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   879
     'hello:world:isnt:this nice' asCollectionOfSubstringsSeparatedByAny:': ' 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   880
     'h1e2l3l4o' asCollectionOfSubstringsSeparatedByAny:($1 to: $9) 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   881
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   882
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   883
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   884
asCollectionOfWords
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   885
    "return a collection containing the words (separated by whitespace) 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   886
     of the receiver. Multiple occurences of whitespace characters will
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   887
     be treated like one - i.e. whitespace is skipped."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   888
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   889
    |words
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   890
     start  "{ Class:SmallInteger }" 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   891
     stop   "{ Class:SmallInteger }" 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   892
     mySize "{ Class:SmallInteger }"|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   893
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   894
    words := OrderedCollection new.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   895
    start := 1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   896
    mySize := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   897
    [start <= mySize] whileTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   898
	start := self indexOfNonSeparatorStartingAt:start.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   899
	start == 0 ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   900
	    ^ words
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   901
	].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   902
	stop := self indexOfSeparatorStartingAt:start.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   903
	stop == 0 ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   904
	    words add:(self copyFrom:start to:mySize).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   905
	    ^ words
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   906
	].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   907
	words add:(self copyFrom:start to:(stop - 1)).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   908
	start := stop
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   909
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   910
    ^ words
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   911
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   912
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   913
     'hello world isnt this nice' asCollectionOfWords
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   914
     '    hello    world   isnt   this   nice  ' asCollectionOfWords
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   915
     'hello' asCollectionOfWords
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   916
     '' asCollectionOfWords
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   917
     '      ' asCollectionOfWords
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   918
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   919
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   920
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   921
asComposedText
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   922
    ^ ComposedText fromString:self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   923
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   924
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   925
asFilename
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   926
    "return a Filename with pathname taken from the receiver"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   927
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   928
    ^ Filename named:self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   929
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   930
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   931
asFloat
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   932
    "read a float number from the receiver.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   933
     Notice, that errors may occur during the read, so you better
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   934
     setup some signal handler when using this method."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   935
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   936
    ^ (Number readFromString:self) asFloat
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   937
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   938
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   939
     '0.123' asFloat 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   940
     '12345' asFloat
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   941
     '(1/5)' asFloat
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   942
     Object errorSignal handle:[:ex | ex returnWith:0] do:['foo' asFloat] 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   943
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   944
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   945
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   946
asInteger
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   947
    "read an integer from the receiver.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   948
     Notice, that errors may occur during the read, so you better
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   949
     setup some signal handler when using this method."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   950
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   951
    ^ Integer readFromString:self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   952
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   953
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   954
     '12345678901234567890' asInteger
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   955
     '-1234' asInteger
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   956
     '0.123' asInteger   <- reader stops at ., returning 0 here
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   957
     '0.123' asNumber    <- returns what you expect
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   958
     Object errorSignal handle:[:ex | ex returnWith:0] do:['foo' asInteger] 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   959
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   960
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   961
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   962
asLowercase
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   963
    "return a copy of myself in lowercase letters"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   964
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   965
    |newStr
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   966
     mySize "{ Class: SmallInteger }" |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   967
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   968
    mySize := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   969
    newStr := self species new:mySize.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   970
    1 to:mySize do:[:i |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   971
	newStr at:i put:(self at:i) asLowercase
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   972
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   973
    ^ newStr
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   974
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   975
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   976
     'HelloWorld' asLowercase   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   977
     'HelloWorld' asLowercaseFirst   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   978
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   979
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   980
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   981
asLowercaseFirst
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   982
    "return a copy of myself where the first character is
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   983
     converted to lowercase."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   984
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   985
    |newString sz|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   986
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   987
    sz := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   988
    newString := self copyFrom:1 to:sz.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   989
    sz > 0 ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   990
	newString at:1 put:(newString at:1) asLowercase
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   991
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   992
    ^ newString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   993
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   994
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   995
     'HelloWorld' asLowercase   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   996
     'HelloWorld' asLowercaseFirst   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   997
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   998
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
   999
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1000
asNumber
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1001
    "read a number from the receiver.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1002
     Notice, that (in contrast to ST-80) errors may occur during the read, 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1003
     so you better setup some signal handler when using this method.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1004
     This may change if ANSI specifies it."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1005
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1006
"/ ST-80 behavior:
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1007
"/  ^ Number readFromString:self onError:0
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1008
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1009
    ^ Number readFromString:self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1010
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1011
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1012
     '123'     asNumber
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1013
     '123.567' asNumber
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1014
     '(5/6)'   asNumber
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1015
     'foo'     asNumber
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1016
     Object errorSignal handle:[:ex | ex returnWith:0] do:['foo' asNumber] 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1017
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1018
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1019
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1020
asNumberFromFormatString:ignored
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1021
    "read a number from the receiver, ignoring any nonDigit characters.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1022
     This is typically used to convert from strings which include
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1023
     dollar-signs or millenium digits. However, this method also ignores
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1024
     the decimal point (if any) and therefore should be used with care."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1025
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1026
    |tempString|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1027
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1028
    tempString := self collect:[:char | char isDigit].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1029
    ^ Number readFromString:tempString onError:0
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1030
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1031
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1032
     'USD 123' asNumberFromFormatString:'foo'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1033
     'DM 123'  asNumberFromFormatString:'foo'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1034
     '123'     asNumberFromFormatString:'foo'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1035
     '123.567' asNumberFromFormatString:'foo'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1036
     '(5/6)'   asNumberFromFormatString:'foo'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1037
     'foo'     asNumberFromFormatString:'foo'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1038
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1039
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1040
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1041
asSingleByteString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1042
    "return the receiver converted to a 'normal' string"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1043
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1044
    ^ String fromString:self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1045
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1046
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1047
asString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1048
    "return myself - I am a string"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1049
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1050
    ^ self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1051
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1052
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1053
asStringCollection
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1054
    "return a collection of lines from myself."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1055
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1056
    ^ StringCollection from:self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1057
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1058
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1059
asTwoByteString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1060
    "return the receiver converted to a two-byte string"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1061
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1062
    ^ TwoByteString fromString:self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1063
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1064
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1065
asUppercase
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1066
    "return a copy of myself in uppercase letters"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1067
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1068
    |newStr
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1069
     mySize "{ Class: SmallInteger }" |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1070
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1071
    mySize := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1072
    newStr := self species new:mySize.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1073
    1 to:mySize do:[:i |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1074
	newStr at:i put:(self at:i) asUppercase
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1075
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1076
    ^ newStr
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1077
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1078
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1079
     'helloWorld' asUppercase      
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1080
     'helloWorld' asUppercaseFirst 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1081
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1082
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1083
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1084
asUppercaseFirst
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1085
    "return a copy of myself where the first character is
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1086
     converted to uppercase."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1087
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1088
    |newString sz|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1089
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1090
    sz := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1091
    newString := self copyFrom:1 to:sz.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1092
    sz > 0 ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1093
	newString at:1 put:(newString at:1) asUppercase
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1094
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1095
    ^ newString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1096
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1097
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1098
     'helloWorld' asUppercase      
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1099
     'helloWorld' asUppercaseFirst 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1100
     'HelloWorld' asUppercaseFirst   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1101
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1102
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1103
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1104
replaceFrom:aString decode:encoding 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1105
    "this is an experimental interface - unfinished"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1106
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1107
    |table|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1108
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1109
    table := self class decoderTableFor:encoding.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1110
    table isNil ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1111
	^ self replaceFrom:aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1112
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1113
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1114
    1 to:self size do:[:index |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1115
	|char oldCode newCode|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1116
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1117
	char := aString at:index.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1118
	oldCode := char asciiValue.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1119
	newCode := table at:(oldCode + 1).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1120
	newCode ~~ oldCode ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1121
	    self at:index put:(Character value:newCode)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1122
	]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1123
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1124
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1125
    "Created: 20.10.1995 / 23:00:09 / cg"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1126
    "Modified: 20.10.1995 / 23:08:16 / cg"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1127
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1128
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1129
string
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1130
    ^ self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1131
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1132
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1133
tokensBasedOn:aCharacter
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1134
    "this is an ST-80 alias for the ST/X method
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1135
	asCollectionOfSubstringsSeparatedBy:"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1136
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1137
    ^ self asCollectionOfSubstringsSeparatedBy:aCharacter
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1138
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1139
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1140
     'hello:world:isnt:this nice' tokensBasedOn:$:
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1141
     'foo,bar,baz' tokensBasedOn:$,
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1142
     '/etc/passwd' asFilename readStream nextLine tokensBasedOn:$:
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1143
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1144
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1145
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1146
!CharacterArray methodsFor:'copying'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1147
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1148
concatenate:string1 and:string2
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1149
    "return the concatenation of myself and the arguments, string1 and string2.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1150
     This is equivalent to self , string1 , string2
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1151
     - generated by compiler when such a construct is detected and the receiver
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1152
     is known to be a string."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1153
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1154
    ^ self , string1 , string2
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1155
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1156
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1157
concatenate:string1 and:string2 and:string3
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1158
    "return the concatenation of myself and the string arguments.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1159
     This is equivalent to self , string1 , string2 , string3
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1160
     - generated by compiler when such a construct is detected and the receiver
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1161
     is known to be a string."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1162
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1163
    ^ self , string1 , string2 , string3
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1164
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1165
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1166
!CharacterArray methodsFor:'displaying'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1167
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1168
displayOn:aGc x:x y:y
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1169
    "display the receiver in a graphicsContext - this method allows
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1170
     strings to be used like DisplayObjects."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1171
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1172
    ^ aGc displayString:self x:x y:y.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1173
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1174
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1175
!CharacterArray methodsFor:'padded copying'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1176
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1177
leftPaddedTo:size
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1178
    "return a new string of length size, which contains the receiver
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1179
     right-adjusted (i.e. padded on the left).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1180
     Characters on the left are filled with spaces.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1181
     If the receivers size is equal or greater than the length argument, 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1182
     the original receiver is returned unchanged."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1183
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1184
    ^ self leftPaddedTo:size with:(Character space)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1185
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1186
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1187
     'foo' leftPaddedTo:10  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1188
     'fooBar' leftPaddedTo:5      
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1189
     123 printString leftPaddedTo:10        
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1190
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1191
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1192
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1193
leftPaddedTo:size with:padCharacter
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1194
    "return a new string of length size, which contains the receiver
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1195
     right-adjusted (i.e. padded on the left).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1196
     Characters on the left are filled with padCharacter.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1197
     If the receivers size is equal or greater than the length argument, 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1198
     the original receiver is returned unchanged."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1199
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1200
    |len s|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1201
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1202
    len := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1203
    (len < size) ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1204
	s := self species new:size withAll:padCharacter.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1205
	s replaceFrom:(size - len + 1) with:self.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1206
	^ s
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1207
    ]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1208
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1209
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1210
     'foo' leftPaddedTo:10 with:$.      
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1211
     'fooBar' leftPaddedTo:5 with:$.      
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1212
     123 printString leftPaddedTo:10 with:$.        
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1213
     (' ' , 123 printString) leftPaddedTo:10 with:$.        
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1214
     (Float pi printString) leftPaddedTo:15 with:(Character space)  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1215
     (Float pi printString) leftPaddedTo:15 with:$-           
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1216
     (' ' , Float pi class name) leftPaddedTo:15 with:$.     
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1217
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1218
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1219
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1220
paddedTo:newSize
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1221
     "return a new string consisting of the receivers characters,
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1222
     plus spaces up to length.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1223
     If the receivers size is equal or greater than the length argument, 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1224
     the original receiver is returned unchanged."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1225
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1226
     ^ self paddedTo:newSize with:(Character space)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1227
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1228
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1229
     'foo' paddedTo:10            
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1230
     123 printString paddedTo:10 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1231
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1232
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1233
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1234
paddedTo:newSize with:padCharacter
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1235
    "return a new string consisting of the receivers characters,
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1236
     plus pad characters up to length.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1237
     If the receivers size is equal or greater than the length argument, 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1238
     the  original receiver is returned unchanged."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1239
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1240
    |s len|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1241
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1242
    len := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1243
    len < newSize ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1244
	s := self species new:newSize withAll:padCharacter.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1245
	s replaceFrom:1 to:len with:self.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1246
	^ s
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1247
    ]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1248
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1249
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1250
     'foo' paddedTo:10 with:$.             
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1251
     123 printString paddedTo:10 with:$*   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1252
     (Float pi printString) paddedTo:15 with:(Character space)  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1253
     (Float pi printString) paddedTo:15 with:$-  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1254
     (Float pi class name , ' ') paddedTo:15 with:$.  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1255
    "
650
9aef9de12f65 added centered padding
Claus Gittinger <cg@exept.de>
parents: 629
diff changeset
  1256
!
9aef9de12f65 added centered padding
Claus Gittinger <cg@exept.de>
parents: 629
diff changeset
  1257
9aef9de12f65 added centered padding
Claus Gittinger <cg@exept.de>
parents: 629
diff changeset
  1258
centerPaddedTo:newSize
9aef9de12f65 added centered padding
Claus Gittinger <cg@exept.de>
parents: 629
diff changeset
  1259
     "return a new string consisting of the receivers characters,
9aef9de12f65 added centered padding
Claus Gittinger <cg@exept.de>
parents: 629
diff changeset
  1260
     plus spaces up to length and center the receivers characters in
9aef9de12f65 added centered padding
Claus Gittinger <cg@exept.de>
parents: 629
diff changeset
  1261
     the resulting string.
9aef9de12f65 added centered padding
Claus Gittinger <cg@exept.de>
parents: 629
diff changeset
  1262
     If the receivers size is equal or greater than the length argument, 
9aef9de12f65 added centered padding
Claus Gittinger <cg@exept.de>
parents: 629
diff changeset
  1263
     the original receiver is returned unchanged."
9aef9de12f65 added centered padding
Claus Gittinger <cg@exept.de>
parents: 629
diff changeset
  1264
9aef9de12f65 added centered padding
Claus Gittinger <cg@exept.de>
parents: 629
diff changeset
  1265
     ^ self centerPaddedTo:newSize with:(Character space)
9aef9de12f65 added centered padding
Claus Gittinger <cg@exept.de>
parents: 629
diff changeset
  1266
9aef9de12f65 added centered padding
Claus Gittinger <cg@exept.de>
parents: 629
diff changeset
  1267
    "
9aef9de12f65 added centered padding
Claus Gittinger <cg@exept.de>
parents: 629
diff changeset
  1268
     'foo' centerPaddedTo:10            
9aef9de12f65 added centered padding
Claus Gittinger <cg@exept.de>
parents: 629
diff changeset
  1269
     123 printString centerPaddedTo:10 
9aef9de12f65 added centered padding
Claus Gittinger <cg@exept.de>
parents: 629
diff changeset
  1270
    "
9aef9de12f65 added centered padding
Claus Gittinger <cg@exept.de>
parents: 629
diff changeset
  1271
9aef9de12f65 added centered padding
Claus Gittinger <cg@exept.de>
parents: 629
diff changeset
  1272
    "Created: 25.11.1995 / 10:53:57 / cg"
9aef9de12f65 added centered padding
Claus Gittinger <cg@exept.de>
parents: 629
diff changeset
  1273
!
9aef9de12f65 added centered padding
Claus Gittinger <cg@exept.de>
parents: 629
diff changeset
  1274
9aef9de12f65 added centered padding
Claus Gittinger <cg@exept.de>
parents: 629
diff changeset
  1275
centerPaddedTo:size with:padCharacter
9aef9de12f65 added centered padding
Claus Gittinger <cg@exept.de>
parents: 629
diff changeset
  1276
    "return a new string of length size, which contains the receiver
9aef9de12f65 added centered padding
Claus Gittinger <cg@exept.de>
parents: 629
diff changeset
  1277
     centered (i.e. padded on both sides).
9aef9de12f65 added centered padding
Claus Gittinger <cg@exept.de>
parents: 629
diff changeset
  1278
     Characters are filled with padCharacter.
9aef9de12f65 added centered padding
Claus Gittinger <cg@exept.de>
parents: 629
diff changeset
  1279
     If the receivers size is equal or greater than the length argument, 
9aef9de12f65 added centered padding
Claus Gittinger <cg@exept.de>
parents: 629
diff changeset
  1280
     the original receiver is returned unchanged."
9aef9de12f65 added centered padding
Claus Gittinger <cg@exept.de>
parents: 629
diff changeset
  1281
9aef9de12f65 added centered padding
Claus Gittinger <cg@exept.de>
parents: 629
diff changeset
  1282
    |len s|
9aef9de12f65 added centered padding
Claus Gittinger <cg@exept.de>
parents: 629
diff changeset
  1283
9aef9de12f65 added centered padding
Claus Gittinger <cg@exept.de>
parents: 629
diff changeset
  1284
    len := self size.
9aef9de12f65 added centered padding
Claus Gittinger <cg@exept.de>
parents: 629
diff changeset
  1285
    (len < size) ifTrue:[
9aef9de12f65 added centered padding
Claus Gittinger <cg@exept.de>
parents: 629
diff changeset
  1286
	s := self species new:size withAll:padCharacter.
9aef9de12f65 added centered padding
Claus Gittinger <cg@exept.de>
parents: 629
diff changeset
  1287
	s replaceFrom:(size - len) // 2  + 1 with:self.
9aef9de12f65 added centered padding
Claus Gittinger <cg@exept.de>
parents: 629
diff changeset
  1288
	^ s
9aef9de12f65 added centered padding
Claus Gittinger <cg@exept.de>
parents: 629
diff changeset
  1289
    ]
9aef9de12f65 added centered padding
Claus Gittinger <cg@exept.de>
parents: 629
diff changeset
  1290
9aef9de12f65 added centered padding
Claus Gittinger <cg@exept.de>
parents: 629
diff changeset
  1291
    "
9aef9de12f65 added centered padding
Claus Gittinger <cg@exept.de>
parents: 629
diff changeset
  1292
     'foo' centerPaddedTo:11 with:$.     
9aef9de12f65 added centered padding
Claus Gittinger <cg@exept.de>
parents: 629
diff changeset
  1293
     'fooBar' centerPaddedTo:5 with:$.      
9aef9de12f65 added centered padding
Claus Gittinger <cg@exept.de>
parents: 629
diff changeset
  1294
     123 printString centerPaddedTo:10 with:$.        
9aef9de12f65 added centered padding
Claus Gittinger <cg@exept.de>
parents: 629
diff changeset
  1295
     (' ' , 123 printString) centerPaddedTo:10 with:$.        
9aef9de12f65 added centered padding
Claus Gittinger <cg@exept.de>
parents: 629
diff changeset
  1296
     (Float pi printString) centerPaddedTo:15 with:(Character space)  
9aef9de12f65 added centered padding
Claus Gittinger <cg@exept.de>
parents: 629
diff changeset
  1297
     (Float pi printString) centerPaddedTo:15 with:$-           
9aef9de12f65 added centered padding
Claus Gittinger <cg@exept.de>
parents: 629
diff changeset
  1298
     (' ' , Float pi class name) centerPaddedTo:15 with:$.     
9aef9de12f65 added centered padding
Claus Gittinger <cg@exept.de>
parents: 629
diff changeset
  1299
    "
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  1300
! !
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  1301
328
claus
parents: 327
diff changeset
  1302
!CharacterArray methodsFor:'pattern matching'!
claus
parents: 327
diff changeset
  1303
claus
parents: 327
diff changeset
  1304
findMatchString:matchString
368
a3c21a89ec37 *** empty log message ***
claus
parents: 360
diff changeset
  1305
    "like findString/indexOfSubCollection, but allowing match patterns.
328
claus
parents: 327
diff changeset
  1306
     find matchstring; if found, return the index;
claus
parents: 327
diff changeset
  1307
     if not found, return 0."
claus
parents: 327
diff changeset
  1308
claus
parents: 327
diff changeset
  1309
    ^ self findMatchString:matchString startingAt:1 ignoreCase:false ifAbsent:[0] 
claus
parents: 327
diff changeset
  1310
!
claus
parents: 327
diff changeset
  1311
claus
parents: 327
diff changeset
  1312
findMatchString:matchString startingAt:index
claus
parents: 327
diff changeset
  1313
    "like findString, but allowing match patterns.
claus
parents: 327
diff changeset
  1314
     find matchstring, starting at index. if found, return the index;
claus
parents: 327
diff changeset
  1315
     if not found, return 0."
claus
parents: 327
diff changeset
  1316
claus
parents: 327
diff changeset
  1317
    ^ self findMatchString:matchString startingAt:index ignoreCase:false ifAbsent:[0] 
claus
parents: 327
diff changeset
  1318
!
claus
parents: 327
diff changeset
  1319
claus
parents: 327
diff changeset
  1320
findMatchString:matchString startingAt:index ignoreCase:ignoreCase ifAbsent:exceptionBlock
claus
parents: 327
diff changeset
  1321
    "like findString, but allowing match patterns.
claus
parents: 327
diff changeset
  1322
     find matchstring, starting at index. if found, return the index;
claus
parents: 327
diff changeset
  1323
     if not found, return the result of evaluating exceptionBlock.
claus
parents: 327
diff changeset
  1324
     This is a q&d hack - not very efficient"
claus
parents: 327
diff changeset
  1325
claus
parents: 327
diff changeset
  1326
    |firstChar 
claus
parents: 327
diff changeset
  1327
     startIndex "{ Class: SmallInteger }"
claus
parents: 327
diff changeset
  1328
     matchSize  "{ Class: SmallInteger }"
claus
parents: 327
diff changeset
  1329
     mySize     "{ Class: SmallInteger }"
claus
parents: 327
diff changeset
  1330
     realMatchString|
claus
parents: 327
diff changeset
  1331
claus
parents: 327
diff changeset
  1332
    matchSize := matchString size.
claus
parents: 327
diff changeset
  1333
    matchSize == 0 ifTrue:[^ index]. "empty string matches"
claus
parents: 327
diff changeset
  1334
claus
parents: 327
diff changeset
  1335
    realMatchString := matchString.
claus
parents: 327
diff changeset
  1336
    (realMatchString endsWith:$*) ifFalse:[
claus
parents: 327
diff changeset
  1337
	realMatchString := realMatchString , '*'.
claus
parents: 327
diff changeset
  1338
	matchSize := matchSize + 1
claus
parents: 327
diff changeset
  1339
    ].
claus
parents: 327
diff changeset
  1340
claus
parents: 327
diff changeset
  1341
    mySize := self size.
claus
parents: 327
diff changeset
  1342
    firstChar := realMatchString at:1.
claus
parents: 327
diff changeset
  1343
claus
parents: 327
diff changeset
  1344
    firstChar asString includesMatchCharacters ifTrue:[
claus
parents: 327
diff changeset
  1345
	index to:mySize do:[:col |
claus
parents: 327
diff changeset
  1346
	    (realMatchString match:self from:col to:mySize ignoreCase:ignoreCase)
claus
parents: 327
diff changeset
  1347
	    ifTrue:[^ col]
claus
parents: 327
diff changeset
  1348
	].
claus
parents: 327
diff changeset
  1349
	^ exceptionBlock value.
claus
parents: 327
diff changeset
  1350
    ].
claus
parents: 327
diff changeset
  1351
    startIndex := self indexOf:firstChar startingAt:index.
claus
parents: 327
diff changeset
  1352
    [startIndex == 0] whileFalse:[
claus
parents: 327
diff changeset
  1353
	(realMatchString match:self from:startIndex to:mySize ignoreCase:ignoreCase)
claus
parents: 327
diff changeset
  1354
	ifTrue:[^ startIndex].
claus
parents: 327
diff changeset
  1355
	startIndex := self indexOf:firstChar startingAt:(startIndex + 1)
claus
parents: 327
diff changeset
  1356
    ].
claus
parents: 327
diff changeset
  1357
    ^ exceptionBlock value
claus
parents: 327
diff changeset
  1358
claus
parents: 327
diff changeset
  1359
    "
claus
parents: 327
diff changeset
  1360
     'one two three four' findMatchString:'o[nu]'
claus
parents: 327
diff changeset
  1361
     'one two three four' findMatchString:'o[nu]' startingAt:3
claus
parents: 327
diff changeset
  1362
    "
claus
parents: 327
diff changeset
  1363
!
claus
parents: 327
diff changeset
  1364
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1365
includesMatchString:matchString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1366
    "like includesString, but allowing match patterns.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1367
     find matchstring; if found, return true, otherwise return false"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1368
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1369
    ^ (self findMatchString:matchString) ~~ 0
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1370
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1371
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1372
     'hello world' includesMatchString:'h*'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1373
     'hello world' includesMatchString:'h[aeiou]llo' 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1374
     'hello world' includesMatchString:'wor*'     
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1375
     'hello world' includesMatchString:'woR*'     
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1376
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1377
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1378
328
claus
parents: 327
diff changeset
  1379
match:aString
claus
parents: 327
diff changeset
  1380
    "return true if aString matches self, where self may contain meta-match 
claus
parents: 327
diff changeset
  1381
     characters $* (to match any string) or $# (to match any character).
claus
parents: 327
diff changeset
  1382
     or [...] to match a set of characters.
345
claus
parents: 343
diff changeset
  1383
     Lower/uppercase are considered different.
claus
parents: 343
diff changeset
  1384
     NOTICE: match-meta character interpretation is like in unix-matching, 
claus
parents: 343
diff changeset
  1385
	     NOT the ST-80 meaning."
328
claus
parents: 327
diff changeset
  1386
claus
parents: 327
diff changeset
  1387
    ^ self match:aString from:1 to:aString size ignoreCase:false
claus
parents: 327
diff changeset
  1388
claus
parents: 327
diff changeset
  1389
    "
claus
parents: 327
diff changeset
  1390
     '*ute*' match:'computer' 
claus
parents: 327
diff changeset
  1391
     '*uter' match:'computer' 
claus
parents: 327
diff changeset
  1392
     'uter*' match:'computer' 
claus
parents: 327
diff changeset
  1393
     '*ute*' match:'' 
claus
parents: 327
diff changeset
  1394
     '[abcd]*' match:'computer' 
claus
parents: 327
diff changeset
  1395
     '[abcd]*' match:'komputer' 
claus
parents: 327
diff changeset
  1396
     '*some*compl*ern*' match:'this is some more complicated pattern match' 
claus
parents: 327
diff changeset
  1397
     '*some*compl*ern*' match:'this is another complicated pattern match' 
claus
parents: 327
diff changeset
  1398
    "
claus
parents: 327
diff changeset
  1399
!
claus
parents: 327
diff changeset
  1400
claus
parents: 327
diff changeset
  1401
match:aString from:start to:stop ignoreCase:ignoreCase
claus
parents: 327
diff changeset
  1402
    "return true if part of aString matches myself, 
claus
parents: 327
diff changeset
  1403
     where self may contain meta-match 
claus
parents: 327
diff changeset
  1404
     characters $* (to match any string) or $# (to match any character)
claus
parents: 327
diff changeset
  1405
     or [...] to match a set of characters.
345
claus
parents: 343
diff changeset
  1406
     If ignoreCase is true, lower/uppercase are considered the same.
claus
parents: 343
diff changeset
  1407
     NOTICE: match-meta character interpretation is like in unix-matching, 
claus
parents: 343
diff changeset
  1408
	     NOT the ST-80 meaning."
328
claus
parents: 327
diff changeset
  1409
claus
parents: 327
diff changeset
  1410
    |matchScanArray|
claus
parents: 327
diff changeset
  1411
claus
parents: 327
diff changeset
  1412
    "
claus
parents: 327
diff changeset
  1413
     keep the matchScanArray from the most recent match -
claus
parents: 327
diff changeset
  1414
     avoids parsing the pattern over-and over if multiple searches
claus
parents: 327
diff changeset
  1415
     are done with the same pattern.
claus
parents: 327
diff changeset
  1416
    "
claus
parents: 327
diff changeset
  1417
    (PreviousMatch notNil
claus
parents: 327
diff changeset
  1418
    and:[PreviousMatch key = self]) ifTrue:[
claus
parents: 327
diff changeset
  1419
	matchScanArray := PreviousMatch value
claus
parents: 327
diff changeset
  1420
    ] ifFalse:[
claus
parents: 327
diff changeset
  1421
	matchScanArray := self class matchScanArrayFrom:self.
claus
parents: 327
diff changeset
  1422
	matchScanArray isNil ifTrue:[
356
claus
parents: 350
diff changeset
  1423
	    'CHARARRAY: invalid matchpattern:' infoPrint. self infoPrintNL.
328
claus
parents: 327
diff changeset
  1424
	    ^ false
claus
parents: 327
diff changeset
  1425
	].
claus
parents: 327
diff changeset
  1426
	PreviousMatch := self -> matchScanArray.
claus
parents: 327
diff changeset
  1427
    ].
claus
parents: 327
diff changeset
  1428
claus
parents: 327
diff changeset
  1429
    ^ self class
claus
parents: 327
diff changeset
  1430
	matchScan:matchScanArray 
claus
parents: 327
diff changeset
  1431
	from:1 to:matchScanArray size
claus
parents: 327
diff changeset
  1432
	with:aString 
claus
parents: 327
diff changeset
  1433
	from:start to:stop 
claus
parents: 327
diff changeset
  1434
	ignoreCase:ignoreCase
claus
parents: 327
diff changeset
  1435
claus
parents: 327
diff changeset
  1436
    "
claus
parents: 327
diff changeset
  1437
     '*ute*' match:'12345COMPUTER' from:1 to:5 ignoreCase:true 
claus
parents: 327
diff changeset
  1438
     '*ute*' match:'12345COMPUTER' from:6 to:13 ignoreCase:true  
claus
parents: 327
diff changeset
  1439
    "
359
claus
parents: 357
diff changeset
  1440
!
claus
parents: 357
diff changeset
  1441
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1442
match:aString ignoreCase:ignoreCase
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1443
    "return true if aString matches self, where self may contain meta-match 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1444
     characters $* (to match any string) or $# (to match any character)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1445
     or [...] to match a set of characters.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1446
     If ignoreCase is true, lower/uppercase are considered the same.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1447
     NOTICE: match-meta character interpretation is like in unix-matching, 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1448
	     NOT the ST-80 meaning."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1449
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1450
    ^ self match:aString from:1 to:aString size ignoreCase:ignoreCase
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1451
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1452
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1453
     '*ute*' match:'COMPUTER' ignoreCase:true  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1454
     '*uter' match:'COMPUTER' ignoreCase:false 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1455
     '[abcd]*' match:'computer' ignoreCase:false 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1456
     '[abcd]*' match:'Computer' ignoreCase:false 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1457
     '[a-k]*' match:'komputer' ignoreCase:false   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1458
     '[a-k]*' match:'zomputer' ignoreCase:false    
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1459
     '[a-k]*' match:'Komputer' ignoreCase:false    
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1460
     '[a-k]*' match:'Komputer' ignoreCase:true     
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1461
     '*some*compl*ern*' match:'this is some more complicated pattern match' ignoreCase:true 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1462
     '*some*compl*ern*' match:'this is another complicated pattern match' ignoreCase:true 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1463
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1464
     Time millisecondsToRun:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1465
	Symbol allInstancesDo:[:sym |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1466
	    '[ab]*' match:sym ignoreCase:false
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1467
	]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1468
     ]. 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1469
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1470
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1471
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1472
!CharacterArray methodsFor:'printing & storing'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1473
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1474
article
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1475
    "return an article string for the receiver."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1476
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1477
    |firstChar|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1478
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1479
    firstChar := (self at:1) asLowercase. 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1480
    (firstChar isVowel or:[firstChar == $x]) ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1481
	firstChar ~~ $u ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1482
	     ^ 'an'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1483
	]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1484
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1485
    ^ 'a'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1486
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1487
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1488
displayString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1489
    "return a string to display the receiver - use storeString to have
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1490
     quotes around."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1491
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1492
    ^ self storeString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1493
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1494
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1495
printOn:aStream
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1496
    "print the receiver on aStream"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1497
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1498
    aStream nextPutAll:self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1499
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1500
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1501
printString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1502
    "return a string for printing - thats myself"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1503
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1504
    ^ self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1505
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1506
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1507
!CharacterArray methodsFor:'queries'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1508
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1509
encoding
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1510
    ^ #unknown
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1511
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1512
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1513
isString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1514
    "return true, if the receiver is some kind of string;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1515
     true is returned here - redefinition of Object>>isString."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1516
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1517
    ^ true
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1518
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1519
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1520
!CharacterArray methodsFor:'special string converting'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1521
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1522
chopTo:maxLen
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1523
    "if the receivers size is less or equal to maxLen, return it.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1524
     Otherwise, return a copy of the receiver, where some characters 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1525
     in the middle have been removed for a total string length
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1526
     of maxLen."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1527
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1528
    |sz n1 n2|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1529
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1530
    (sz := self size) > maxLen ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1531
	n1 := n2 := maxLen // 2.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1532
	maxLen odd ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1533
	    n2 := n1 + 1
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1534
	].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1535
	^ (self copyFrom:1 to:n1) , (self copyFrom:sz - n2 + 1)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1536
    ]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1537
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1538
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1539
     '12345678901234'   chopTo:15            
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1540
     '123456789012345'  chopTo:15         
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1541
     '1234567890123456' chopTo:15      
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1542
     'aShortString' chopTo:15 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1543
     'aVeryLongNameForAStringThatShouldBeShortened' chopTo:15 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1544
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1545
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1546
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1547
contractAtBeginningTo:maxLen
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1548
    "if the receivers size is less or equal to maxLen, return it.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1549
     Otherwise, return a copy of the receiver, where some characters 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1550
     at the beginning have been replaced by '...' for a total string length
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1551
     of maxLen. Can be used to abbreviate long entries in tables."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1552
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1553
    |sz|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1554
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1555
    (sz := self size) > maxLen ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1556
	^ '...' , (self copyFrom:(sz - (maxLen - 4))) 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1557
    ]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1558
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1559
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1560
     '12345678901234' contractAtBeginningTo:15          
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1561
     '123456789012345' contractAtBeginningTo:15          
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1562
     '1234567890123456' contractAtBeginningTo:15          
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1563
     'aShortString' contractAtBeginningTo:15          
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1564
     'aVeryLongNameForAStringThatShouldBeShortened' contractAtBeginningTo:15
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1565
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1566
!
359
claus
parents: 357
diff changeset
  1567
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1568
contractAtEndTo:maxLen
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1569
    "if the receivers size is less or equal to maxLen, return it.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1570
     Otherwise, return a copy of the receiver, where some characters 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1571
     at the end have been replaced by '...' for a total string length
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1572
     of maxLen. Can be used to abbreviate long entries in tables."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1573
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1574
    |sz|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1575
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1576
    (sz := self size) > maxLen ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1577
	^ self copyReplaceFrom:maxLen - 3
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1578
			    with:'...'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1579
    ]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1580
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1581
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1582
     '12345678901234' contractAtEndTo:15          
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1583
     '123456789012345' contractAtEndTo:15          
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1584
     '1234567890123456' contractAtEndTo:15          
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1585
     'aShortString' contractAtEndTo:15          
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1586
     'aVeryLongNameForAStringThatShouldBeShortened' contractAtEndTo:15 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1587
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1588
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1589
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1590
contractTo:maxLen
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1591
    "if the receivers size is less or equal to maxLen, return it.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1592
     Otherwise, return a copy of the receiver, where some characters 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1593
     in the middle have been replaced by '...' for a total string length
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1594
     of maxLen. Can be used to abbreviate long entries in tables."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1595
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1596
    |sz "{ SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1597
     halfSize "{ SmallInteger }"|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1598
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1599
    (sz := self size) > maxLen ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1600
	halfSize := maxLen // 2.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1601
	^ self copyReplaceFrom:halfSize - 1
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1602
			    to:sz - maxLen + halfSize + 1
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1603
			    with:'...'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1604
    ]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1605
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1606
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1607
     '12345678901234' contractTo:15          
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1608
     '123456789012345' contractTo:15          
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1609
     '1234567890123456' contractTo:15        
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1610
     'aShortString' contractTo:15 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1611
     'aVeryLongNameForAStringThatShouldBeShortened' contractTo:15 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1612
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1613
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1614
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1615
expandPlaceholdersWith:argArray
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1616
    "return a copy of the receiver, where all %i escapes are
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1617
     replaced by corresponding arguments from the argArray.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1618
     I.e. 'hello %1; how is %2' expandPlaceholdersWith:#('world' 'this') results
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1619
     in the new string 'hello world; how is this'.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1620
     To get a '%' character, use a '%%'-escape.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1621
     See also bindWith:... for VisualAge compatibility."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1622
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1623
    |expandedString next 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1624
     idx   "{ SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1625
     start "{ SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1626
     stop  "{ SmallInteger }"|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1627
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1628
    expandedString := ''.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1629
    stop := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1630
    start := 1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1631
    [start <= stop] whileTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1632
	idx := self indexOf:$% startingAt:start.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1633
	idx == 0 ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1634
	    ^ expandedString , (self copyFrom:start to:stop)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1635
	].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1636
	"found a %"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1637
	expandedString := expandedString , (self copyFrom:start to:(idx - 1)).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1638
	next := self at:(idx + 1).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1639
	(next == $%) ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1640
	    expandedString := expandedString , '%'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1641
	] ifFalse:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1642
	    expandedString := expandedString , (argArray at:(next digitValue)) printString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1643
	].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1644
	start := idx + 2
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1645
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1646
    ^  expandedString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1647
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1648
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1649
     'hello %1' expandPlaceholdersWith:#('world') 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1650
     'hello %1; how is %2' expandPlaceholdersWith:#('world' 'this') 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1651
     'hello %2; how is %1' expandPlaceholdersWith:#('world' 'this') 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1652
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1653
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1654
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1655
withCRs
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1656
    "return a new string consisting of receivers characters
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1657
     with all \-characters replaced by cr-characters."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1658
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1659
    ^ self copy replaceAll:$\ by:(Character cr)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1660
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1661
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1662
     'hello\world' withCRs
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1663
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1664
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1665
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1666
withEscapes
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1667
    "return a new string consisting of receivers characters
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1668
     with all \X-character escapes replaced by corresponding-characters.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1669
     (similar to the way C-language Strings are converted).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1670
     The following escapes are supported:
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1671
	\r      return character
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1672
	\n      newline character
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1673
	\b      backspace character
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1674
	\f      formfeed character
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1675
	\t      tab character
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1676
	\\      the \ character itself
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1677
	\nnn    three digit octal number defining the characters ascii value
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1678
	\other  other
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1679
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1680
     Notice, that \' is NOT a valid escape, since the general syntax of
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1681
     string constants is not affected by this method.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1682
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1683
     Although easily implementable, this is NOT done automatically
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1684
     by the compiler (due to a lack of a language standard for this).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1685
     However, the compiler may detect sends ot #withEscapes to string literals
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1686
     and place a modified string constant into the binary/byte-code.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1687
     Therefore, no runtime penalty will be payed for using these escapes.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1688
     (not in pre 2.11 versions)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1689
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1690
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1691
    |sz      "{ SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1692
     newSize "{ SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1693
     srcIdx  "{ SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1694
     dstIdx  "{ SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1695
     val     "{ SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1696
     newString next start| 
359
claus
parents: 357
diff changeset
  1697
claus
parents: 357
diff changeset
  1698
    "
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1699
     first, count the number of escapes, to allow preallocation
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1700
     of the new string ...
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1701
     (it is faster to scan the string twice than to reallocate it multiple
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1702
      times in a WriteStream)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1703
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1704
    sz := newSize := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1705
    srcIdx := 1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1706
    [(srcIdx := self indexOf:$\ startingAt:srcIdx) ~~ 0] whileTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1707
	srcIdx == sz ifFalse:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1708
	    newSize := newSize - 1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1709
	    srcIdx := srcIdx + 1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1710
	    next := self at:srcIdx.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1711
	    next == $0 ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1712
		[(self at:srcIdx) isDigit] whileTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1713
		    newSize := newSize - 1. srcIdx := srcIdx + 1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1714
		]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1715
	    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1716
	].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1717
	srcIdx := srcIdx + 1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1718
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1719
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1720
    newSize == sz ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1721
	^ self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1722
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1723
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1724
    newString := self species new:newSize.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1725
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1726
     copy over, replace escapes
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1727
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1728
    srcIdx := dstIdx := 1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1729
    [srcIdx <= sz] whileTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1730
	next := self at:srcIdx.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1731
	srcIdx := srcIdx + 1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1732
	next == $\ ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1733
	    srcIdx <= sz ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1734
		next := self at:srcIdx.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1735
		srcIdx := srcIdx + 1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1736
		next == $r ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1737
		    next := Character return
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1738
		] ifFalse:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1739
		    next == $n ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1740
			next := Character nl
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1741
		    ] ifFalse:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1742
			next == $b ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1743
			    next := Character backspace
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1744
			] ifFalse:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1745
			    next == $f ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1746
				next := Character newPage
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1747
			    ] ifFalse:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1748
				next == $t ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1749
				    next := Character tab
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1750
				] ifFalse:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1751
				    next == $0 ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1752
					val := 0.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1753
					[next isDigit] whileTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1754
					    val := val * 8 + next digitValue.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1755
					    next := self at:srcIdx.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1756
					    srcIdx := srcIdx + 1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1757
					].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1758
					next := Character value:val.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1759
				    ]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1760
				]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1761
			    ]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1762
			]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1763
		    ]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1764
		].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1765
	    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1766
	].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1767
	newString at:dstIdx put:next.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1768
	dstIdx := dstIdx + 1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1769
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1770
    ^ newString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1771
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1772
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1773
     'hello world' withEscapes  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1774
     'hello\world' withEscapes   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1775
     'hello\world\' withEscapes   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1776
     'hello world\' withEscapes   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1777
     'hello\tworld' withEscapes   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1778
     'hello\nworld\na\n\tnice\n\t\tstring' withEscapes   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1779
     'hello\tworld\n' withEscapes   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1780
     'hello\010world' withEscapes   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1781
     'hello\r\nworld' withEscapes   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1782
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1783
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1784
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1785
withTabs
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1786
    "return a copy of the receiver where leading spaces are
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1787
     replaced by tabulator characters (assuming 8-col tabs)"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1788
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1789
    |idx   "{ SmallInteger }" 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1790
     nTabs "{ SmallInteger }" 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1791
     newString|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1792
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1793
    idx := self findFirst:[:c | (c ~~ Character space)].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1794
    nTabs := (idx-1) // 8.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1795
    nTabs == 0 ifTrue:[^ self].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1796
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1797
    "any tabs"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1798
    newString := self class new:(self size - (nTabs * 7)).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1799
    newString atAll:(1 to:nTabs) put:(Character tab).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1800
    newString replaceFrom:(nTabs + 1) with:self startingAt:(nTabs * 8 + 1).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1801
    ^ newString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1802
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1803
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1804
     '12345678901234567890' withTabs 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1805
     '       8901234567890' withTabs 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1806
     '        901234567890' withTabs  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1807
     '               67890' withTabs
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1808
     '                7890' withTabs
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1809
     '                 890' withTabs
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1810
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1811
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1812
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1813
withTabsExpanded
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1814
    "return a copy of the receiver where all tabulator characters
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1815
     are expanded into spaces (assuming 8-col tabs)"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1816
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1817
    |idx "{ SmallInteger }" str|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1818
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1819
    (self includes:(Character tab)) ifFalse:[^ self].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1820
    str := WriteStream on:String new.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1821
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1822
    idx := 1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1823
    self do:[:ch |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1824
	ch == Character tab ifFalse:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1825
	    str nextPut:ch.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1826
	    idx := idx + 1
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1827
	] ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1828
	    (idx \\ 8) to:8 do:[:ii |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1829
		str space.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1830
		idx := idx + 1
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1831
	    ]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1832
	]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1833
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1834
    ^ str contents
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1835
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1836
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1837
     (String with:Character tab
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1838
	     with:Character tab
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1839
	     with:$1) withTabsExpanded
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1840
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1841
     (String with:Character tab
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1842
	     with:$1
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1843
	     with:Character tab
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1844
	     with:$2) withTabsExpanded  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1845
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1846
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1847
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1848
withoutCRs
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1849
    "return a new collection consisting of receivers elements
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1850
     with all cr-characters replaced by \-characters.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1851
     This is the reverse operation of withCRs."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1852
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1853
    ^ self copy replaceAll:(Character cr) by:$\
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1854
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1855
     'hello
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1856
world' withoutCRs
359
claus
parents: 357
diff changeset
  1857
    "
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1858
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1859
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1860
withoutLeadingSeparators
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1861
    "return a copy of myself without leading separators.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1862
     Notice: this does remove tabs, newline or any other whitespace.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1863
     Returns an empty string, if the receiver consist only of whitespace."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1864
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1865
    |index|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1866
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1867
    index := self indexOfNonSeparatorStartingAt:1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1868
    index ~~ 0 ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1869
	index == 1 ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1870
	    ^ self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1871
	].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1872
	^ self copyFrom:index
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1873
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1874
    ^ ''
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1875
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1876
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1877
     '    foo    ' withoutLeadingSeparators  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1878
     'foo    '     withoutLeadingSeparators   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1879
     '    foo'     withoutLeadingSeparators  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1880
     '       '     withoutLeadingSeparators   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1881
     'foo'         withoutLeadingSeparators   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1882
     ('  ' , Character tab asString , ' foo   ') withoutLeadingSeparators inspect 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1883
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1884
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1885
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1886
withoutSeparators
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1887
    "return a copy of myself without leading and trailing whitespace.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1888
     Whitespace is space, tab, newline, formfeed.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1889
     Use withoutSpaces, if you want to remove spaces only."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1890
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1891
    |startIndex "{ Class: SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1892
     endIndex   "{ Class: SmallInteger }" 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1893
     sz|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1894
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1895
    sz := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1896
    startIndex := 1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1897
    endIndex := sz.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1898
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1899
    [(startIndex < endIndex) and:[(self at:startIndex) isSeparator]] whileTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1900
	startIndex := startIndex + 1
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1901
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1902
    [(endIndex > 1) and:[(self at:endIndex) isSeparator]] whileTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1903
	endIndex := endIndex - 1
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1904
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1905
    startIndex > endIndex ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1906
	^ ''
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1907
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1908
    ((startIndex == 1) and:[endIndex == sz]) ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1909
	^ self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1910
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1911
    ^ self copyFrom:startIndex to:endIndex
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1912
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1913
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1914
     '    foo    ' withoutSeparators      
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1915
     '    foo' withoutSeparators      
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1916
     'foo    ' withoutSeparators      
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1917
     '       ' withoutSeparators      
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1918
     ('  foo' , Character tab asString , '    ') withoutSeparators inspect 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1919
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1920
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1921
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1922
withoutSpaces
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1923
    "return a copy of myself without leading and trailing spaces.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1924
     Notice: this does NOT remove tabs, newline or any other whitespace.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1925
     Use withoutSeparators for this."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1926
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1927
    |startIndex "{ Class: SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1928
     endIndex   "{ Class: SmallInteger }" 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1929
     sz|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1930
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1931
    sz := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1932
    startIndex := 1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1933
    endIndex := sz.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1934
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1935
    [(startIndex < endIndex) and:[(self at:startIndex) == Character space]] whileTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1936
	startIndex := startIndex + 1
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1937
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1938
    [(endIndex > 1) and:[(self at:endIndex) == Character space]] whileTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1939
	endIndex := endIndex - 1
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1940
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1941
    startIndex > endIndex ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1942
	^ ''
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1943
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1944
    ((startIndex == 1) and:[endIndex == sz]) ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1945
	^ self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1946
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1947
    ^ self copyFrom:startIndex to:endIndex
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1948
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1949
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1950
     '    foo    ' withoutSpaces  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1951
     'foo    '     withoutSpaces   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1952
     '    foo'     withoutSpaces  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1953
     '       '     withoutSpaces   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1954
     ('  foo' , Character tab asString , '    ') withoutSpaces inspect 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1955
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1956
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1957
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1958
!CharacterArray methodsFor:'substring searching'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1959
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1960
findString:subString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1961
    "find a substring. if found, return the index;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1962
     if not found, return 0."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1963
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1964
    ^ self indexOfSubCollection:subString startingAt:1 ifAbsent:[0]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1965
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1966
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1967
     'hello world' findString:'llo'   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1968
     'hello world' findString:'ole'  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1969
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1970
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1971
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1972
findString:subString ifAbsent:exceptionBlock
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1973
    "find a substring. If found, return the index;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1974
     if not found, return the result of evaluating exceptionBlock."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1975
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1976
    ^ self indexOfSubCollection:subString startingAt:1 ifAbsent:exceptionBlock
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1977
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1978
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1979
findString:subString startingAt:index
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1980
    "find a substring, starting at index. if found, return the index;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1981
     if not found, return 0."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1982
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1983
    ^ self indexOfSubCollection:subString startingAt:index ifAbsent:[0]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1984
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1985
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1986
     'hello yello' findString:'llo' startingAt:1   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1987
     'hello yello' findString:'llo' startingAt:5   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1988
     'hello yello' findString:'llo' startingAt:15   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1989
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1990
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1991
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1992
findString:subString startingAt:index ifAbsent:exceptionBlock
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1993
    "find a substring, starting at index. if found, return the index;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1994
     if not found, return the result of evaluating exceptionBlock."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1995
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1996
    ^ self indexOfSubCollection:subString startingAt:index ifAbsent:exceptionBlock
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1997
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1998
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  1999
includesString:aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2000
    "return true, if a substring is contained in the receiver"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2001
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2002
    ^ (self indexOfSubCollection:aString startingAt:1 ifAbsent:[0]) ~~ 0
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2003
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2004
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2005
     'hello world' includesString:'hel' 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2006
     'hello world' includesString:'rld' 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2007
     'hello world' includesString:'llo'  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2008
     'hello world' includesString:'LLO'   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2009
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2010
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2011
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2012
indexOfSubCollection:subString startingAt:index ifAbsent:exceptionBlock
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2013
    "find a substring, starting at index. if found, return the index;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2014
     if not found, return the result of evaluating exceptionBlock.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2015
     This is a q&d hack - not very efficient"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2016
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2017
    |firstChar found
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2018
     startIndex "{ Class: SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2019
     subSize    "{ Class: SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2020
     mySize     "{ Class: SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2021
     runIdx     "{ Class: SmallInteger }" |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2022
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2023
    subSize := subString size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2024
    subSize == 0 ifTrue:[^ index]. "empty string matches"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2025
    mySize := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2026
    firstChar := subString at:1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2027
    startIndex := self indexOf:firstChar startingAt:index.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2028
    [startIndex == 0] whileFalse:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2029
	runIdx := startIndex.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2030
	found := true.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2031
	1 to:subSize do:[:i |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2032
	    runIdx > mySize ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2033
		found := false
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2034
	    ] ifFalse:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2035
		(subString at:i) ~~ (self at:runIdx) ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2036
		    found := false
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2037
		]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2038
	    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2039
	    runIdx := runIdx + 1
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2040
	].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2041
	found ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2042
	    ^ startIndex
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2043
	].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2044
	startIndex := self indexOf:firstChar startingAt:(startIndex + 1)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2045
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2046
    ^ exceptionBlock value
651
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2047
!
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2048
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2049
restAfter:keyword withOutSeparators:strip
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2050
    "compare the left of the receiver with keyword,
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2051
     if it matches return the right. 
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2052
     Finally, if strip is true, remove whiteSpace.
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2053
     This method is used to match and extract lines of the form:
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2054
	something: rest
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2055
     where we are interrested in rest, but only if the receiver string
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2056
     begins with something. 
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2057
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2058
     You may wonder why such a specialized method exists here
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2059
     - this is so common when processing mailboxes,
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2060
     rcs files, nntp/pop3 responses, that is was considered worth
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2061
     a special method here to avoid having the code below a hundred
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2062
     times in variuos places."
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2063
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2064
    |rest|
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2065
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2066
    (self startsWith:keyword) ifTrue:[
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2067
	rest := self copyFrom:(keyword size + 1).
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2068
	strip ifTrue:[
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2069
	    rest := rest withoutSeparators
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2070
	].
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2071
	^ rest
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2072
    ].
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2073
    ^ nil
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2074
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2075
    "
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2076
     'foo: hello world' restAfter:'foo:' withoutSeparators:true 
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2077
     'funny: something' restAfter:'foo:' withoutSeparators:true 
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2078
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2079
     'foo:     hello world    ' restAfter:'foo:' withoutSeparators:true 
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2080
     'foo:     hello world    ' restAfter:'foo:' withoutSeparators:false 
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2081
    "
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2082
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2083
    "Created: 25.11.1995 / 11:04:18 / cg"
328
claus
parents: 327
diff changeset
  2084
! !
claus
parents: 327
diff changeset
  2085
255
2b2c5c0facab *** empty log message ***
claus
parents: 247
diff changeset
  2086
!CharacterArray methodsFor:'testing'!
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2087
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2088
countWords
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2089
    "return the number of words, which are separated by separators"
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2090
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  2091
    |tally "{ Class: SmallInteger }"
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  2092
     start "{ Class: SmallInteger }"
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  2093
     mySize "{ Class: SmallInteger }"
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  2094
     stop ch|
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2095
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2096
    tally := 0.
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2097
    start := 1.
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2098
    mySize := self size.
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2099
    [start <= mySize] whileTrue:[
154
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2100
	ch := self at:start.
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2101
	ch isSeparator ifTrue:[
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2102
	    start := start + 1
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2103
	] ifFalse:[
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2104
	    stop := self indexOfSeparatorStartingAt:start.
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2105
	    (stop == 0) ifTrue:[
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2106
		stop := mySize + 1
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2107
	    ].
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2108
	    tally := tally + 1.
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2109
	    start := stop
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2110
	]
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2111
    ].
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2112
    ^ tally
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2113
92
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  2114
    "
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  2115
     'hello world isnt this nice' countWords'
0c73b48551ac *** empty log message ***
claus
parents: 82
diff changeset
  2116
    "
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2117
!
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2118
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2119
isAlphaNumeric
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2120
    "return true, if the receiver is some alphanumeric word;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2121
     i.e. consists of a letter followed by letters or digits."
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2122
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2123
    self size == 0 ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2124
	"mhmh what is this ?"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2125
	^ false
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2126
    ].
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2127
    (self at:1) isLetter ifFalse:[^ false].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2128
    self do:[:char |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2129
	char isLetterOrDigit ifFalse:[^ false].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2130
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2131
    ^ true
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2132
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2133
    "
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2134
     'helloWorld' isAlphaNumeric  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2135
     'foo1234' isAlphaNumeric    
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2136
     'f1234' isAlphaNumeric      
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2137
     '1234' isAlphaNumeric       
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2138
     '+' isAlphaNumeric         
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2139
    "
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2140
!
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2141
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2142
isBlank
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2143
    "return true, if the receiver contains spaces only"
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2144
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2145
    self do:[:char |
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2146
	char ~~ Character space ifTrue:[^ false].
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2147
    ].
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2148
    ^ true
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2149
!
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2150
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2151
levenshteinTo:aString
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2152
    "return the levenshtein distance to the argument, aString;
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2153
     this value corrensponds to the number of replacements that have to be
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2154
     made to get aString from the receiver.
196
ab5727ae9e38 added asUppercaseFirst / asLowercaseFirst
claus
parents: 163
diff changeset
  2155
     See IEEE transactions on Computers 1976 Pg 172 ff."
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2156
327
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  2157
    "
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  2158
     in the following, we assum that ommiting a character
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  2159
     is less of an error than inserting an extra character.
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  2160
     Therefore the different insertion (i) and deletion (d)
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  2161
     values.
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  2162
    "
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  2163
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2164
    ^ self levenshteinTo:aString s:4 c:1 i:2 d:6
154
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2165
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2166
    "
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2167
     'ocmprt' levenshteinTo:'computer'
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2168
     'computer' levenshteinTo:'computer'
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2169
     'ocmputer' levenshteinTo:'computer'
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2170
     'cmputer' levenshteinTo:'computer'
327
183f094cfd72 last with old match code
claus
parents: 326
diff changeset
  2171
     'computer' levenshteinTo:'cmputer'
154
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2172
     'Computer' levenshteinTo:'computer'
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2173
    "
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2174
!
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2175
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2176
levenshteinTo:aString s:substWeight c:caseWeight i:insrtWeight d:deleteWeight
196
ab5727ae9e38 added asUppercaseFirst / asLowercaseFirst
claus
parents: 163
diff changeset
  2177
    "parametrized levenshtein. 
ab5727ae9e38 added asUppercaseFirst / asLowercaseFirst
claus
parents: 163
diff changeset
  2178
     return the levenshtein distance to the argument, aString;
ab5727ae9e38 added asUppercaseFirst / asLowercaseFirst
claus
parents: 163
diff changeset
  2179
     this value corrensponds to the number of replacements that have to be
ab5727ae9e38 added asUppercaseFirst / asLowercaseFirst
claus
parents: 163
diff changeset
  2180
     made to get aString from the receiver.
ab5727ae9e38 added asUppercaseFirst / asLowercaseFirst
claus
parents: 163
diff changeset
  2181
     The arguments are the costs for substitution, case-change, insertion and 
ab5727ae9e38 added asUppercaseFirst / asLowercaseFirst
claus
parents: 163
diff changeset
  2182
     deletion of a character.
ab5727ae9e38 added asUppercaseFirst / asLowercaseFirst
claus
parents: 163
diff changeset
  2183
     See IEEE transactions on Computers 1976 Pg 172 ff"
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2184
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2185
    |d  "delta matrix"
196
ab5727ae9e38 added asUppercaseFirst / asLowercaseFirst
claus
parents: 163
diff changeset
  2186
     len1 "{ Class: SmallInteger }"
ab5727ae9e38 added asUppercaseFirst / asLowercaseFirst
claus
parents: 163
diff changeset
  2187
     len2 "{ Class: SmallInteger }"
ab5727ae9e38 added asUppercaseFirst / asLowercaseFirst
claus
parents: 163
diff changeset
  2188
     dim  "{ Class: SmallInteger }"
ab5727ae9e38 added asUppercaseFirst / asLowercaseFirst
claus
parents: 163
diff changeset
  2189
     prevRow row col 
ab5727ae9e38 added asUppercaseFirst / asLowercaseFirst
claus
parents: 163
diff changeset
  2190
     dimPlus1 "{ Class: SmallInteger }"
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2191
     min pp c1 c2|
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2192
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2193
    len1 := self size.
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2194
    len2 := aString size.
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2195
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2196
    "create the help-matrix"
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2197
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2198
    dim := len1 max:len2.
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2199
    dimPlus1 := dim + 1.
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2200
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2201
    d := Array new:dimPlus1.
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2202
    1 to:dimPlus1 do:[:i |
154
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2203
	d at:i put:(Array new:dimPlus1)
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2204
    ].
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2205
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2206
    "init help-matrix"
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2207
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2208
    (d at:1) at:1 put:0.
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2209
    row := d at:1.
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2210
    1 to:dim do:[:j |
154
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2211
	row at:(j + 1) put:( (row at:j) + insrtWeight )
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2212
    ].
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2213
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2214
    1 to:dim do:[:i |
154
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2215
	 (d at:(i + 1)) at:1 put:(  ((d at:i) at:1) + deleteWeight )
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2216
    ].
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2217
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2218
    1 to:len1 do:[:i |
154
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2219
	c1 := self at:i.
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2220
	1 to:len2 do:[:j |
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2221
	    c2 := aString at:j.
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2222
	    (c1 == c2) ifTrue:[
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2223
		pp := 0
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2224
	    ] ifFalse:[
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2225
		(c1 asLowercase == c2 asLowercase) ifTrue:[
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2226
		    pp := caseWeight
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2227
		] ifFalse:[
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2228
		    pp := substWeight
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2229
		]
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2230
	    ].
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2231
	    prevRow := d at:i.
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2232
	    row := d at:(i + 1).
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2233
	    col := j + 1.
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2234
	    min := (prevRow at:j) + pp.
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2235
	    min := min min:( (row at:j) + insrtWeight).
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2236
	    min := min min:( (prevRow at:col) + deleteWeight).
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2237
	    row at:col put: min
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2238
	]
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2239
    ].
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2240
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2241
    ^ (d at:(len1 + 1)) at:(len2 + 1)
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2242
!
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2243
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2244
numArgs
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2245
    "treating the receiver as a message selector, return how many arguments would it take"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2246
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2247
    |binopChars|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2248
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2249
    (self size > 2) ifFalse:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2250
	binopChars := '|&-+=*/\<>~@,'.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2251
	(self size == 1) ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2252
	    ((binopChars occurrencesOf:(self at:1)) == 0) ifTrue:[^ 0].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2253
	    ^ 1
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2254
	].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2255
	((binopChars occurrencesOf:(self at:1)) == 0) ifFalse:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2256
	    ((binopChars occurrencesOf:(self at:2)) == 0) ifFalse:[^ 1]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2257
	]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2258
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2259
    ^ self occurrencesOf:$:
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2260
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2261
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2262
     'foo:bar:' numArgs  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2263
     #foo:bar: numArgs    
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2264
     'hello' numArgs       
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2265
     '+' numArgs   
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2266
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2267
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2268
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2269
partsIfSelector
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2270
    "treat the receiver as a message selector, return a collection of parts."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2271
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2272
    |idx1 "{ Class: SmallInteger }"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2273
     coll idx2 sz|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2274
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2275
    coll := OrderedCollection new.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2276
    idx1 := 1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2277
    sz := self size.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2278
    [true] whileTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2279
	idx2 := self indexOf:$: startingAt:idx1 + 1.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2280
	(idx2 == 0 or:[idx2 == sz]) ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2281
	    coll add:(self copyFrom:idx1).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2282
	    ^ coll
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2283
	].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2284
	coll add:(self copyFrom:idx1 to:idx2).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2285
	idx1 := idx2 + 1
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2286
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2287
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2288
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2289
     'foo:bar:' partsIfSelector     
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2290
     #foo:bar: partsIfSelector     
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2291
     'hello' partsIfSelector       
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2292
     '+' partsIfSelector           
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2293
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2294
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 581
diff changeset
  2295
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2296
spellAgainst: aString 
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2297
    "return an integer between 0 and 100 indicating how similar 
154
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2298
     the argument is to the receiver.  No case conversion is done.
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2299
     This algorithm is much simpler (but also less exact) than the
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2300
     levenshtein distance. Experiment which is better for your
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2301
     application."
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2302
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2303
    | i1     "{ Class: SmallInteger }"
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2304
      i2     "{ Class: SmallInteger }"
154
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2305
      next1  "{ Class: SmallInteger }"
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2306
      next2  "{ Class: SmallInteger }"
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2307
      size1  "{ Class: SmallInteger }"
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2308
      size2  "{ Class: SmallInteger }"
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2309
      score  "{ Class: SmallInteger }"
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2310
      maxLen "{ Class: SmallInteger }" |
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2311
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2312
    size1 := self size.
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2313
    size2 := aString size.
154
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2314
    maxLen := size1 max:size2.
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2315
    score := 0.
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2316
    i1 := i2 := 1.
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2317
    [i1 <= size1 and: [i2 <= size2]] whileTrue:[
154
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2318
	next1 := i1 + 1.
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2319
	next2 := i2 + 1.
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2320
	(self at:i1) == (aString at:i2) ifTrue: [
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2321
	    score := score+1.             
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2322
	    i1 := next1.                    
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2323
	    i2 := next2
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2324
	] ifFalse: [
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2325
	    (i2 < size2 and: [(self at:i1) == (aString at:next2)]) ifTrue: [
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2326
		i2 := next2
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2327
	    ] ifFalse: [
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2328
		(i1 < size1 and: [(self at:next1) == (aString at:i2)]) ifTrue: [
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2329
		    i1 := next1
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2330
		] ifFalse: [
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2331
		    i1 := next1.
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2332
		    i2 := next2
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2333
		] 
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2334
	    ] 
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2335
	] 
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2336
    ].
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2337
154
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2338
    score = maxLen ifTrue: [^ 100].
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2339
    ^ 100 * score // maxLen
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2340
154
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2341
    " 
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2342
     'Smalltalk' spellAgainst: 'Smalltlak' 
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2343
     'Smalltalk' spellAgainst: 'smalltlak' 
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2344
     'Smalltalk' spellAgainst: 'smalltalk' 
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2345
     'Smalltalk' spellAgainst: 'smalltlk'  
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2346
     'Smalltalk' spellAgainst: 'Smalltolk'   
d4236ec280a6 *** empty log message ***
claus
parents: 138
diff changeset
  2347
    "
64
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2348
! !
af7aeb79b25e Initial revision
claus
parents:
diff changeset
  2349
629
2ceefe9b5a19 version at the end
Claus Gittinger <cg@exept.de>
parents: 608
diff changeset
  2350
!CharacterArray class methodsFor:'documentation'!
2ceefe9b5a19 version at the end
Claus Gittinger <cg@exept.de>
parents: 608
diff changeset
  2351
2ceefe9b5a19 version at the end
Claus Gittinger <cg@exept.de>
parents: 608
diff changeset
  2352
version
651
2093b018dc3a added restAfter:withoutSeparators:
Claus Gittinger <cg@exept.de>
parents: 650
diff changeset
  2353
    ^ '$Header: /cvs/stx/stx/libbasic/CharacterArray.st,v 1.41 1995-11-25 10:06:58 cg Exp $'
629
2ceefe9b5a19 version at the end
Claus Gittinger <cg@exept.de>
parents: 608
diff changeset
  2354
! !