Janilabo

Untitled

Aug 25th, 2012
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 2.50 KB | None | 0 0
  1. type
  2.   RSC_TTextMethod = (tm_PlayerName, tm_PlayerText, tm_GameName, tm_GameText);
  3.  
  4. procedure RSC_FixText(var text: string; method: RSC_TTextMethod);
  5. var    
  6.   r: TRegexMatchArray;
  7. begin
  8.   case method of
  9.     tm_PlayerName:
  10.     while PregMatchEx('/[a-zA-Z0-9]I/', text, r) do
  11.     begin    
  12.       text[(r[0].Offset + 1)] := 'l';
  13.       SetLength(r, 0);
  14.     end;
  15.     tm_PlayerText:
  16.     begin
  17.       while PregMatchEx('/[a-z]I/', text, r) do
  18.       begin              
  19.         text[(r[0].Offset + 1)] := 'l';
  20.         SetLength(r, 0);
  21.       end;      
  22.       while PregMatchEx('/[A-Za-z][A-Z]/', text, r) do
  23.       begin
  24.         text[(r[0].Offset + 1)] := Chr(Ord(text[(r[0].Offset + 1)]) + 32);
  25.         SetLength(r, 0);  
  26.       end;
  27.       while PregMatchEx('/[:!?.]\s*[a-z]/', text, r) do
  28.       begin
  29.         text := Replace(text, r[0].MatchedText, Uppercase(r[0].MatchedText));
  30.         SetLength(r, 0);
  31.       end;
  32.       if PregMatchEx('/\A[a-z]/', text, r) then
  33.         text[1] := Chr(Ord(text[1]) - 32);    
  34.     end;  
  35.     tm_GameName:
  36.     begin
  37.       if PregMatchEx('/\A[a-z]/', text, r) then
  38.         text[1] := Chr(Ord(text[1]) - 32);    
  39.       SetLength(r, 0);
  40.       while PregMatchEx('/[a-z]I/', text, r) do
  41.       begin              
  42.         text[(r[0].Offset + 1)] := 'l';
  43.         SetLength(r, 0);
  44.       end;            
  45.       text := Lowercase(text);
  46.       text := Capitalize(text);
  47.       while PregMatchEx('/( Of | The | Le )/', text, r) do
  48.       begin
  49.         text := Replace(text, r[0].MatchedText, Lowercase(r[0].MatchedText));
  50.         SetLength(r, 0);
  51.       end;
  52.     end;
  53.     tm_GameText:
  54.     begin
  55.       while PregMatchEx('/[a-z]I/', text, r) do
  56.       begin
  57.         text := Replace(text, r[0].MatchedText, Replace(r[0].MatchedText, 'I', 'l'));
  58.         SetLength(r, 0);  
  59.       end;    
  60.       text := Lowercase(text);
  61.       while PregMatchEx('/[:!?.]\s*[a-z]/', text, r) do
  62.       begin                                                      
  63.         text := Replace(text, r[0].MatchedText, Uppercase(r[0].MatchedText));
  64.         SetLength(r, 0);
  65.       end;    
  66.       if PregMatchEx('/\A[a-z]/', text, r) then
  67.         text[1] := Chr(Ord(text[1]) - 32);
  68.       SetLength(r, 0);
  69.     end;                                  
  70.   end;
  71. end;
  72.  
  73. var
  74.   str: string;
  75.  
  76. begin
  77.   ClearDebug;
  78.   str := 'lol, let''s see how FixText() works. should we? it definitely wiII work. RIGHT?!';
  79.   WriteLn('Before FIX: ' + str);
  80.   RSC_FixText(str, tm_PlayerText);      
  81.   WriteLn('After FIX: ' + str);
  82. end.
Advertisement
Add Comment
Please, Sign In to add comment