The Trunk: Collections-nice.279.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Trunk: Collections-nice.279.mcz

commits-2
Nicolas Cellier uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-nice.279.mcz

==================== Summary ====================

Name: Collections-nice.279
Author: nice
Time: 18 January 2010, 11:40:13.347 pm
UUID: 161387ef-e444-46d2-9a5e-4a744bff3e97
Ancestors: Collections-ar.278

remove a useless fixTemps
fast-up #withInternetLineEndings a bit
fast-up #withSqueakLineEndings substantially
add a fast #withUnixLineEndings


=============== Diff against Collections-ar.278 ===============

Item was added:
+ ----- Method: String>>withUnixLineEndings (in category 'internet') -----
+ withUnixLineEndings
+ "Assume the string is textual, and that CR, LF, and CRLF are all valid line endings.
+ Replace each occurence with a single LF."
+ | cr lf inPos outPos outString newOutPos indexLF indexCR |
+ cr := Character cr.
+ indexCR := self indexOf: cr startingAt: 1.
+ indexCR = 0 ifTrue: [^self].
+
+ lf := Character linefeed.
+ indexLF := self indexOf: lf startingAt: 1.
+ indexLF = 0 ifTrue: [^self copy replaceAll: cr with: lf].
+
+ inPos := outPos := 1.
+ outString := String new: self size.
+
+ ["check if next CR is before next LF or if there are no more LF"
+ (indexLF = 0 or: [indexCR < indexLF])
+ ifTrue: [
+ newOutPos := outPos + 1 + indexCR - inPos.
+ outString replaceFrom: outPos to: newOutPos - 2 with: self startingAt: inPos.
+ outString at: newOutPos - 1 put: lf.
+ outPos := newOutPos.
+ 1 + indexCR = indexLF
+ ifTrue: ["Caught a CR-LF pair"
+ inPos := 1 + indexLF.
+ indexLF := self  indexOf: lf startingAt: inPos]
+ ifFalse: [inPos := 1 + indexCR].
+ indexCR := self indexOf: cr startingAt: inPos]
+ ifFalse: [
+ newOutPos := outPos + 1 + indexLF - inPos.
+ outString replaceFrom: outPos to: newOutPos - 1 with: self startingAt: inPos.
+ outPos := newOutPos.
+ inPos := 1 + indexLF.
+ indexLF := self indexOf: lf startingAt: inPos].
+ indexCR = 0]
+ whileFalse.
+
+ "no more CR line endings.  copy the rest"
+ newOutPos := outPos + (self size - inPos + 1).
+ outString replaceFrom: outPos to: newOutPos - 1 with: self startingAt: inPos.
+ ^outString copyFrom: 1 to: newOutPos - 1!

Item was changed:
  ----- Method: LimitingLineStreamWrapper>>limitingBlock: (in category 'accessing') -----
  limitingBlock: aBlock
  "The limitingBlock is evaluated with a line to check if this line terminates the stream"
 
+ limitingBlock := aBlock.
- limitingBlock := aBlock fixTemps.
  self updatePosition!

Item was changed:
  ----- Method: String>>withSqueakLineEndings (in category 'internet') -----
  withSqueakLineEndings
+ "Assume the string is textual, and that CR, LF, and CRLF are all valid line endings.
+ Replace each occurence with a single CR."
+ | cr lf inPos outPos outString newOutPos indexLF indexCR |
- "assume the string is textual, and that CR, LF, and CRLF are all
- valid line endings.  Replace each occurence with a single CR"
- | cr lf crlf inPos outPos outString lineEndPos newOutPos |
- cr := Character cr.
  lf := Character linefeed.
+ indexLF := self indexOf: lf startingAt: 1.
+ indexLF = 0 ifTrue: [^self].
+
+ cr := Character cr.
+ indexCR := self indexOf: cr startingAt: 1.
+ indexCR = 0 ifTrue: [^self copy replaceAll: lf with: cr].
- crlf := CharacterSet crlf.
 
+ inPos := outPos := 1.
- inPos := 1.
- outPos := 1.
  outString := String new: self size.
 
+ ["check if next CR (if any) is before next LF"
+ (indexCR > 0 and: [indexCR < indexLF])
+ ifTrue: [
+ newOutPos := outPos + 1 + indexCR - inPos.
+ outString replaceFrom: outPos to: newOutPos - 1 with: self startingAt: inPos.
+ outPos := newOutPos.
+ 1 + indexCR = indexLF
+ ifTrue: ["Caught a CR-LF pair"
+ inPos := 1 + indexLF.
+ indexLF := self  indexOf: lf startingAt: inPos]
+ ifFalse: [inPos := 1 + indexCR].
+ indexCR := self indexOf: cr startingAt: inPos]
+ ifFalse: [
+ newOutPos := outPos + 1 + indexLF - inPos.
- [ lineEndPos := self indexOfAnyOf: crlf startingAt: inPos ifAbsent: [0].
- lineEndPos ~= 0 ] whileTrue: [
- newOutPos := outPos + (lineEndPos - inPos + 1).
  outString replaceFrom: outPos to: newOutPos - 2 with: self startingAt: inPos.
+ outString at: newOutPos - 1 put: cr.
- outString at: newOutPos-1 put: cr.
  outPos := newOutPos.
+ inPos := 1 + indexLF.
+ indexLF := self indexOf: lf startingAt: inPos].
+ indexLF = 0]
+ whileFalse.
 
+ "no more LF line endings.  copy the rest"
- ((self at: lineEndPos) = cr and: [ lineEndPos < self size and: [ (self at: lineEndPos+1) = lf ] ]) ifTrue: [
- "CRLF ending"
- inPos := lineEndPos + 2 ]
- ifFalse: [
- "CR or LF ending"
- inPos := lineEndPos + 1 ]. ].
-
- "no more line endings.  copy the rest"
  newOutPos := outPos + (self size - inPos + 1).
+ outString replaceFrom: outPos to: newOutPos - 1 with: self startingAt: inPos.
+ ^outString copyFrom: 1 to: newOutPos - 1!
- outString replaceFrom: outPos to: newOutPos-1 with: self startingAt: inPos.
-
- ^outString copyFrom: 1 to: newOutPos-1
- !

Item was changed:
  ----- Method: String>>withInternetLineEndings (in category 'internet') -----
  withInternetLineEndings
  "change line endings from CR's and LF's to CRLF's.  This is probably in prepration for sending a string over the Internet"
 
  ^self class
  new: self size * 16 // 15 "provisions for CR-LF pairs"
  streamContents: [ :stream |
  self lineIndicesDo: [:start :endWithoutDelimiters :end |
+ stream next: 1 + endWithoutDelimiters - start putAll: self startingAt: start.
- stream nextPutAll: (self copyFrom: start to: endWithoutDelimiters).
  endWithoutDelimiters = end ifFalse: [
  stream crlf ] ] ]!