Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function GetCodeWithoutCommentsAndLiterals(const text: String): String;
- var
- inKind: (ikComment, ikLiteral, ikPassage, ikNone);
- i: Integer;
- begin
- Result := text;
- inKind := ikNone;
- for i := Low(Result) to High(Result) do
- case inKind of
- ikComment: begin
- if Result[i] in [#13, #10] then
- inKind := ikNone;
- Result[i] := ' ';
- end;
- ikLiteral: begin
- if Result[i] in ['''', #13, #10] then
- inKind := ikNone;
- Result[i] := ' ';
- end;
- ikPassage: begin
- if
- (i < High(Result)) and
- (Result[i] = '$') and
- (Result[i + 1] = ']')
- then begin
- inKind := ikNone;
- Result[i + 1] := ' ';
- end;
- Result[i] := ' ';
- end;
- ikNone: begin
- if i < Low(text) then
- if (Result[i] = '/') and (Result[i + 1] = '/') then begin
- inKind := ikComment;
- Result[i + 1] := ' ';
- end else if (Result[i] = '[') and (Result[i + 1] = '$') then begin
- inKind := ikPassage;
- Result[i + 1] := ' ';
- end
- else if Result[i] = '''' then
- inKind := ikLiteral
- else
- inKind := ikNone;
- if inKind <> ikNone then
- Result[i] := ' ';
- end
- else
- Assert(false);
- end;
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement