On 11/23/2011 11:59 AM, maarten wrote:
Hee,

I've fixed two bugs in the VFSAddOns package, both in fileData, which
should make the package usable now.
The first bug was a little hard to find as it seemed to be time related.
It showed up every now and then. It seemed to be the case that a pipe
was still being read out while it's output was already being processed.

Hi Maarten. Do you have a reproducer? In this case, the pipe should block until all data is read.

The second bug. fileData returns an array with some information, but the
VFSAddOns package didn't fill every variable in this array. A loop goes
over a string and extracts information from it. The Date package read
the string till the end while processing the date, leaving no data for
any processing after it.

I think the bug here is in the Date/Duration/DateTime readers. Does something like the attached patch (lightly tested) help?

Paolo
diff --git a/kernel/AnsiDates.st b/kernel/AnsiDates.st
index f04b9c8..a170291 100644
--- a/kernel/AnsiDates.st
+++ b/kernel/AnsiDates.st
@@ -111,7 +111,18 @@ Date subclass: DateTime [
        "Parse an instance of the receiver from aStream"
 
        <category: 'instance creation'>
-       ^(super readFrom: aStream) + (Duration readFrom: aStream)
+        | date time ofs ch |
+        date := super readFrom: aStream.
+        (aStream peekFor: $T) ifFalse: [aStream skipSeparators].
+        time := aStream peek isDigit
+            ifTrue: [Duration readFrom: aStream]
+            ifFalse: [Duration zero].
+        aStream skipSeparators.
+        ch := aStream peek.
+        (ch = $+ or: [ch = $-]) ifFalse: [^date + time].
+        aStream next.
+        ofs := Duration readFrom: aStream.
+        ^(date + time) setOffset: ofs
     ]
 
     DateTime class >> today [
@@ -584,25 +595,26 @@ Time subclass: Duration [
          aStream"
 
         <category: 'instance creation'>
-        | t1 t2 t3 t4 i ch ws |
-        t1 := t2 := t3 := t4 := 0.
-        ch := $:.
+        | sign sec hms i ch ws |
+        hms := {0. 0. 0}.
+        sign := (aStream peekFor: $-) ifTrue: [-1] ifFalse: [1].
         i := 1.
-        [i <= 4 and: [(aStream atEnd not and: [ch isSeparator not]) or: [i < 
4]]] whileTrue: [
+        ch := $:.
+        [i <= 4 and: [aStream atEnd not and: [ch isSeparator not]]] whileTrue: 
[
             ws := WriteStream on: (String new: 10).
-
-            ch := $:.
-            [aStream atEnd not and: [(ch := aStream next) isDigit not]] 
whileTrue.
-            ch isDigit ifTrue: [
-                [ws nextPut: ch.
-                aStream atEnd not and: [(ch := aStream next) isDigit]]
-                        whileTrue].
-           t1 := t2.
-           t2 := t3.
-           t3 := t4.
-            t4 := ws contents asNumber.
+            [aStream atEnd not and: [(ch := aStream next) isDigit]]
+                whileTrue: [ws nextPut: ch].
+            i = 4
+                ifTrue: [
+                    hms := {
+                        (hms at: 1) * 24 + (hms at: 2).
+                        hms at: 3.
+                        ws contents asNumber}]
+                ifFalse: [
+                    hms at: i put: ws contents asNumber].
            i := i + 1].
-        ^self fromSeconds: (t1 * 24 + t2) * 3600 + (t3 * 60) + t4
+        sec := ((hms at: 1) * 3600 + ((hms at: 2) * 60) + (hms at: 3)) * sign.
+        ^self fromSeconds: sec
     ]
 
     Duration class >> initialize [
diff --git a/kernel/Date.st b/kernel/Date.st
index fb961b7..3751d79 100644
--- a/kernel/Date.st
+++ b/kernel/Date.st
@@ -255,12 +255,16 @@ method.'>
                ws := WriteStream on: (String new: 10).
                [aStream atEnd not and: [(ch := aStream next) isAlphaNumeric 
not]] 
                    whileTrue.
-               ch isAlphaNumeric 
+               ch isLetter
                    ifTrue: 
-                       [
-                       [ws nextPut: ch.
-                       aStream atEnd not and: [(ch := aStream next) 
isAlphaNumeric]] 
-                               whileTrue].
+                       [[ws nextPut: ch.
+                       aStream atEnd not and: [(ch := aStream next) isLetter]] 
+                               whileTrue]
+                    ifFalse: [
+                       ch isDigit ifTrue: 
+                           [[ws nextPut: ch.
+                           aStream atEnd not and: [(ch := aStream next) 
isDigit]] 
+                                   whileTrue]].
                t1 := t2.
                t2 := t3.
                t3 := ws contents.
diff --git a/kernel/Time.st b/kernel/Time.st
index d3810e7..99289d3 100644
--- a/kernel/Time.st
+++ b/kernel/Time.st
@@ -245,26 +245,17 @@ time value, and a block execution timing facility.'>
         aStream"
 
        <category: 'instance creation'>
-       | t1 t2 t3 ch ws |
-       t1 := t2 := t3 := 0.
-       ch := $:.
-       3 timesRepeat: 
-               [t1 := t2.
-               t2 := t3.
-               t3 := 0.
-               ch isSeparator 
-                   ifFalse: 
-                       [ws := WriteStream on: (String new: 10).
-                       ch := $:.
-                       [aStream atEnd not and: [(ch := aStream next) isDigit 
not]] whileTrue.
-                       ch isDigit 
-                           ifTrue: 
-                               [
-                               [ws nextPut: ch.
-                               aStream atEnd not and: [(ch := aStream next) 
isDigit]] 
-                                       whileTrue].
-                       t3 := ws contents asNumber]].
-       ^self fromSeconds: t1 * 3600 + (t2 * 60) + t3
+        | hms i ch ws |
+        hms := {0. 0. 0}.
+        i := 1.
+        ch := $:.
+        [i <= 3 and: [aStream atEnd not and: [ch isSeparator not]]] whileTrue: 
[
+            ws := WriteStream on: (String new: 10).
+            [aStream atEnd not and: [(ch := aStream next) isDigit]]
+                whileTrue: [ws nextPut: ch].
+            hms at: i put: ws contents asNumber.
+            i := i + 1].
+        ^self fromSeconds: (hms at: 1) * 3600 + ((hms at: 2) * 60) + (hms at: 
3)
     ]
 
     Time class >> millisecondClockValue [
_______________________________________________
help-smalltalk mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/help-smalltalk

Reply via email to