[squeak-dev] Problem handling nextLine

Casimiro de Almeida Barreto casimiro.barreto at gmail.com
Tue Nov 17 19:02:41 UTC 2009


After today's update, the following code:

    [ fHandle atEnd ] whileFalse: [
        stringFromFile := fHandle nextLine.
        draw := Draw newFromString: stringFromFile.
        draw isNil
            ifTrue: [
                Transcript show: 'Failed to load draw.'; cr.
                fHandle close.
                ^nil ].
        model draws addLast: draw ].

Results in the following error:

nextLine
    "Answer next line (may be empty), or nil if at end.
    Handle a zoo of line delimiters CR, LF, or CR-LF pair"

    | newStream element crlf |
    self atEnd ifTrue: [^nil].
    crlf := CharacterSet crlf.
    newStream := WriteStream on: (collection species new: 100).
    [self atEnd ifTrue: [^newStream contents].
    crlf includes: (element := self next)]
        whileFalse: [newStream nextPut: element].
    element = Character cr ifTrue: [self peekFor: Character lf]. "handle
an eventual CR LF pair"
    ^newStream contents

=============================================================

new: sizeRequested
    "Answer an initialized instance of this class with the number of
indexable
    variables specified by the argument, sizeRequested."

    ^ (self basicNew: sizeRequested) initialize 

=============================================================

basicNew: sizeRequested
    "Primitive. Answer an instance of this class with the number
    of indexable variables specified by the argument, sizeRequested.
    Fail if this class is not indexable or if the argument is not a
    positive Integer, or if there is not enough memory available.
    Essential. See Object documentation whatIsAPrimitive."

    <primitive: 71>
    self isVariable ifFalse:
        [self error: self printString, ' cannot have variable sized
instances'].
    (sizeRequested isInteger and: [sizeRequested >= 0]) ifTrue:
        ["arg okay; space must be low."
        self environment signalLowSpace.
        ^ self basicNew: sizeRequested  "retry if user proceeds"].
    self primitiveFailed

=============================================================

error: aString
    "Throw a generic Error exception."

    ^Error new signal: aString

Error: UndefinedObject cannot have variable sized instances


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 260 bytes
Desc: OpenPGP digital signature
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20091117/ae3f40de/signature.pgp


More information about the Squeak-dev mailing list