IF
NOT Rope.IsEmpty[key]
AND
NOT Rope.IsEmpty[sub]
THEN {
writer: TiogaAccess.Writer ¬ TiogaAccess.Create[];
firstKeyChar: CHAR ¬ Ascii.Lower[Rope.Fetch[key]];
keyLen: NAT ¬ Rope.Length[key];
subLen: NAT ¬ Rope.Length[sub];
keyChars: REF CharSequence ¬ NEW[CharSequence[keyLen]];
subChars: REF CharSequence ¬ NEW[CharSequence[subLen]];
tiogaChars: REF TiogaCharSequence ¬ NEW[TiogaCharSequence[keyLen]];
FOR n: NAT IN [0..keyLen) DO keyChars[n] ¬ Ascii.Lower[Rope.Fetch[key, n]]; ENDLOOP;
FOR n: NAT IN [0..subLen) DO subChars[n] ¬ Rope.Fetch[sub, n]; ENDLOOP;
DO
tiogaChar: TiogaChar;
CedarProcess.CheckAbort[];
IF TiogaAccess.EndOf[reader]
THEN {
IF nSubs > 0 THEN TiogaAccess.WriteFile[writer, fileName];
EXIT;
};
tiogaChar ¬ tiogaChars[0] ¬ TiogaAccess.Get[reader];
IF Ascii.Lower[tiogaChar.char] = firstKeyChar
THEN {
FOR n:
NAT
IN [1..keyLen)
DO
IF TiogaAccess.EndOf[reader] THEN EXIT;
tiogaChars[n] ¬ TiogaAccess.Get[reader];
IF Ascii.Lower[tiogaChars[n].char] # keyChars[n]
THEN {
FOR i: INT IN [0..n] DO TiogaAccess.Put[writer, tiogaChars[i]]; ENDLOOP;
EXIT;
};
REPEAT
FINISHED => {
nSubs ¬ nSubs+1;
subChars[0] ¬
SELECT tiogaChar.char
FROM
IN ['A..'Z] => Ascii.Upper[subChars[0]],
IN ['a..'z] => Ascii.Lower[subChars[0]],
ENDCASE => subChars[0];
FOR n:
NAT
IN [0..subLen)
DO
tiogaChar.char ¬ subChars[n];
TiogaAccess.Put[writer, tiogaChar];
ENDLOOP;
};
ENDLOOP;
}
ELSE TiogaAccess.Put[writer, tiogaChar];
ENDLOOP;
};