Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Wee(str: string): string;
- var
- h, i: Integer;
- s, r: string;
- begin
- if (Length(str) > 1) then
- begin
- s := '0'#0 'a'#7 'b'#8 't'#9 'n'#10 'f'#12 'r'#13 'e'#27;
- h := (Length(s) div 2);
- r := #0'[R%B%S]'#0;
- Result := Replace(str, '\\', r, [rfReplaceAll]);
- for i := 1 to h do
- Result := Replace(Result, ('\' + s[((i * 2) - 1)]), s[(i * 2)], [rfReplaceAll]);
- Result := Replace(Result, r, '\', [rfReplaceAll]);
- end;
- end;
- function Wee2(str: string): string;
- var
- b, h, i, l, p, c, q: Integer;
- s, r, t, z: string;
- begin
- Result := '';
- if (Length(str) > 1) then
- begin
- s := '0abtnfre'#0#7#8#9#10#12#13#27;
- h := (Length(s) div 2);
- r := #0'[R%B%S]'#0;
- c := 0;
- p := 0;
- b := 1;
- z := Replace(str, '\\', r, [rfReplaceAll]);
- l := (Length(z) - 1);
- repeat
- p := (p + 1);
- if (z[p] = '\') then
- begin
- q := (p + 1);
- for i := 1 to h do
- if (z[q] = s[i]) then
- begin
- if (c > 0) then
- Result := (Result + Copy(z, b, c));
- Result := (Result + s[(i + h)]);
- p := q;
- b := (p + 1);
- c := -1;
- Break;
- end;
- end;
- c := (c + 1);
- until (p >= l);
- Result := (Result + Copy(z, b, (c + 1)));
- Result := Replace(Result, r, '\', [rfReplaceAll]);
- end;
- end;
- function Wee3(Str: string): String;
- var
- hi,i,j,k,hipat: Integer;
- ptrn, repl: TCharArray;
- prev,next: Char;
- DidRep: Boolean;
- begin
- Result := '';
- if (Length(str) > 1) then
- begin
- ptrn := ['0','a','b','t','n','f','r','e'];
- repl := [#0, #7, #8, #9, #10,#12,#13,#27];
- hipat := High(ptrn);
- Hi := Length(Str);
- SetLength(Result, (Hi+1));
- prev := ' ';
- k := 1;
- i := 1;
- repeat
- DidRep := False;
- if (Str[i] = '\') then
- if (Prev = '\') then
- Inc(i)
- else begin
- next := Str[i+1];
- for j := 0 to HiPat do
- if (next = ptrn[j]) then
- begin
- Result[k] := repl[j];
- Inc(k);
- DidRep := True;
- i := i+2;
- break;
- end;
- if DidRep then Continue;
- end;
- Result[k] := Str[i];
- prev := Str[i];
- Inc(k);
- Inc(i);
- until (i > Hi);
- SetLength(Result, k-1);
- end else
- Result := Str[1];
- end;
- var
- t: Integer;
- str, data: string;
- begin
- data := 'Test \r\n Wtf \\n Wee\r\n';
- for t := 0 to 13 do
- data := (data + data);
- WriteLn(Length(data));
- t := GetSystemTime;
- str := Wee2(data);
- WriteLn('Wee2 - ' + IntToStr(Length(str)) + ': ' + IntToStr(GetSystemTime - t) + ' ms. [' + MD5(str) + ']');
- str := '';
- t := GetSystemTime;
- str := Wee(data);
- WriteLn('Wee - ' + IntToStr(Length(str)) + ': ' + IntToStr(GetSystemTime - t) + ' ms. [' + MD5(str) + ']');
- t := GetSystemTime;
- str := Wee3(data);
- WriteLn('Wee3 - ' + IntToStr(Length(str)) + ': ' + IntToStr(GetSystemTime - t) + ' ms. [' + MD5(str) + ']');
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement