TEditDocumentRopeImpl.mesa
Copyright © 1985, 1986 by Xerox Corporation. All rights reserved.
written by Bill Paxton. March 31, 1983
last written by Paxton. March 31, 1983 9:22 am
Doug Wyatt, September 2, 1986 2:48:12 pm PDT
DIRECTORY
Rope USING [Fetch, MakeRope, ROPE, Size],
TEditDocumentRope USING [],
TextNode USING [LastLocWithin, Location, LocOffset, LocRelative, Node];
TEditDocumentRopeImpl: CEDAR PROGRAM
IMPORTS Rope, TextNode
EXPORTS TEditDocumentRope
= BEGIN
Fetch: PROC [data: REF, index: INT] RETURNS [CHAR] = {
doc: TextNode.Node ← NARROW[data];
loc: TextNode.Location = TextNode.LocRelative[[doc,0], index];
n: TextNode.Node = loc.node;
IF n=NIL THEN ERROR;
IF loc.where >= Rope.Size[n.rope] THEN RETURN ['\n];
RETURN [Rope.Fetch[n.rope, loc.where]]
};
Create: PUBLIC PROC [doc: TextNode.Node] RETURNS [r: Rope.ROPE] = {
docSize: INT = TextNode.LocOffset[[doc,0], TextNode.LastLocWithin[doc]];
RETURN[Rope.MakeRope[base: doc, size: docSize, fetch: Fetch]];
};
END.