<> DIRECTORY Convert USING [IntFromRope, ValueToRope], GEditIO, GEditViewer, Rope USING [Cat, Concat, Equal, Fetch, ROPE, Size, Substr]; GEditIOImpl: PROGRAM IMPORTS Convert, Rope EXPORTS GEditIO = BEGIN OPEN GEditViewer; GetInteger: PUBLIC PROC [rope: Rope.ROPE, offset: INT] RETURNS [value: INTEGER, newOffset: INT] = BEGIN token: Rope.ROPE; [token, newOffset] _ GetToken[rope, offset]; value _ Convert.IntFromRope[token]; END; GetInt: PUBLIC PROC [rope: Rope.ROPE, offset: INT] RETURNS [value: INT, newOffset: INT] = BEGIN token: Rope.ROPE; [token, newOffset] _ GetToken[rope, offset]; value _ Convert.IntFromRope[token]; END; GetBoolean: PUBLIC PROC [rope: Rope.ROPE, offset: INT] RETURNS [value: BOOL, newOffset: INT] = BEGIN token: Rope.ROPE; [token, newOffset] _ GetToken[rope, offset]; value _ Rope.Equal[token, "T"]; END; GetRope: PUBLIC PROC [rope: Rope.ROPE, offset: INT] RETURNS [value: Rope.ROPE, newOffset: INT] = BEGIN [value, newOffset] _ GetToken[rope, offset, TRUE]; END; GetToken: PROC [rope: Rope.ROPE, offset: INT _ 0, thruEnd: BOOL _ FALSE] RETURNS [token: Rope.ROPE, newOffset: INT] = BEGIN size: INT = Rope.Size[rope]; start: INT; Sep: PROC [c: CHARACTER] RETURNS [BOOL] = INLINE BEGIN RETURN[SELECT c FROM ' , ',, 11C, 15C, 0C => TRUE, ENDCASE => FALSE]; END; IF offset>=size THEN RETURN["", offset]; WHILE offset=size THEN EXIT; IF Sep[Rope.Fetch[rope, offset]] THEN EXIT; offset _ offset+1; ENDLOOP; RETURN[Rope.Substr[rope, start, IF thruEnd THEN size ELSE offset-start], offset]; END; PutInteger: PUBLIC PROC [rope: Rope.ROPE, value: INTEGER] RETURNS [newRope: Rope.ROPE] = {newRope _ Rope.Cat[rope, Convert.ValueToRope[[signed[value, 10]]], ","]}; PutInt: PUBLIC PROC [rope: Rope.ROPE, value: INT] RETURNS [newRope: Rope.ROPE] = {newRope _ Rope.Cat[rope, Convert.ValueToRope[[signed[value, 10]]], ","]}; PutBoolean: PUBLIC PROC [rope: Rope.ROPE, value: BOOL] RETURNS [newRope: Rope.ROPE] = {newRope _ Rope.Concat[rope, IF value THEN "T," ELSE "F,"]}; END.