X-Git-Url: https://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fshared%2Futils.pas;h=10f7f930faa92089fd260571492dc767caf9f40c;hb=6e52b3dc2eb459c745e571dfef5afb5c2ccd546f;hp=04780bb6eae7a0ee216ab2465c71ec19d6d8b234;hpb=3dc2fe6b3d29cd54425db8f590e922f2dce50e99;p=d2df-editor.git diff --git a/src/shared/utils.pas b/src/shared/utils.pas index 04780bb..10f7f93 100644 --- a/src/shared/utils.pas +++ b/src/shared/utils.pas @@ -2,8 +2,7 @@ * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * the Free Software Foundation, version 3 of the License ONLY. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -64,8 +63,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 +452,7 @@ begin end; -function UpCase1251 (ch: Char): Char; +function UpCase1251 (ch: AnsiChar): AnsiChar; inline; begin if ch < #128 then begin @@ -475,7 +476,7 @@ begin end; -function LoCase1251 (ch: Char): Char; +function LoCase1251 (ch: AnsiChar): AnsiChar; inline; begin if ch < #128 then begin @@ -510,6 +511,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