- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
procedure FirstStep (var Text: string);
// Удаление комментариев <!--...-->, переводов строк, раскрытие тегов <br>, удаление парных пробелов:
var
P: Integer;
State: Integer;
Idx: Integer;
Cnt: Integer;
NL: Boolean;
begin
State := 0;
P := 1;
NL := True;
while P <= Length (Text) do
begin
if Text[P] in [#9,#10,#13] then Text[P] := ' ';
case State of
0: case Text[P] of
'<': State := 1;
' ': begin
Idx := P;
State := 9;
end; { }
else NL := False;
end; {case}
1: case Text[P] of
'!': State := 2;
'b': State := 7;
else
begin
Dec (P);
State := 10;
end; {else}
end; {case}
2: if Text[P] <> '-' then
begin
Dec (P);
State := 10;
end else State := 3;
3: if Text[P] = '-' then
begin
Idx := P - 3;
State := 4;
end else
begin
Dec (P);
State := 10;
end; {if}
4: if Text[P] = '-' then State := 5;
5: if Text[P] = '-' then State := 6 else State := 4;
6: if Text[P] = '>' then
begin
Delete (Text, Idx, P - Idx + 1);
P := Idx - 1;
while (P >= 1) and (Text[P] = ' ') do Dec (P);
State := 0;
end else State := 4;
7: if Text[P] = 'r' then State := 8 else State := 0;
8: begin
if Text[P] = '>' then
begin
Text[P-3] := #13;
Text[P-2] := #10;
Delete (Text, P - 1, 2);
Dec (P, 2);
NL := True;
end; {if}
State := 0;
end; {8}
9: if Text[P] <> ' ' then
begin
Cnt := P - Idx;
if NL then
begin
Delete (Text, Idx, Cnt);
Dec (Idx);
end else if Cnt > 1 then Delete (Text, Idx, Cnt - 1);
P := Idx;
State := 0;
end; {if}
10: if Text[P] = '>' then State := 0;
end; {case}
Inc (P);
end; {while}
end; {proc FirstStep}