DEADSOFTWARE

changed license to GPLv3 only; sorry, no trust to FSF anymore
[d2df-editor.git] / src / shared / utils.pas
index 04780bb6eae7a0ee216ab2465c71ec19d6d8b234..10f7f930faa92089fd260571492dc767caf9f40c 100644 (file)
@@ -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