From f232b1e693edf980b15da896079eaa26bab5ef9d Mon Sep 17 00:00:00 2001 From: Stas'M Date: Wed, 23 May 2018 17:36:03 +0300 Subject: [PATCH] Shared: Import toLowerCase1251 function and use it http://doom2d.org/forum/viewtopic.php?f=36&t=2566 --- src/shared/WADEDITOR.pas | 8 ++++---- src/shared/utils.pas | 30 ++++++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/shared/WADEDITOR.pas b/src/shared/WADEDITOR.pas index d218355..5e0573e 100644 --- a/src/shared/WADEDITOR.pas +++ b/src/shared/WADEDITOR.pas @@ -585,19 +585,19 @@ begin Exit; end; - Section := UpperCase(Section); - Resource := UpperCase(Resource); + Section := toLowerCase1251(Section); + Resource := toLowerCase1251(Resource); i := -1; for a := 0 to High(FResTable) do begin if FResTable[a].Length = 0 then begin - CurrentSection := FResTable[a].ResourceName; + CurrentSection := toLowerCase1251(FResTable[a].ResourceName); Continue; end; - if (FResTable[a].ResourceName = Resource) and + if (toLowerCase1251(FResTable[a].ResourceName) = Resource) and (CurrentSection = Section) then begin i := a; diff --git a/src/shared/utils.pas b/src/shared/utils.pas index 04780bb..14e6f76 100644 --- a/src/shared/utils.pas +++ b/src/shared/utils.pas @@ -64,8 +64,10 @@ function addWadExtension (fn: AnsiString): AnsiString; // convert number to strig with nice commas function Int64ToStrComma (i: Int64): AnsiString; -function UpCase1251 (ch: Char): Char; -function LoCase1251 (ch: Char): Char; +function UpCase1251 (ch: AnsiChar): AnsiChar; inline; +function LoCase1251 (ch: AnsiChar): AnsiChar; inline; + +function toLowerCase1251 (const s: AnsiString): AnsiString; // `true` if strings are equal; ignoring case for cp1251 function StrEquCI1251 (const s0, s1: AnsiString): Boolean; @@ -451,7 +453,7 @@ begin end; -function UpCase1251 (ch: Char): Char; +function UpCase1251 (ch: AnsiChar): AnsiChar; inline; begin if ch < #128 then begin @@ -475,7 +477,7 @@ begin end; -function LoCase1251 (ch: Char): Char; +function LoCase1251 (ch: AnsiChar): AnsiChar; inline; begin if ch < #128 then begin @@ -510,6 +512,26 @@ begin end; +function toLowerCase1251 (const s: AnsiString): AnsiString; +var + f: Integer; + ch: AnsiChar; +begin + for ch in s do + begin + if (ch <> LoCase1251(ch)) then + begin + result := ''; + SetLength(result, Length(s)); + for f := 1 to Length(s) do result[f] := LoCase1251(s[f]); + exit; + end; + end; + // nothing to do + result := s; +end; + + // ////////////////////////////////////////////////////////////////////////// // // utils // `ch`: utf8 start -- 2.29.2