[squeak-dev] The Inbox: Collections-cwp.491.mcz
commits at source.squeak.org
commits at source.squeak.org
Mon Oct 22 06:37:47 UTC 2012
A new version of Collections was added to project The Inbox:
http://source.squeak.org/inbox/Collections-cwp.491.mcz
==================== Summary ====================
Name: Collections-cwp.491
Author: cwp
Time: 21 October 2012, 11:37:20.466 pm
UUID: ecb9c37e-309e-43eb-8f24-3d5662da038e
Ancestors: Collections-fbs.490
Cleaned up the behavior of #numArgs with respect to selectors containing underscores.
=============== Diff against Collections-fbs.490 ===============
Item was changed:
----- Method: String class>>initialize (in category 'initialization') -----
initialize "self initialize"
| order |
AsciiOrder := (0 to: 255) as: ByteArray.
CaseInsensitiveOrder := AsciiOrder copy.
($a to: $z) do:
[:c | CaseInsensitiveOrder at: c asciiValue + 1
put: (CaseInsensitiveOrder at: c asUppercase asciiValue +1)].
"Case-sensitive compare sorts space, digits, letters, all the rest..."
CaseSensitiveOrder := ByteArray new: 256 withAll: 255.
order := -1.
' 0123456789' do: "0..10"
[:c | CaseSensitiveOrder at: c asciiValue + 1 put: (order := order+1)].
($a to: $z) do: "11-64"
[:c | CaseSensitiveOrder at: c asUppercase asciiValue + 1 put: (order := order+1).
CaseSensitiveOrder at: c asciiValue + 1 put: (order := order+1)].
1 to: CaseSensitiveOrder size do:
[:i | (CaseSensitiveOrder at: i) = 255 ifTrue:
[CaseSensitiveOrder at: i put: (order := order+1)]].
order = 255 ifFalse: [self error: 'order problem'].
"a table for translating to lower case"
LowercasingTable := String withAll: (Character allByteCharacters collect: [:c | c asLowercase]).
"a table for translating to upper case"
UppercasingTable := String withAll: (Character allByteCharacters collect: [:c | c asUppercase]).
"a table for testing tokenish (for fast numArgs)"
+ self initializeTokenish.
- Tokenish := String withAll: (Character allByteCharacters collect:
- [:c | c tokenish ifTrue: [c] ifFalse: [$~]]).
"CR and LF--characters that terminate a line"
CSLineEnders := CharacterSet crlf.
"separators and non-separators"
CSSeparators := CharacterSet separators.
CSNonSeparators := CSSeparators complement.
"% and < for #expandMacros*"
CSMacroCharacters := CharacterSet newFrom: '%<'.
"a table for exchanging cr with lf and vica versa"
CrLfExchangeTable := Character allByteCharacters collect: [ :each |
each
caseOf: {
[ Character cr ] -> [ Character lf ].
[ Character lf ] -> [ Character cr ] }
otherwise: [ each ] ]!
Item was added:
+ ----- Method: String class>>initializeTokenish (in category 'initialization') -----
+ initializeTokenish
+ Tokenish := String withAll:
+ (Character allByteCharacters collect:
+ [ :c |
+ c tokenish
+ ifTrue: [ c ]
+ ifFalse: [ $~ ]]) !
Item was changed:
----- Method: String>>numArgs (in category 'accessing') -----
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]]].
- Scanner prefAllowUnderscoreSelectors ifFalse:
- [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 added:
+ ----- Method: Symbol>>numArgs (in category 'accessing') -----
+ 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:
+ [2 to: self size do:
+ [:i || c |
+ c := self at: i.
+ (c = $_ or: [c 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.!
More information about the Squeak-dev
mailing list
|