|
@@ -806,6 +806,12 @@ new
|
|
|
|
|
|
applyTo: anObject arguments: aCollection
|
|
applyTo: anObject arguments: aCollection
|
|
<return self.apply(anObject, aCollection)>
|
|
<return self.apply(anObject, aCollection)>
|
|
|
|
+!
|
|
|
|
+
|
|
|
|
+timeToRun
|
|
|
|
+ "Answer the number of milliseconds taken to execute this block."
|
|
|
|
+
|
|
|
|
+ ^ Date millisecondsToRun: self
|
|
! !
|
|
! !
|
|
|
|
|
|
!BlockClosure methodsFor: 'timeout/interval'!
|
|
!BlockClosure methodsFor: 'timeout/interval'!
|
|
@@ -1665,6 +1671,68 @@ join: aCollection
|
|
streamContents: [:stream | aCollection
|
|
streamContents: [:stream | aCollection
|
|
do: [:each | stream nextPutAll: each asString]
|
|
do: [:each | stream nextPutAll: each asString]
|
|
separatedBy: [stream nextPutAll: self]]
|
|
separatedBy: [stream nextPutAll: self]]
|
|
|
|
+!
|
|
|
|
+
|
|
|
|
+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 := 1.
|
|
|
|
+ sz := self size.
|
|
|
|
+ cr := String cr.
|
|
|
|
+ nextCR := self indexOf: cr startingAt: 1.
|
|
|
|
+ lf := String 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 ]]]
|
|
|
|
+!
|
|
|
|
+
|
|
|
|
+linesDo: aBlock
|
|
|
|
+ "Execute aBlock with each line in this string. The terminating line
|
|
|
|
+ delimiters CR, LF or CRLF pairs are not included in what is passed to aBlock"
|
|
|
|
+
|
|
|
|
+ self lineIndicesDo: [:start :endWithoutDelimiters :end |
|
|
|
|
+ aBlock value: (self copyFrom: start to: endWithoutDelimiters)]
|
|
|
|
+!
|
|
|
|
+
|
|
|
|
+lines
|
|
|
|
+ "Answer an array of lines composing this receiver without the line ending delimiters."
|
|
|
|
+
|
|
|
|
+ | lines |
|
|
|
|
+ lines := Array new.
|
|
|
|
+ self linesDo: [:aLine | lines add: aLine].
|
|
|
|
+ ^lines
|
|
|
|
+!
|
|
|
|
+
|
|
|
|
+lineNumber: anIndex
|
|
|
|
+ "Answer a string containing the characters in the given line number."
|
|
|
|
+
|
|
|
|
+ | lineCount |
|
|
|
|
+ lineCount := 0.
|
|
|
|
+ self lineIndicesDo: [:start :endWithoutDelimiters :end |
|
|
|
|
+ (lineCount := lineCount + 1) = anIndex ifTrue: [^self copyFrom: start to: endWithoutDelimiters]].
|
|
|
|
+ ^nil
|
|
! !
|
|
! !
|
|
|
|
|
|
!String methodsFor: 'testing'!
|
|
!String methodsFor: 'testing'!
|