WalnutDocumentRopeImpl.Mesa
Copyright © 1984, 1985 by Xerox Corporation. All rights reserved.
Willie-Sue, March 20, 1985 8:38:32 am PST
Russ Atkinson (RRA) March 21, 1985 2:16:00 am PST
DIRECTORY
Rope,
TextNode,
WalnutDocumentRope;
WalnutDocumentRopeImpl: CEDAR PROGRAM
IMPORTS TextNode, Rope
EXPORTS WalnutDocumentRope
= BEGIN
ROPE: TYPE = Rope.ROPE;
Create: PUBLIC PROC [doc: TextNode.Ref] RETURNS [r: ROPE] = {
docSize: INT ← TextNode.LocOffset[[doc,0], TextNode.LastLocWithin[doc]];
r ← Rope.MakeRope[base: doc, size: docSize, fetch: Fetch];
IF docSize > 0 THEN {
loc0: TextNode.Location = TextNode.LocRelative[[doc,0], 0];
loc1: TextNode.Location = TextNode.LocRelative[[doc,0], 1];
IF loc0 = loc1 THEN {
RRA: I think that this is a bug! But we have observed this, so we have to correct for it, I think. I wish that this were not the case.
r ← Rope.Substr[r, 1];
};
};
};
Fetch: PROC [data: REF, index: INT] RETURNS [CHAR] = {
doc: TextNode.Ref ← NARROW[data];
loc: TextNode.Location = TextNode.LocRelative[[doc,0], index];
n: TextNode.RefTextNode = TextNode.NarrowToTextNode[loc.node];
IF n=NIL THEN ERROR;
IF loc.where >= Rope.Size[n.rope] THEN RETURN ['\n];
RETURN [Rope.Fetch[n.rope, loc.where]]
};
END.