[Pkg] The Trunk: Collections-nice.280.mcz
commits at source.squeak.org
commits at source.squeak.org
Mon Jan 18 23:43:49 UTC 2010
Nicolas Cellier uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-nice.280.mcz
==================== Summary ====================
Name: Collections-nice.280
Author: nice
Time: 19 January 2010, 12:43:28.817 am
UUID: daaafc43-9896-4a4a-88cd-ac3c4255a745
Ancestors: Collections-nice.279
Fast-up linesDo: & co
Same idea than withSqueakLineEndings
=============== Diff against Collections-nice.279 ===============
Item was changed:
----- Method: Collection>>do:displayingProgress:every: (in category 'enumerating') -----
do: aBlock displayingProgress: aStringOrBlock every: msecs
"Enumerate aBlock displaying progress information.
If the argument is a string, use a static label for the process.
If the argument is a block, evaluate it with the element to retrieve the label.
The msecs argument ensures that updates happen at most every msecs.
Example:
Smalltalk allClasses
do:[:aClass| (Delay forMilliseconds: 1) wait]
displayingProgress:[:aClass| 'Processing ', aClass name]
every: 0.
Smalltalk allClasses
do:[:aClass| (Delay forMilliseconds: 1) wait]
displayingProgress:[:aClass| 'Processing ', aClass name]
every: 100.
"
+ | size labelBlock count oldLabel lastUpdate |
- | count size labelBlock oldLabel newLabel lastUpdate |
labelBlock := aStringOrBlock isString
ifTrue:[[:item| aStringOrBlock]]
ifFalse:[aStringOrBlock].
oldLabel := nil.
count := lastUpdate := 0.
size := self size.
'' displayProgressAt: Sensor cursorPoint from: 0 to: size during:[:bar |
+ self do:[:each| | newLabel |
- self do:[:each|
"Special handling for first and last element"
(count = 0 or:[count+1 = size
or:[(Time millisecondsSince: lastUpdate) >= msecs]]) ifTrue:[
bar value: count.
oldLabel = (newLabel := labelBlock value: each) ifFalse:[
ProgressNotification signal: '' extra: (oldLabel := newLabel).
].
lastUpdate := Time millisecondClockValue.
].
aBlock value: each.
count := count + 1.
]]!
Item was changed:
----- Method: Text>>emphasisAt: (in category 'emphasis') -----
emphasisAt: characterIndex
"Answer the fontfor characters in the run beginning at characterIndex."
+ | attributes |
- | attributes emph |
self size = 0 ifTrue: [^ 0]. "null text tolerates access"
- emph := 0.
attributes := runs at: characterIndex.
+ ^attributes inject: 0 into:
+ [:emph :att | emph bitOr: att emphasisCode].
- attributes do:
- [:att | emph := emph bitOr: att emphasisCode].
- ^ emph
!
Item was changed:
----- Method: String>>lineIndicesDo: (in category 'accessing') -----
lineIndicesDo: aBlock
"execute aBlock with 3 arguments for each line:
- start index of line
- end index of line without line delimiter
- end index of line including line delimiter(s) CR, LF or CRLF"
+ | cr lf start sz nextLF nextCR |
- | start end endWithoutDelimiters |
start := 1.
+ sz := self size.
+ cr := Character cr.
+ nextCR := self indexOf: cr startingAt: 1.
+ lf := Character lf.
+ nextLF := self indexOf: lf startingAt: 1.
+ [ start <= sz ] whileTrue: [
+ (nextLF = 0 and: [ nextCR = 0 ])
+ ifTrue: [ "No more CR, nor LF, the string is over"
+ aBlock value: start value: sz value: sz.
+ ^self ].
+ (nextCR = 0 or: [ 0 < nextLF and: [ nextLF < nextCR ] ])
+ ifTrue: [ "Found a LF"
+ aBlock value: start value: nextLF - 1 value: nextLF.
+ start := 1 + nextLF.
+ nextLF := self indexOf: lf startingAt: start ]
+ ifFalse: [ 1 + nextCR = nextLF
+ ifTrue: [ "Found a CR-LF pair"
+ aBlock value: start value: nextCR - 1 value: nextLF.
+ start := 1 + nextLF.
+ nextCR := self indexOf: cr startingAt: start.
+ nextLF := self indexOf: lf startingAt: start ]
+ ifFalse: [ "Found a CR"
+ aBlock value: start value: nextCR - 1 value: nextCR.
+ start := 1 + nextCR.
+ nextCR := self indexOf: cr startingAt: start ]]]!
- [ start <= self size ] whileTrue: [
- end := self indexOfAnyOf: CSLineEnders startingAt: start ifAbsent: [ 0 ].
- end = 0
- ifTrue: [endWithoutDelimiters := end := self size]
- ifFalse: [endWithoutDelimiters := end - 1.
- (end < self size
- and: [(self at: end + 1) = Character lf
- and: [(self at: end) = Character cr]])
- ifTrue: [end := end + 1]].
- aBlock value: start value: endWithoutDelimiters value: end.
- start := end + 1]!
More information about the Packages
mailing list