Код из "Советов Валентина Озерова":
function rtf2sgml(text: string): string;
var
temptext: string;
start: integer;
begin
text := stringreplaceall(text, '&', '##amp;');
text := stringreplaceall(text, '##amp', '&');
text := stringreplaceall(text, '\' + chr(39) + 'e5', 'a');
text := stringreplaceall(text, '\' + chr(39) + 'c5', 'A');
text := stringreplaceall(text, '\' + chr(39) + 'e4', 'a');
text := stringreplaceall(text, '\' + chr(39) + 'c4', 'A');
text := stringreplaceall(text, '\' + chr(39) + 'f6', 'o');
text := stringreplaceall(text, '\' + chr(39) + 'd6', 'O');
text := stringreplaceall(text, '\' + chr(39) + 'e9', 'e');
text := stringreplaceall(text, '\' + chr(39) + 'c9', 'E');
text := stringreplaceall(text, '\' + chr(39) + 'e1', 'a');
text := stringreplaceall(text, '\' + chr(39) + 'c1', 'A');
text := stringreplaceall(text, '\' + chr(39) + 'e0', 'a');
text := stringreplaceall(text, '\' + chr(39) + 'c0', 'A');
text := stringreplaceall(text, '\' + chr(39) + 'f2', 'o');
text := stringreplaceall(text, '\' + chr(39) + 'd2', 'O');
text := stringreplaceall(text, '\' + chr(39) + 'fc', 'u');
text := stringreplaceall(text, '\' + chr(39) + 'dc', 'U');
text := stringreplaceall(text, '\' + chr(39) + 'a3', '?');
text := stringreplaceall(text, '\}', '#]#');
text := stringreplaceall(text, '\{', '#[#');
text := stringreplaceall(text, '{\rtf1\ansi\deff0\deftab720', '');
text := stringreplaceall(text, '{\fonttbl', '');
text := stringreplaceall(text, '{\f0\fnil MS Sans Serif;}', '');
text := stringreplaceall(text, '{\f1\fnil\fcharset2 Symbol;}', '');
text := stringreplaceall(text, '{\f2\fswiss\fprq2 System;}}', '');
text := stringreplaceall(text, '{\colortbl\red0\green0\blue0;}', '');
text := stringreplaceall(text, '\cf0', '');
temptext := hamtastreng(text, '\deflang', '\pard');
text := stringreplace(text, temptext, '');
while pos('\fs', text) > 0 do
begin
application.processmessages;
start := pos('\fs', text);
Delete(text, start, 5);
end;
text := stringreplaceall(text, '\pard\plain\f0 ', '<P>');
text := stringreplaceall(text, '\par \plain\f0\b\ul ', '</P><MELLIS>');
text := stringreplaceall(text, '\plain\f0\b\ul ', '</P><MELLIS>');
text := stringreplaceall(text, '\plain\f0', '</MELLIS>');
text := stringreplaceall(text, '\par }', '</P>');
text := stringreplaceall(text, '\par ', '</P><P>');
text := stringreplaceall(text, '#]#', '}');
text := stringreplaceall(text, '#[#', '{');
text := stringreplaceall(text, '\\', '\');
result := text;
end;
utfilnamn := mditted.exepath + stringreplace(stringreplace(extractfilename(pathname), '.TTT', ''), '.ttt', '') + 'ut.RTF';
brodtext.lines.savetofile(utfilnamn);
temptext := '';
assignfile(tempF, utfilnamn);
reset(tempF);
try
while not eof(tempF) do
begin
readln(tempF, temptext2);
temptext2 := stringreplaceall(temptext2, '\' + chr(39) + 'b6', '');
temptext2 := rtf2sgml(temptext2);
if temptext2 <> '' then temptext := temptext + temptext2;
application.processmessages;
end;
finally
closefile(tempF);
end;
deletefile(utfilnamn);
temptext := stringreplaceall(temptext, '</MELLIS> ', '</MELLIS>');
temptext := stringreplaceall(temptext, '</P> ', '</P>');
temptext := stringreplaceall(temptext, '</P>' + chr(0), '</P>');
temptext := stringreplaceall(temptext, '</MELLIS></P>', '</MELLIS>');
temptext := stringreplaceall(temptext, '<P></P>', '');
temptext := stringreplaceall(temptext, '</P><P></MELLIS>', '</MELLIS><P>');
temptext := stringreplaceall(temptext, '</MELLIS>', '<#MELLIS><P>');
temptext := stringreplaceall(temptext, '<#MELLIS>', '</MELLIS>');
temptext := stringreplaceall(temptext, '<P><P>', '<P>');
temptext := stringreplaceall(temptext, '<P> ', '<P>');
temptext := stringreplaceall(temptext, '<P>-', '<P>_');
temptext := stringreplaceall(temptext, '<P>_', '<CITAT>_');
while pos('<CITAT>_', temptext) > 0 do
begin
application.processmessages;
temptext2 := hamtastreng(temptext, '<CITAT>_', '</P>');
temptext := stringreplace(temptext, temptext2 + '</P>', temptext2 + '</CITAT>');
temptext := stringreplace(temptext, '<CITAT>_', '<CITAT>-');
end;
writeln(F, '<BRODTEXT>' + temptext + '</BRODTEXT>');
|