The Trunk: Collections-ul.741.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-ul.741.mcz

commits-2
Levente Uzonyi uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-ul.741.mcz

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

Name: Collections-ul.741
Author: ul
Time: 12 March 2017, 10:38:18.989253 pm
UUID: aca328b5-8334-400c-b7d9-9bf1ce83f49f
Ancestors: Collections-fn.740

- trimmed some more #ifAbsent: sends

=============== Diff against Collections-fn.740 ===============

Item was changed:
  ----- Method: SequenceableCollection>>copyReplaceAll:with:asTokens: (in category 'private') -----
  copyReplaceAll: oldSubstring with: newSubstring asTokens: ifTokens
  "Answer a copy of the receiver in which all occurrences of
  oldSubstring have been replaced by newSubstring.
  ifTokens (valid for Strings only) specifies that the characters
  surrounding the recplacement must not be alphanumeric.
  Bruce Simth,  must be incremented by 1 and not
  newSubstring if ifTokens is true.  See example below. "
 
  | currentIndex |
  (ifTokens and: [ self isString not and: [ self isText not ] ]) ifTrue: [
  self error: 'Token replacement only valid for Strings' ].
+ (currentIndex := self indexOfSubCollection: oldSubstring startingAt: 1) = 0 ifTrue: [ ^self copy ].
- (currentIndex := self indexOfSubCollection: oldSubstring startingAt: 1 ifAbsent: 0) = 0 ifTrue: [ ^self copy ].
  oldSubstring size = newSubstring size ifTrue: [ "Special case"
  | string startSearch endIndex |
  string := self copy.
  startSearch := 1.
  [
  endIndex := currentIndex + oldSubstring size - 1.
  (ifTokens and: [
  (currentIndex > 1 and: [ (self at: currentIndex - 1) isAlphaNumeric ])
  or: [ endIndex < self size and: [ (self at: endIndex + 1) isAlphaNumeric ] ] ])
  ifFalse: [ "match"
  string
  replaceFrom: currentIndex
  to: endIndex
  with: newSubstring
  startingAt: 1 ].
  startSearch := endIndex + 1.
+ (currentIndex := self indexOfSubCollection: oldSubstring startingAt: startSearch) = 0 ] whileFalse.
- (currentIndex := self indexOfSubCollection: oldSubstring startingAt: startSearch ifAbsent: 0) = 0 ] whileFalse.
  ^string ].
  ^self species new: self size streamContents: [ :stream |
  | startSearch endIndex |
  startSearch := 1.
  [
  endIndex := currentIndex + oldSubstring size - 1.
  (ifTokens and: [
  (currentIndex > 1 and: [ (self at: currentIndex - 1) isAlphaNumeric ])
  or: [ endIndex < self size and: [ (self at: endIndex + 1) isAlphaNumeric ] ] ])
  ifFalse: [ "match"
  stream
  next: currentIndex - startSearch
  putAll: self
  startingAt: startSearch;
  nextPutAll: newSubstring ]
  ifTrue: [
  stream
  next: currentIndex - startSearch + oldSubstring size
  putAll: self
  startingAt: startSearch ].
  startSearch := endIndex + 1.
+ (currentIndex := self indexOfSubCollection: oldSubstring startingAt: startSearch) = 0 ] whileFalse.
- (currentIndex := self indexOfSubCollection: oldSubstring startingAt: startSearch ifAbsent: 0) = 0 ] whileFalse.
  stream
  next: self size - startSearch + 1
  putAll: self
  startingAt: startSearch ]
 
  "Test case:
  'test te string' copyReplaceAll: 'te' with: 'longone' asTokens: true   "!