const COMMENT_FILTER = '@'; // CHAR, NOT STRING! Set as * if you want to disable this filter. STRING_FILTER = '#'; // CHAR, NOT STRING! Set as * if you want to disable this filter. USE_CLIPBOARD_DATA = False; // Use text from clipboard as the str to filter comments and/or strings from? // Set as true for clipboard, false to use the custom str inside SetupSTR procedure. var str: string; procedure SetupSTR; begin case USE_CLIPBOARD_DATA of False: begin str := 'begin // THIS IS A TEST ;)' + #13#10 + '{' + #13#10 + ' ..MULTILINE COMMENT...' #13#10 + ' IT JUST WORKS! RIGHT?' + #13#10 + '}' + #13#10 + ' WriteLn(''WOOHOOOOO, some text over here?'');' + #13#10 + ' WriteLn(''USERNAME: '' + Players[9999999].Name + '', PASSWORD: '' + Players[-1].Pass + ''); // SC4MZ AL3RT!!111 :D' + #13#10 + ' Wait(1000 + (* PERHAPS A LITTLE COMMENT HERE? *) + Random(1000));' + #13#10 + ' WriteLn(''Lets test comment inside here...'' + {COMMENT TEST!} + ''..seems to work!'')' + #13#10 + 'end.'; end; True: str := GetClipBoard; end; end; {==============================================================================] Explanation: Finds position from s items in str. Stores the ID of the found s item to index variable. The importance order for d items is from left to right (=>). So place the important ones first and then less important after those. Contains field for offset. [==============================================================================} function PosMultiIDEx(s: TStringArray; str: string; var index: Integer; offset: Integer): Integer; var h, i, p, t: Integer; begin Result := -1; index := -1; h := High(s); if ((h > -1) and (str <> '')) then begin t := (Length(str) + 1); Result := t; for i := 0 to h do begin p := PosEx(s[i], str, offset); if ((p > 0) and (p < Result)) then begin Result := p; index := i; end; end; if (Result = t) then Result := 0; end; end; type TRange = record minimum, maximum: Integer; end; TRangeArray = array of TRange; function ToRange(minimum, maximum: Integer): TRange; begin Result.minimum := Integer(minimum); Result.maximum := Integer(maximum); end; procedure TRAAppend(var TRA: TRangeArray; x: TRange); var aL: Integer; begin aL := (Length(TRA) + 1); SetLength(TRA, aL); TRA[(aL - 1)] := TRange(x); end; function TrackCaS(str: string; var comments, strings: TRangeArray): Boolean; var p, s, i, o, e, x, l, a: Integer; t: TStringArray; begin Result := False; SetLength(comments, 0); SetLength(strings, 0); l := Length(str); if (l > 0) then begin o := 1; t := ['//', '(*', '{', '''']; repeat s := PosMultiIDEx(t, str, i, o); if (s > 0) then begin o := (s + 1); a := 0; case i of 0, 1, 2: begin case i of 0: begin e := PosMultiIDEx([#13#10, #13, #10], str, x, o); if (x = 0) then a := 1; TRAAppend(comments, ToRange(s, e)); end; 1, 2: begin case i of 1: begin e := PosEx('*)', str, o); a := 1; end; 2: e := PosEx('}', str, o); end; if (e = 0) then e := l; TRAAppend(comments, ToRange(s, (e + a))); end; end; end; 3: begin e := PosMultiIDEx([#13#10, #13, #10, ''''], str, x, o); if (x = 0) then a := 1; case (e = 0) of True: begin e := l; TRAAppend(strings, ToRange(s, e)); end; False: case x of 0, 1, 2: TRAAppend(strings, ToRange(s, e)); 3: TRAAppend(strings, ToRange(s, (e + a))); end; end; end; end; o := ((e + 1) + a); end; until (s = 0); end; end; {==============================================================================] Explanation: Returns all the positions by items from s array in str. Place s items in importance order (=>) If overlap is set to true, strings can overlap. (['aa'], 'baaaah', False) => [2,3,4] (['aa'], 'baaaah', True) => [2,4] [==============================================================================} function PosAllMulti(s: TStringArray; str: string; overlap: Boolean): TIntegerArray; var h, l, p, o, x, i, t, r, y, d: Integer; begin h := High(s); y := Length(str); if ((y > 0) and (h > -1)) then begin SetLength(Result, y); o := 1; repeat p := 0; for x := 0 to h do begin t := PosEx(s[x], str, (l + o)); case (t < 1) of True: begin for d := x to (h - 1) do s[d] := s[(d + 1)]; SetLength(s, h); Dec(x); Dec(h); end; False: if ((p = 0) or (t < p)) then begin p := t; i := x; end; end; end; if (p > 0) then begin Result[r] := p; Inc(r); l := p; if not overlap then o := Length(s[i]); end; until (p <= 0); end; SetLength(Result, r); end; procedure FillStrRangeEx(var str: string; fillWith: Char; range: TRange; exceptions: TIntegerArray); var i, l, m, c: Integer; begin l := Length(str); if ((l > 0) and not (range.minimum > range.maximum)) then begin if (range.minimum < 1) then range.minimum := 1; if (range.maximum > l) then range.maximum := l; if (range.minimum > l) then Exit; c := iAbs(range.maximum - range.minimum); for i := range.minimum to range.maximum do if not InIntArray(exceptions, i) then str[i] := fillWith; end; end; var ID, position: Integer; ignore: TIntegerArray; a, b: TRangeArray; h, i: Integer; begin ClearDebug; SetupSTR; WriteLn('STR BEFORE: ' + #13#10 + str); TrackCaS(str, a, b); h := High(a); ignore := PosAllMulti([#13, #10], str, False); if (COMMENT_FILTER <> '*') then for i := 0 to h do FillStrRangeEx(str, COMMENT_FILTER, a[i], ignore); WriteLn(''); h := High(b); if (STRING_FILTER <> '*') then for i := 0 to h do FillStrRangeEx(str, STRING_FILTER, b[i], ignore); WriteLn('STR AFTER: ' + #13#10 + str); end.