Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type
- RSC_TTextMethod = (tm_PlayerName, tm_PlayerText, tm_GameName, tm_GameText);
- procedure RSC_FixText(var text: string; method: RSC_TTextMethod);
- var
- r: TRegexMatchArray;
- begin
- case method of
- tm_PlayerName:
- while PregMatchEx('/[a-zA-Z0-9]I/', text, r) do
- begin
- text[(r[0].Offset + 1)] := 'l';
- SetLength(r, 0);
- end;
- tm_PlayerText:
- begin
- while PregMatchEx('/[a-z]I/', text, r) do
- begin
- text[(r[0].Offset + 1)] := 'l';
- SetLength(r, 0);
- end;
- while PregMatchEx('/[A-Za-z][A-Z]/', text, r) do
- begin
- text[(r[0].Offset + 1)] := Chr(Ord(text[(r[0].Offset + 1)]) + 32);
- SetLength(r, 0);
- end;
- while PregMatchEx('/[:!?.]\s*[a-z]/', text, r) do
- begin
- text := Replace(text, r[0].MatchedText, Uppercase(r[0].MatchedText));
- SetLength(r, 0);
- end;
- if PregMatchEx('/\A[a-z]/', text, r) then
- text[1] := Chr(Ord(text[1]) - 32);
- end;
- tm_GameName:
- begin
- if PregMatchEx('/\A[a-z]/', text, r) then
- text[1] := Chr(Ord(text[1]) - 32);
- SetLength(r, 0);
- while PregMatchEx('/[a-z]I/', text, r) do
- begin
- text[(r[0].Offset + 1)] := 'l';
- SetLength(r, 0);
- end;
- text := Lowercase(text);
- text := Capitalize(text);
- while PregMatchEx('/( Of | The | Le )/', text, r) do
- begin
- text := Replace(text, r[0].MatchedText, Lowercase(r[0].MatchedText));
- SetLength(r, 0);
- end;
- end;
- tm_GameText:
- begin
- while PregMatchEx('/[a-z]I/', text, r) do
- begin
- text := Replace(text, r[0].MatchedText, Replace(r[0].MatchedText, 'I', 'l'));
- SetLength(r, 0);
- end;
- text := Lowercase(text);
- while PregMatchEx('/[:!?.]\s*[a-z]/', text, r) do
- begin
- text := Replace(text, r[0].MatchedText, Uppercase(r[0].MatchedText));
- SetLength(r, 0);
- end;
- if PregMatchEx('/\A[a-z]/', text, r) then
- text[1] := Chr(Ord(text[1]) - 32);
- SetLength(r, 0);
- end;
- end;
- end;
- var
- str: string;
- begin
- ClearDebug;
- str := 'lol, let''s see how FixText() works. should we? it definitely wiII work. RIGHT?!';
- WriteLn('Before FIX: ' + str);
- RSC_FixText(str, tm_PlayerText);
- WriteLn('After FIX: ' + str);
- end.
Advertisement
Add Comment
Please, Sign In to add comment