The Trunk: Kernel-ar.381.mcz

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

The Trunk: Kernel-ar.381.mcz

commits-2
Andreas Raab uploaded a new version of Kernel to project The Trunk:
http://source.squeak.org/trunk/Kernel-ar.381.mcz

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

Name: Kernel-ar.381
Author: ar
Time: 23 January 2010, 2:18:00.652 pm
UUID: 334b9670-3205-1442-846a-04eaacc81774
Ancestors: Kernel-nice.380, Kernel-Igor.Stasenko.377

Merging Kernel-Igor.Stasenko.377:

- Date class>>#readFrom:pattern:

(cross-fork compatibility)

=============== Diff against Kernel-nice.380 ===============

Item was added:
+ ----- Method: Date class>>readFrom:pattern: (in category 'squeak protocol') -----
+ readFrom: inputStream pattern: pattern
+ "Read a Date from the stream based on the pattern which can include the tokens:
+
+ y = A year with 1-n digits
+ yy = A year with 2 digits
+ yyyy = A year with 4 digits
+ m = A month with 1-n digits
+ mm = A month with 2 digits
+ d = A day with 1-n digits
+ dd = A day with 2 digits
+
+ ...and any other Strings inbetween. Representing $y, $m and $d is done using
+ \y, \m and \d and slash itself with \\. Simple example patterns:
+
+ 'yyyy-mm-dd'
+ 'yyyymmdd'
+ 'yy.mm.dd'
+ 'y-m-d'
+
+ A year given using only two decimals is considered to be >2000."
+
+ | day month year patternStream char |
+ patternStream := pattern readStream.
+ [patternStream atEnd] whileFalse: [
+ inputStream atEnd ifTrue: [^nil].
+ char := patternStream next.
+ char = $\
+ ifTrue: [inputStream next = patternStream next ifFalse: [^nil]]
+ ifFalse: [
+ char = $y
+ ifTrue: [
+ (patternStream nextMatchAll: 'yyy')
+ ifTrue: [year := (inputStream next: 4) asInteger]
+ ifFalse: [
+ (patternStream peekFor: $y)
+ ifTrue: [
+ year := (inputStream next: 2) asInteger]
+ ifFalse: [
+ year := Integer readFrom: inputStream]]]
+ ifFalse: [
+ char = $m
+ ifTrue: [
+ (patternStream peekFor: $m)
+ ifTrue: [
+ month := (inputStream next: 2) asInteger]
+ ifFalse: [
+ month := Integer readFrom: inputStream]]
+ ifFalse: [
+ char = $d
+ ifTrue: [
+ (patternStream peekFor: $d)
+ ifTrue: [
+ day := (inputStream next: 2) asInteger]
+ ifFalse: [
+ day := Integer readFrom: inputStream]]
+ ifFalse: [
+ inputStream next = char ifFalse: [^nil]]]]]].
+ (year isNil | month isNil | day isNil) ifTrue: [^nil].
+ ^self year: year month: month day: day!