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