Advertisement
Guest User

ForMaxim

a guest
Mar 31st, 2020
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. function GetCodeWithoutCommentsAndLiterals(const text: String): String;
  2. var
  3. inKind: (ikComment, ikLiteral, ikPassage, ikNone);
  4. i: Integer;
  5. begin
  6. Result := text;
  7.  
  8. inKind := ikNone;
  9.  
  10. for i := Low(Result) to High(Result) do
  11. case inKind of
  12. ikComment: begin
  13. if Result[i] in [#13, #10] then
  14. inKind := ikNone;
  15. Result[i] := ' ';
  16. end;
  17. ikLiteral: begin
  18. if Result[i] in ['''', #13, #10] then
  19. inKind := ikNone;
  20. Result[i] := ' ';
  21. end;
  22. ikPassage: begin
  23. if
  24. (i < High(Result)) and
  25. (Result[i] = '$') and
  26. (Result[i + 1] = ']')
  27. then begin
  28. inKind := ikNone;
  29. Result[i + 1] := ' ';
  30. end;
  31. Result[i] := ' ';
  32. end;
  33. ikNone: begin
  34. if i < Low(text) then
  35. if (Result[i] = '/') and (Result[i + 1] = '/') then begin
  36. inKind := ikComment;
  37. Result[i + 1] := ' ';
  38. end else if (Result[i] = '[') and (Result[i + 1] = '$') then begin
  39. inKind := ikPassage;
  40. Result[i + 1] := ' ';
  41. end
  42. else if Result[i] = '''' then
  43. inKind := ikLiteral
  44. else
  45. inKind := ikNone;
  46.  
  47. if inKind <> ikNone then
  48. Result[i] := ' ';
  49. end
  50. else
  51. Assert(false);
  52. end;
  53. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement