The Trunk: Collections-nice.520.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.520.mcz

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

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

Name: Collections-nice.520
Author: nice
Time: 31 May 2013, 12:23:43.567 am
UUID: 6ef25398-faee-45ff-a409-52d3f36d98c8
Ancestors: Collections-fbs.519

Introduce Character null

=============== Diff against Collections-fbs.519 ===============

Item was changed:
  ----- Method: Character class>>constantNames (in category 'private') -----
  constantNames
+ ^ #( backspace cr delete escape lf null newPage space tab ).!
- ^ #( backspace cr delete escape lf newPage space tab ).!

Item was added:
+ ----- Method: Character class>>null (in category 'accessing untypeable characters') -----
+ null
+ ^ self value: 0!

Item was changed:
  ----- Method: NullStream>>element (in category 'accessing') -----
  element
  "The element returned by the stream"
 
+ ^binary ifTrue:[0] ifFalse:[Character null]!
- ^binary ifTrue:[0] ifFalse:[Character value: 0]!

Item was changed:
  ----- Method: String>>compressWithTable: (in category 'converting') -----
  compressWithTable: tokens
  "Return a string with all substrings that occur in tokens replaced
  by a character with ascii code = 127 + token index.
  This will work best if tokens are sorted by size.
  Assumes this string contains no characters > 127, or that they
  are intentionally there and will not interfere with this process."
  | str null finalSize result ri c |
+ null := Character null.
- null := Character value: 0.
  str := self copyFrom: 1 to: self size.  "Working string will get altered"
  finalSize := str size.
  tokens doWithIndex:
  [:token :tIndex |
  | start ts |
  start := 1.
  [(start := str findString: token startingAt: start) > 0]
  whileTrue:
  [ts := token size.
  ((start + ts) <= str size
  and: [(str at: start + ts) = $  and: [tIndex*2 <= 128]])
  ifTrue: [ts := token size + 1.  "include training blank"
  str at: start put: (Character value: tIndex*2 + 127)]
  ifFalse: [str at: start put: (Character value: tIndex + 127)].
  str at: start put: (Character value: tIndex + 127).
  1 to: ts-1 do: [:i | str at: start+i put: null].
  finalSize := finalSize - (ts - 1).
  start := start + ts]].
  result := String new: finalSize.
  ri := 0.
  1 to: str size do:
  [:i | (c := str at: i) = null ifFalse: [result at: (ri := ri+1) put: c]].
  ^ result!