David T. Lewis uploaded a new version of KernelTests to project The Trunk:
http://source.squeak.org/trunk/KernelTests-dtl.175.mcz
==================== Summary ====================
Name: KernelTests-dtl.175
Author: dtl
Time: 27 February 2011, 9:48:28.704 pm
UUID: 8b527a84-abff-42c1-96d6-845975beff75
Ancestors: KernelTests-ul.174
Add test to document Float>>printPaddedWith:To: bug reported on http://lists.gforge.inria.fr/pipermail/pharo-users/2011-February/001569.html.
=============== Diff against KernelTests-ul.174 ===============
Item was added:
+ ----- Method: FloatTest>>testPrintPaddedWithTo (in category 'printing') -----
+ testPrintPaddedWithTo
+ "This bug was reported in http://lists.gforge.inria.fr/pipermail/pharo-users/2011-February/001569.html.
+ The problem was caused by treating the format specifier as a number rather than
+ as a string, such the the number may be a Float subject to floating point rounding
+ errors. The solution to treat the format specifier as a string, and extract the integer
+ fields before and after the decimal point in the string."
+
+ self assert: [(1.0 printPaddedWith: $0 to: 2.2) = '01.00'].
+ self assert: [(1.0 printPaddedWith: $X to: 2.2) = 'X1.0X'].
+ self assert: [(1.0 printPaddedWith: $0 to: 2) = '01.0'].
+ self assert: [(12345.6789 printPaddedWith: $0 to: 2) = '12345.6789'].
+ self assert: [(12345.6789 printPaddedWith: $0 to: 2.2) = '12345.6789'].
+ self assert: [(12.34 printPaddedWith: $0 to: 2.2) = '12.34'].
+ self assert: [(12345.6789 printPaddedWith: $0 to: 2.2) = '12345.6789'].
+ self assert: [(123.456 printPaddedWith: $X to: 4.4) = 'X123.456X'].
+ self assert: [(1.0 printPaddedWith: $0 to: 2.1) = '01.0'].
+ self assert: [(1.0 printPaddedWith: $0 to: 2.2) = '01.00'].
+ self assert: [(1.0 printPaddedWith: $0 to: 2.3) = '01.000']. "previously failed due to float usage"
+ self assert: [(1.0 printPaddedWith: $0 to: 2.4) = '01.0000']. "previously failed due to float usage"
+ self assert: [(1.0 printPaddedWith: $0 to: 2.5) = '01.00000']
+
+ !
David T. Lewis uploaded a new version of KernelTests to project The Trunk:
http://source.squeak.org/trunk/KernelTests-dtl.175.mcz
==================== Summary ====================
Name: KernelTests-dtl.175
Author: dtl
Time: 27 February 2011, 9:48:28.704 pm
UUID: 8b527a84-abff-42c1-96d6-845975beff75
Ancestors: KernelTests-ul.174
Add test to document Float>>printPaddedWith:To: bug reported on http://lists.gforge.inria.fr/pipermail/pharo-users/2011-February/001569.html.
=============== Diff against KernelTests-ul.174 ===============
Item was added:
+ ----- Method: FloatTest>>testPrintPaddedWithTo (in category 'printing') -----
+ testPrintPaddedWithTo
+ "This bug was reported in http://lists.gforge.inria.fr/pipermail/pharo-users/2011-February/001569.html.
+ The problem was caused by treating the format specifier as a number rather than
+ as a string, such the the number may be a Float subject to floating point rounding
+ errors. The solution to treat the format specifier as a string, and extract the integer
+ fields before and after the decimal point in the string."
+
+ self assert: [(1.0 printPaddedWith: $0 to: 2.2) = '01.00'].
+ self assert: [(1.0 printPaddedWith: $X to: 2.2) = 'X1.0X'].
+ self assert: [(1.0 printPaddedWith: $0 to: 2) = '01.0'].
+ self assert: [(12345.6789 printPaddedWith: $0 to: 2) = '12345.6789'].
+ self assert: [(12345.6789 printPaddedWith: $0 to: 2.2) = '12345.6789'].
+ self assert: [(12.34 printPaddedWith: $0 to: 2.2) = '12.34'].
+ self assert: [(12345.6789 printPaddedWith: $0 to: 2.2) = '12345.6789'].
+ self assert: [(123.456 printPaddedWith: $X to: 4.4) = 'X123.456X'].
+ self assert: [(1.0 printPaddedWith: $0 to: 2.1) = '01.0'].
+ self assert: [(1.0 printPaddedWith: $0 to: 2.2) = '01.00'].
+ self assert: [(1.0 printPaddedWith: $0 to: 2.3) = '01.000']. "previously failed due to float usage"
+ self assert: [(1.0 printPaddedWith: $0 to: 2.4) = '01.0000']. "previously failed due to float usage"
+ self assert: [(1.0 printPaddedWith: $0 to: 2.5) = '01.00000']
+
+ !
David T. Lewis uploaded a new version of KernelTests to project The Trunk:
http://source.squeak.org/trunk/KernelTests-dtl.175.mcz
==================== Summary ====================
Name: KernelTests-dtl.175
Author: dtl
Time: 27 February 2011, 9:48:28.704 pm
UUID: 8b527a84-abff-42c1-96d6-845975beff75
Ancestors: KernelTests-ul.174
Add test to document Float>>printPaddedWith:To: bug reported on http://lists.gforge.inria.fr/pipermail/pharo-users/2011-February/001569.html.
=============== Diff against KernelTests-ul.174 ===============
Item was added:
+ ----- Method: FloatTest>>testPrintPaddedWithTo (in category 'printing') -----
+ testPrintPaddedWithTo
+ "This bug was reported in http://lists.gforge.inria.fr/pipermail/pharo-users/2011-February/001569.html.
+ The problem was caused by treating the format specifier as a number rather than
+ as a string, such the the number may be a Float subject to floating point rounding
+ errors. The solution to treat the format specifier as a string, and extract the integer
+ fields before and after the decimal point in the string."
+
+ self assert: [(1.0 printPaddedWith: $0 to: 2.2) = '01.00'].
+ self assert: [(1.0 printPaddedWith: $X to: 2.2) = 'X1.0X'].
+ self assert: [(1.0 printPaddedWith: $0 to: 2) = '01.0'].
+ self assert: [(12345.6789 printPaddedWith: $0 to: 2) = '12345.6789'].
+ self assert: [(12345.6789 printPaddedWith: $0 to: 2.2) = '12345.6789'].
+ self assert: [(12.34 printPaddedWith: $0 to: 2.2) = '12.34'].
+ self assert: [(12345.6789 printPaddedWith: $0 to: 2.2) = '12345.6789'].
+ self assert: [(123.456 printPaddedWith: $X to: 4.4) = 'X123.456X'].
+ self assert: [(1.0 printPaddedWith: $0 to: 2.1) = '01.0'].
+ self assert: [(1.0 printPaddedWith: $0 to: 2.2) = '01.00'].
+ self assert: [(1.0 printPaddedWith: $0 to: 2.3) = '01.000']. "previously failed due to float usage"
+ self assert: [(1.0 printPaddedWith: $0 to: 2.4) = '01.0000']. "previously failed due to float usage"
+ self assert: [(1.0 printPaddedWith: $0 to: 2.5) = '01.00000']
+
+ !
Alexander Lazarević uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-laza.428.mcz
==================== Summary ====================
Name: Collections-laza.428
Author: laza
Time: 26 February 2011, 11:31:16.656 am
UUID: f943155d-9f78-844d-9db4-9ae5396da757
Ancestors: Collections-ul.427
Some minor recats
=============== Diff against Collections-ul.427 ===============
Item was changed:
+ ----- Method: String>>endsWith: (in category 'testing') -----
- ----- Method: String>>endsWith: (in category 'comparing') -----
endsWith: suffix
"Answer whether the tail end of the receiver is the same as suffix.
The comparison is case-sensitive."
| extra |
(extra := self size - suffix size) < 0 ifTrue: [^ false].
^ (self findString: suffix startingAt: extra + 1) > 0
"
'Elvis' endsWith: 'vis'
"!
Item was changed:
+ ----- Method: String>>endsWithAColon (in category 'testing') -----
- ----- Method: String>>endsWithAColon (in category 'system primitives') -----
endsWithAColon
"Answer whether the final character of the receiver is a colon"
^ self size > 0 and: [self last == $:]
"
#fred: endsWithAColon
'fred' endsWithAColon
"!
Item was changed:
+ ----- Method: String>>endsWithAnyOf: (in category 'testing') -----
- ----- Method: String>>endsWithAnyOf: (in category 'comparing') -----
endsWithAnyOf: aCollection
aCollection do:[:suffix|
(self endsWith: suffix) ifTrue:[^true].
].
^false!
Item was changed:
+ ----- Method: String>>endsWithDigit (in category 'testing') -----
- ----- Method: String>>endsWithDigit (in category 'accessing') -----
endsWithDigit
"Answer whether the receiver's final character represents a digit. 3/11/96 sw"
^ self size > 0 and: [self last isDigit]!
Item was changed:
+ ----- Method: String>>findSubstring:in:startingAt:matchTable: (in category 'accessing') -----
- ----- Method: String>>findSubstring:in:startingAt:matchTable: (in category 'system primitives') -----
findSubstring: key in: body startingAt: start matchTable: matchTable
"Answer the index in the string body at which the substring key first occurs, at or beyond start. The match is determined using matchTable, which can be used to effect, eg, case-insensitive matches. If no match is found, zero will be returned."
| index c1 c2 |
matchTable == nil ifTrue: [
key size = 0 ifTrue: [^ 0].
start to: body size - key size + 1 do:
[:startIndex |
index := 1.
[(body at: startIndex+index-1)
= (key at: index)]
whileTrue:
[index = key size ifTrue: [^ startIndex].
index := index+1]].
^ 0
].
key size = 0 ifTrue: [^ 0].
start to: body size - key size + 1 do:
[:startIndex |
index := 1.
[c1 := body at: startIndex+index-1.
c2 := key at: index.
((c1 leadingChar = 0 and: [ c1 asciiValue < matchTable size ])
ifTrue: [ matchTable at: c1 asciiValue + 1 ]
ifFalse: [ c1 asciiValue + 1 ]) =
((c2 leadingChar = 0 and: [ c2 asciiValue < matchTable size ])
ifTrue: [ matchTable at: c2 asciiValue + 1 ]
ifFalse: [c2 asciiValue + 1 ]) ]
whileTrue:
[index = key size ifTrue: [^ startIndex].
index := index+1]].
^ 0!
Item was changed:
+ ----- Method: String>>includesSubString: (in category 'testing') -----
- ----- Method: String>>includesSubString: (in category 'accessing') -----
includesSubString: subString
^ (self findString: subString startingAt: 1) > 0!
Item was changed:
+ ----- Method: String>>includesSubstring:caseSensitive: (in category 'testing') -----
- ----- Method: String>>includesSubstring:caseSensitive: (in category 'accessing') -----
includesSubstring: aString caseSensitive: caseSensitive
^ (self findString: aString startingAt: 1 caseSensitive: caseSensitive) > 0!
Item was changed:
+ ----- Method: String>>lastSpacePosition (in category 'accessing') -----
- ----- Method: String>>lastSpacePosition (in category 'testing') -----
lastSpacePosition
"Answer the character position of the final space or other separator character in the receiver, and 0 if none"
self size to: 1 by: -1 do:
[:i | ((self at: i) isSeparator) ifTrue: [^ i]].
^ 0
"
'fred the bear' lastSpacePosition
'ziggie' lastSpacePosition
'elvis ' lastSpacePosition
'wimpy ' lastSpacePosition
'' lastSpacePosition
"!
Item was changed:
+ ----- Method: String>>numArgs (in category 'accessing') -----
- ----- Method: String>>numArgs (in category 'system primitives') -----
numArgs
"Answer either the number of arguments that the receiver would take if considered a selector. Answer -1 if it couldn't be a selector. Note that currently this will answer -1 for anything begining with an uppercase letter even though the system will accept such symbols as selectors. It is intended mostly for the assistance of spelling correction."
| firstChar numColons excess start ix |
self size = 0 ifTrue: [^ -1].
firstChar := self at: 1.
(firstChar isLetter or: [firstChar = $:]) ifTrue:
["Fast reject if any chars are non-alphanumeric
NOTE: fast only for Byte things - Broken for Wide"
self class isBytes
ifTrue: [(self findSubstring: '~' in: self startingAt: 1 matchTable: Tokenish) > 0 ifTrue: [^ -1]]
ifFalse: [2 to: self size do: [:i | (self at: i) tokenish ifFalse: [^ -1]]].
"Fast colon count"
numColons := 0. start := 1.
[(ix := self indexOf: $: startingAt: start) > 0]
whileTrue:
[numColons := numColons + 1.
start := ix + 1].
numColons = 0 ifTrue: [^ 0].
firstChar = $:
ifTrue: [excess := 2 "Has an initial keyword, as #:if:then:else:"]
ifFalse: [excess := 0].
self last = $:
ifTrue: [^ numColons - excess]
ifFalse: [^ numColons - excess - 1 "Has a final keywords as #nextPut::andCR"]].
firstChar isSpecial ifTrue:
[self size = 1 ifTrue: [^ 1].
2 to: self size do: [:i | (self at: i) isSpecial ifFalse: [^ -1]].
^ 1].
^ -1.!
Item was changed:
+ ----- Method: String>>startsWithDigit (in category 'testing') -----
- ----- Method: String>>startsWithDigit (in category 'accessing') -----
startsWithDigit
"Answer whether the receiver's first character represents a digit"
^ self size > 0 and: [self first isDigit]!
Item was changed:
+ ----- Method: String>>string (in category 'converting') -----
- ----- Method: String>>string (in category 'accessing') -----
string
^self!
Alexander Lazarević uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-laza.428.mcz
==================== Summary ====================
Name: Collections-laza.428
Author: laza
Time: 26 February 2011, 11:31:16.656 am
UUID: f943155d-9f78-844d-9db4-9ae5396da757
Ancestors: Collections-ul.427
Some minor recats
=============== Diff against Collections-ul.427 ===============
Item was changed:
+ ----- Method: String>>endsWith: (in category 'testing') -----
- ----- Method: String>>endsWith: (in category 'comparing') -----
endsWith: suffix
"Answer whether the tail end of the receiver is the same as suffix.
The comparison is case-sensitive."
| extra |
(extra := self size - suffix size) < 0 ifTrue: [^ false].
^ (self findString: suffix startingAt: extra + 1) > 0
"
'Elvis' endsWith: 'vis'
"!
Item was changed:
+ ----- Method: String>>endsWithAColon (in category 'testing') -----
- ----- Method: String>>endsWithAColon (in category 'system primitives') -----
endsWithAColon
"Answer whether the final character of the receiver is a colon"
^ self size > 0 and: [self last == $:]
"
#fred: endsWithAColon
'fred' endsWithAColon
"!
Item was changed:
+ ----- Method: String>>endsWithAnyOf: (in category 'testing') -----
- ----- Method: String>>endsWithAnyOf: (in category 'comparing') -----
endsWithAnyOf: aCollection
aCollection do:[:suffix|
(self endsWith: suffix) ifTrue:[^true].
].
^false!
Item was changed:
+ ----- Method: String>>endsWithDigit (in category 'testing') -----
- ----- Method: String>>endsWithDigit (in category 'accessing') -----
endsWithDigit
"Answer whether the receiver's final character represents a digit. 3/11/96 sw"
^ self size > 0 and: [self last isDigit]!
Item was changed:
+ ----- Method: String>>findSubstring:in:startingAt:matchTable: (in category 'accessing') -----
- ----- Method: String>>findSubstring:in:startingAt:matchTable: (in category 'system primitives') -----
findSubstring: key in: body startingAt: start matchTable: matchTable
"Answer the index in the string body at which the substring key first occurs, at or beyond start. The match is determined using matchTable, which can be used to effect, eg, case-insensitive matches. If no match is found, zero will be returned."
| index c1 c2 |
matchTable == nil ifTrue: [
key size = 0 ifTrue: [^ 0].
start to: body size - key size + 1 do:
[:startIndex |
index := 1.
[(body at: startIndex+index-1)
= (key at: index)]
whileTrue:
[index = key size ifTrue: [^ startIndex].
index := index+1]].
^ 0
].
key size = 0 ifTrue: [^ 0].
start to: body size - key size + 1 do:
[:startIndex |
index := 1.
[c1 := body at: startIndex+index-1.
c2 := key at: index.
((c1 leadingChar = 0 and: [ c1 asciiValue < matchTable size ])
ifTrue: [ matchTable at: c1 asciiValue + 1 ]
ifFalse: [ c1 asciiValue + 1 ]) =
((c2 leadingChar = 0 and: [ c2 asciiValue < matchTable size ])
ifTrue: [ matchTable at: c2 asciiValue + 1 ]
ifFalse: [c2 asciiValue + 1 ]) ]
whileTrue:
[index = key size ifTrue: [^ startIndex].
index := index+1]].
^ 0!
Item was changed:
+ ----- Method: String>>includesSubString: (in category 'testing') -----
- ----- Method: String>>includesSubString: (in category 'accessing') -----
includesSubString: subString
^ (self findString: subString startingAt: 1) > 0!
Item was changed:
+ ----- Method: String>>includesSubstring:caseSensitive: (in category 'testing') -----
- ----- Method: String>>includesSubstring:caseSensitive: (in category 'accessing') -----
includesSubstring: aString caseSensitive: caseSensitive
^ (self findString: aString startingAt: 1 caseSensitive: caseSensitive) > 0!
Item was changed:
+ ----- Method: String>>lastSpacePosition (in category 'accessing') -----
- ----- Method: String>>lastSpacePosition (in category 'testing') -----
lastSpacePosition
"Answer the character position of the final space or other separator character in the receiver, and 0 if none"
self size to: 1 by: -1 do:
[:i | ((self at: i) isSeparator) ifTrue: [^ i]].
^ 0
"
'fred the bear' lastSpacePosition
'ziggie' lastSpacePosition
'elvis ' lastSpacePosition
'wimpy ' lastSpacePosition
'' lastSpacePosition
"!
Item was changed:
+ ----- Method: String>>numArgs (in category 'accessing') -----
- ----- Method: String>>numArgs (in category 'system primitives') -----
numArgs
"Answer either the number of arguments that the receiver would take if considered a selector. Answer -1 if it couldn't be a selector. Note that currently this will answer -1 for anything begining with an uppercase letter even though the system will accept such symbols as selectors. It is intended mostly for the assistance of spelling correction."
| firstChar numColons excess start ix |
self size = 0 ifTrue: [^ -1].
firstChar := self at: 1.
(firstChar isLetter or: [firstChar = $:]) ifTrue:
["Fast reject if any chars are non-alphanumeric
NOTE: fast only for Byte things - Broken for Wide"
self class isBytes
ifTrue: [(self findSubstring: '~' in: self startingAt: 1 matchTable: Tokenish) > 0 ifTrue: [^ -1]]
ifFalse: [2 to: self size do: [:i | (self at: i) tokenish ifFalse: [^ -1]]].
"Fast colon count"
numColons := 0. start := 1.
[(ix := self indexOf: $: startingAt: start) > 0]
whileTrue:
[numColons := numColons + 1.
start := ix + 1].
numColons = 0 ifTrue: [^ 0].
firstChar = $:
ifTrue: [excess := 2 "Has an initial keyword, as #:if:then:else:"]
ifFalse: [excess := 0].
self last = $:
ifTrue: [^ numColons - excess]
ifFalse: [^ numColons - excess - 1 "Has a final keywords as #nextPut::andCR"]].
firstChar isSpecial ifTrue:
[self size = 1 ifTrue: [^ 1].
2 to: self size do: [:i | (self at: i) isSpecial ifFalse: [^ -1]].
^ 1].
^ -1.!
Item was changed:
+ ----- Method: String>>startsWithDigit (in category 'testing') -----
- ----- Method: String>>startsWithDigit (in category 'accessing') -----
startsWithDigit
"Answer whether the receiver's first character represents a digit"
^ self size > 0 and: [self first isDigit]!
Item was changed:
+ ----- Method: String>>string (in category 'converting') -----
- ----- Method: String>>string (in category 'accessing') -----
string
^self!
Alexander Lazarević uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-laza.428.mcz
==================== Summary ====================
Name: Collections-laza.428
Author: laza
Time: 26 February 2011, 11:31:16.656 am
UUID: f943155d-9f78-844d-9db4-9ae5396da757
Ancestors: Collections-ul.427
Some minor recats
=============== Diff against Collections-ul.427 ===============
Item was changed:
+ ----- Method: String>>endsWith: (in category 'testing') -----
- ----- Method: String>>endsWith: (in category 'comparing') -----
endsWith: suffix
"Answer whether the tail end of the receiver is the same as suffix.
The comparison is case-sensitive."
| extra |
(extra := self size - suffix size) < 0 ifTrue: [^ false].
^ (self findString: suffix startingAt: extra + 1) > 0
"
'Elvis' endsWith: 'vis'
"!
Item was changed:
+ ----- Method: String>>endsWithAColon (in category 'testing') -----
- ----- Method: String>>endsWithAColon (in category 'system primitives') -----
endsWithAColon
"Answer whether the final character of the receiver is a colon"
^ self size > 0 and: [self last == $:]
"
#fred: endsWithAColon
'fred' endsWithAColon
"!
Item was changed:
+ ----- Method: String>>endsWithAnyOf: (in category 'testing') -----
- ----- Method: String>>endsWithAnyOf: (in category 'comparing') -----
endsWithAnyOf: aCollection
aCollection do:[:suffix|
(self endsWith: suffix) ifTrue:[^true].
].
^false!
Item was changed:
+ ----- Method: String>>endsWithDigit (in category 'testing') -----
- ----- Method: String>>endsWithDigit (in category 'accessing') -----
endsWithDigit
"Answer whether the receiver's final character represents a digit. 3/11/96 sw"
^ self size > 0 and: [self last isDigit]!
Item was changed:
+ ----- Method: String>>findSubstring:in:startingAt:matchTable: (in category 'accessing') -----
- ----- Method: String>>findSubstring:in:startingAt:matchTable: (in category 'system primitives') -----
findSubstring: key in: body startingAt: start matchTable: matchTable
"Answer the index in the string body at which the substring key first occurs, at or beyond start. The match is determined using matchTable, which can be used to effect, eg, case-insensitive matches. If no match is found, zero will be returned."
| index c1 c2 |
matchTable == nil ifTrue: [
key size = 0 ifTrue: [^ 0].
start to: body size - key size + 1 do:
[:startIndex |
index := 1.
[(body at: startIndex+index-1)
= (key at: index)]
whileTrue:
[index = key size ifTrue: [^ startIndex].
index := index+1]].
^ 0
].
key size = 0 ifTrue: [^ 0].
start to: body size - key size + 1 do:
[:startIndex |
index := 1.
[c1 := body at: startIndex+index-1.
c2 := key at: index.
((c1 leadingChar = 0 and: [ c1 asciiValue < matchTable size ])
ifTrue: [ matchTable at: c1 asciiValue + 1 ]
ifFalse: [ c1 asciiValue + 1 ]) =
((c2 leadingChar = 0 and: [ c2 asciiValue < matchTable size ])
ifTrue: [ matchTable at: c2 asciiValue + 1 ]
ifFalse: [c2 asciiValue + 1 ]) ]
whileTrue:
[index = key size ifTrue: [^ startIndex].
index := index+1]].
^ 0!
Item was changed:
+ ----- Method: String>>includesSubString: (in category 'testing') -----
- ----- Method: String>>includesSubString: (in category 'accessing') -----
includesSubString: subString
^ (self findString: subString startingAt: 1) > 0!
Item was changed:
+ ----- Method: String>>includesSubstring:caseSensitive: (in category 'testing') -----
- ----- Method: String>>includesSubstring:caseSensitive: (in category 'accessing') -----
includesSubstring: aString caseSensitive: caseSensitive
^ (self findString: aString startingAt: 1 caseSensitive: caseSensitive) > 0!
Item was changed:
+ ----- Method: String>>lastSpacePosition (in category 'accessing') -----
- ----- Method: String>>lastSpacePosition (in category 'testing') -----
lastSpacePosition
"Answer the character position of the final space or other separator character in the receiver, and 0 if none"
self size to: 1 by: -1 do:
[:i | ((self at: i) isSeparator) ifTrue: [^ i]].
^ 0
"
'fred the bear' lastSpacePosition
'ziggie' lastSpacePosition
'elvis ' lastSpacePosition
'wimpy ' lastSpacePosition
'' lastSpacePosition
"!
Item was changed:
+ ----- Method: String>>numArgs (in category 'accessing') -----
- ----- Method: String>>numArgs (in category 'system primitives') -----
numArgs
"Answer either the number of arguments that the receiver would take if considered a selector. Answer -1 if it couldn't be a selector. Note that currently this will answer -1 for anything begining with an uppercase letter even though the system will accept such symbols as selectors. It is intended mostly for the assistance of spelling correction."
| firstChar numColons excess start ix |
self size = 0 ifTrue: [^ -1].
firstChar := self at: 1.
(firstChar isLetter or: [firstChar = $:]) ifTrue:
["Fast reject if any chars are non-alphanumeric
NOTE: fast only for Byte things - Broken for Wide"
self class isBytes
ifTrue: [(self findSubstring: '~' in: self startingAt: 1 matchTable: Tokenish) > 0 ifTrue: [^ -1]]
ifFalse: [2 to: self size do: [:i | (self at: i) tokenish ifFalse: [^ -1]]].
"Fast colon count"
numColons := 0. start := 1.
[(ix := self indexOf: $: startingAt: start) > 0]
whileTrue:
[numColons := numColons + 1.
start := ix + 1].
numColons = 0 ifTrue: [^ 0].
firstChar = $:
ifTrue: [excess := 2 "Has an initial keyword, as #:if:then:else:"]
ifFalse: [excess := 0].
self last = $:
ifTrue: [^ numColons - excess]
ifFalse: [^ numColons - excess - 1 "Has a final keywords as #nextPut::andCR"]].
firstChar isSpecial ifTrue:
[self size = 1 ifTrue: [^ 1].
2 to: self size do: [:i | (self at: i) isSpecial ifFalse: [^ -1]].
^ 1].
^ -1.!
Item was changed:
+ ----- Method: String>>startsWithDigit (in category 'testing') -----
- ----- Method: String>>startsWithDigit (in category 'accessing') -----
startsWithDigit
"Answer whether the receiver's first character represents a digit"
^ self size > 0 and: [self first isDigit]!
Item was changed:
+ ----- Method: String>>string (in category 'converting') -----
- ----- Method: String>>string (in category 'accessing') -----
string
^self!
Chris Muller uploaded a new version of Files to project The Trunk:
http://source.squeak.org/trunk/Files-cmm.101.mcz
==================== Summary ====================
Name: Files-cmm.101
Author: cmm
Time: 24 February 2011, 7:19:36.954 pm
UUID: 3463cdfa-5a3c-4e33-8c70-22a5f5be61fa
Ancestors: Files-cmm.100
Added conventional and necessary type-checking to new DirectoryEntry>>#=.
=============== Diff against Files-cmm.100 ===============
Item was changed:
----- Method: DirectoryEntry>>= (in category 'testing') -----
= aDirectoryEntry
"Answer whether I am equivalent in all of my file-system attributes."
+ super = aDirectoryEntry ifTrue: [^ true].
+ self species = aDirectoryEntry species ifFalse: [^ false].
^ self containingDirectory = aDirectoryEntry containingDirectory
and: [self name = aDirectoryEntry name
and: [self modificationTime = aDirectoryEntry modificationTime
and: [self fileSize = aDirectoryEntry fileSize]]]!