[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-smalltalk] Streams' copyFrom:to:
From: |
Stephen Compall |
Subject: |
[Help-smalltalk] Streams' copyFrom:to: |
Date: |
Sat, 30 Dec 2006 21:31:53 -0600 |
In 2.3.1 with compiler-cascade.diff and the 3 diffs I posted yesterday
and today, I noticed that FileStream>>#copyFrom:to: uses 0-index,
whereas PositionableStream>>#copyFrom:to: uses 1-index.
st> | fs |
fs := FileStream fopen: '/home/sirian/TODO' mode: FileStream read.
[(fs copyFrom: 1 to: 3) printNl] ensure: [fs close]!
' To'
st> ('* Today' readStream copyFrom: 1 to: 3) printNl!
'* T'
(/home/sirian/TODO starts with '* Today:')
I'll assume that 0-index is intended, because that's what
PositionableStream>>#segmentFrom:to: depends on in compiler/RBParser.st.
On a related note, I found something else in kernel/FileDescr.st:
copyFrom: from to: to
"Answer the contents of the file between the two given positions"
| offset fromPos toPos savePos |
from > to ifTrue: [
from = to + 1 ifTrue: [ ^self species new ].
^SystemExceptions.ArgumentOutOfRange signalOn: from mustBeBetween: 1
and: to + 1
].
savePos := self fileOp: 5.
^[
self position: fromPos.
self next: toPos - fromPos + 1
] ensure: [
self position: savePos
]
How do offset, fromPos, and toPos get set in this method?
--
Stephen Compall
http://scompall.nocandysw.com/blog
signature.asc
Description: This is a digitally signed message part
- [Help-smalltalk] Streams' copyFrom:to:,
Stephen Compall <=