-- TEditDocumentRopeImpl.Mesa
-- written by Bill Paxton. March 31, 1983
-- last written by Paxton. March 31, 1983 9:22 am
DIRECTORY
Rope,
TextNode,
TEditDocumentRope;
TEditDocumentRopeImpl: CEDAR PROGRAM
IMPORTS TextNode, Rope
EXPORTS TEditDocumentRope
SHARES Rope = BEGIN
ObjectRope: TYPE = object node Rope.RopeRep;
Create: PUBLIC PROC [doc: TextNode.Ref] RETURNS [r: Rope.ROPE] = {
docSize: INT = TextNode.LocOffset[[doc,0], TextNode.LastLocWithin[doc]];
RETURN [NEW[ObjectRope ← [node[object[docSize,doc,Fetch,NIL,NIL]]]]] };
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.