Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Credits to Dgby714
- 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 else
- Result := str;
- 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 else
- Result := str;
- end;
- // Credits to slacky
- function Wee3(str: string): String;
- var
- hi,i,j,k,hipat: Integer;
- ptrn, repl: TCharArray;
- prev,next: Char;
- DidRep: Boolean;
- begin
- if (Length(str) > 1) then
- begin
- Result := '';
- 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 not (Prev = '\') then
- 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 else
- Inc(i);
- Result[k] := Str[i];
- prev := Str[i];
- Inc(k);
- Inc(i);
- until (i > Hi);
- SetLength(Result, (k - 1));
- end else
- Result := Str;
- end;
- // Credits to slacky
- function Wee4(str: string): string;
- var
- l, i, j, k, g: Integer;
- s, c: string;
- p, n: Char;
- d: Boolean;
- begin
- l := Length(str);
- if (l > 1) then
- begin
- s := '0abtnfre';
- c := #0#7#8#9#10#12#13#27;
- g := Length(s);
- SetLength(Result, (l + 1));
- p := #32;
- k := 1;
- i := 1;
- repeat
- if (str[i] = '\') then
- if not (p = '\') then
- begin
- n := str[(i + 1)];
- for j := 1 to g do
- begin
- d := (n = s[j]);
- if d then
- begin
- Result[k] := c[j];
- k := (k + 1);
- i := (i + 2);
- Break;
- end;
- end;
- if d then
- Continue;
- end else
- i := (i + 1);
- Result[k] := str[i];
- p := str[i];
- k := (k + 1);
- i := (i + 1);
- until (i > l);
- SetLength(Result, (k - 1));
- end else
- Result := str;
- end;
- var
- t: Integer;
- str, data: string;
- begin
- ClearDebug;
- data := 'Test \r\n Wtf \\n Wee\r\n';
- for t := 0 to 13 do
- data := (data + data);
- WriteLn(Length(data));
- t := GetSystemTime;
- str := Wee3(data);
- WriteLn('Wee3 - ' + IntToStr(Length(str)) + ': ' + IntToStr(GetSystemTime - t) + ' ms. [' + MD5(str) + ']');
- str := '';
- t := GetSystemTime;
- str := Wee4(data);
- WriteLn('Wee4 - ' + IntToStr(Length(str)) + ': ' + IntToStr(GetSystemTime - t) + ' ms. [' + MD5(str) + ']');
- str := '';
- 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) + ']');
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement