Janilabo

Untitled

Aug 15th, 2012
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.78 KB | None | 0 0
  1. function StrPosAllTCA(TCA: array of Char; str: string): TIntArray;
  2. var
  3.   h, h2, i, i2, i3, d, o, p, r: Integer;
  4. begin
  5.   h := High(TCA);
  6.   if ((h < 0) or (str = '')) then
  7.     Exit;
  8.   if (h >= 1) then
  9.     for i := (h - d) downto 1 do
  10.       for i2 := (i - 1) downto 0 do
  11.         if (TCA[i] = TCA[i2]) then
  12.         begin
  13.           h2 := High(TCA);
  14.           for i3 := i to (h2 - 1) do
  15.             TCA[i3] := TCA[(i3 + 1)];
  16.           SetLength(TCA, h2);
  17.           Inc(d);
  18.           Break;
  19.         end;
  20.   h := High(TCA);  
  21.   SetLength(Result, Length(str));
  22.   for i := 0 to h do
  23.   begin
  24.     repeat  
  25.       p := PosEx(TCA[i], str, (o + 1));
  26.       if (p > 0) then
  27.       begin
  28.         Result[r] := p;
  29.         o := p;
  30.         Inc(r);
  31.       end;
  32.     until (p <= 0);
  33.     o := 0;
  34.   end;            
  35.   SetLength(Result, r);
  36.   SortTIA(Result);
  37. end;
  38.  
  39. procedure FixText(var text: string);
  40. var
  41.   TIA: TIntArray;
  42.   h, i, o: Integer;
  43. begin
  44.   TIA := StrPosAllTCA(['I', 'l'], text);
  45.   h := High(TIA);
  46.   if (h < 0) then
  47.     Exit;  
  48.   for i := 0 to h do  
  49.   begin          
  50.     if (TIA[i] > 1) then
  51.       o := Ord(text[(TIA[i] - 1)]);  
  52.     case text[TIA[i]] of
  53.       'I': if (TIA[i] > 1) then
  54.              if (InRange(o, 65, 90) or InRange(o, 97, 122) or (o = Ord(' '))) then
  55.                text[TIA[i]] := 'l';
  56.       'l': if (TIA[i] = 1) then
  57.              text[TIA[i]] := 'I'
  58.            else
  59.              if not (InRange(o, 65, 90) or InRange(o, 97, 122)) and (o <> Ord(' ')) then
  60.                text[TIA[i]] := 'I';
  61.     end;
  62.   end;
  63.   SetLength(TIA, 0);
  64. end;
  65.  
  66. var
  67.   str: string;
  68.  
  69. begin
  70.   ClearDebug;
  71.   str := 'lol, JaniIabo is a noooob, Iets test this out.. ShouId we?';
  72.   WriteLn('Before FIX: ' + str);
  73.   FixText(str);      
  74.   WriteLn('After FIX: ' + str);
  75. end.
Advertisement
Add Comment
Please, Sign In to add comment