Advertisement
Janilabo

nl

Dec 10th, 2013
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.89 KB | None | 0 0
  1. function Wee(str: string): string;
  2. var
  3.   h, i: Integer;
  4.   s, r: string;
  5. begin
  6.   if (Length(str) > 1) then
  7.   begin
  8.     s := '0'#0 'a'#7 'b'#8 't'#9 'n'#10 'f'#12 'r'#13 'e'#27;
  9.     h := (Length(s) div 2);
  10.     r := #0'[R%B%S]'#0;
  11.     Result := Replace(str, '\\', r, [rfReplaceAll]);
  12.     for i := 1 to h do
  13.       Result := Replace(Result, ('\' + s[((i * 2) - 1)]), s[(i * 2)], [rfReplaceAll]);
  14.     Result := Replace(Result, r, '\', [rfReplaceAll]);
  15.   end;
  16. end;
  17.  
  18. function Wee2(str: string): string;
  19. var
  20.   b, h, i, l, p, c, q: Integer;
  21.   s, r, t, z: string;
  22. begin
  23.   Result := '';
  24.   if (Length(str) > 1) then
  25.   begin
  26.     s := '0abtnfre'#0#7#8#9#10#12#13#27;
  27.     h := (Length(s) div 2);
  28.     r := #0'[R%B%S]'#0;
  29.     c := 0;
  30.     p := 0;
  31.     b := 1;
  32.     z := Replace(str, '\\', r, [rfReplaceAll]);
  33.     l := (Length(z) - 1);
  34.     repeat
  35.       p := (p + 1);
  36.       if (z[p] = '\') then
  37.       begin
  38.         q := (p + 1);
  39.         for i := 1 to h do
  40.           if (z[q] = s[i]) then
  41.           begin
  42.             if (c > 0) then
  43.               Result := (Result + Copy(z, b, c));
  44.             Result := (Result + s[(i + h)]);
  45.             p := q;
  46.             b := (p + 1);
  47.             c := -1;
  48.             Break;
  49.           end;
  50.       end;
  51.       c := (c + 1);
  52.     until (p >= l);
  53.     Result := (Result + Copy(z, b, (c + 1)));
  54.     Result := Replace(Result, r, '\', [rfReplaceAll]);
  55.   end;
  56. end;
  57.  
  58. var
  59.   t: Integer;
  60.   str, data: string;
  61.  
  62. begin
  63.   ClearDebug;
  64.   data := 'Test \r\n Wtf \\n Wee\r\n';
  65.   for t := 0 to 13 do
  66.     data := (data + data);
  67.   WriteLn(Length(data));
  68.   t := GetSystemTime;
  69.   str := Wee2(data);
  70.   WriteLn('Wee2 - ' + IntToStr(Length(str)) + ': ' + IntToStr(GetSystemTime - t) + ' ms. [' + MD5(str) + ']');
  71.   str := '';
  72.   t := GetSystemTime;
  73.   str := Wee(data);
  74.   WriteLn('Wee - ' + IntToStr(Length(str)) + ': ' + IntToStr(GetSystemTime - t) + ' ms. [' + MD5(str) + ']');
  75. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement