aboutsummaryrefslogtreecommitdiffstats
path: root/src/base/UCommon.pas
diff options
context:
space:
mode:
Diffstat (limited to 'src/base/UCommon.pas')
-rw-r--r--src/base/UCommon.pas62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/base/UCommon.pas b/src/base/UCommon.pas
index 18022337..25b30ed1 100644
--- a/src/base/UCommon.pas
+++ b/src/base/UCommon.pas
@@ -62,6 +62,23 @@ const
*}
function SplitString(const Str: string; MaxCount: integer = 0; Separators: TSysCharSet = SepWhitespace): TStringDynArray;
+function StringInArray(const Value: string; Strings: array of string): boolean;
+
+function GetStringWithNoAccents(str: UTF8String): UTF8String;
+
+type
+ TRGB = record
+ R: single;
+ G: single;
+ B: single;
+ end;
+
+ TRGBA = record
+ R, G, B, A: double;
+ end;
+
+function RGBToHex(R, G, B: integer):string;
+function HexToRGB(Hex: string): TRGB;
type
TMessageType = (mtInfo, mtError);
@@ -104,6 +121,16 @@ uses
UMain,
UUnicodeUtils;
+function StringInArray(const Value: string; Strings: array of string): boolean;
+var
+ i: integer;
+begin
+ Result := true;
+ for i := Low(Strings) to High(Strings) do
+ if Strings[i] = Value then exit;
+ Result := false;
+end;
+
function SplitString(const Str: string; MaxCount: integer; Separators: TSysCharSet): TStringDynArray;
{*
@@ -157,6 +184,41 @@ begin
AddSplit(Start, Length(Str)+1);
end;
+const
+ Accents: array [0..37] of UTF8String = ('ç', 'á', 'é', 'í', 'ó', 'ú', 'ý', 'à', 'è', 'ì', 'ò', 'ù', 'ã', 'õ', 'ñ', 'ä', 'ë', 'ï', 'ö', 'ü', 'ÿ', 'â', 'ê', 'î', 'ô', 'û', '!', '¡', '"', '&', '(', ')', '?', '¿', ',', '.', ':', ';');
+ NoAccents: array [0..37] of UTF8String = ('c', 'a', 'e', 'i', 'o', 'u', 'y', 'a', 'e', 'i', 'o', 'u', 'a', 'o', 'n', 'a', 'e', 'i', 'o', 'u', 'y', 'a', 'e', 'i', 'o', 'u', '', '', '', '', '', '', '', '', '', '', '', '');
+
+function GetStringWithNoAccents(str: UTF8String): UTF8String;
+var
+ i: integer;
+ tmp: string;
+begin
+ tmp := Utf8ToAnsi(str);
+
+ for i := 0 to High(Accents) do
+ begin
+ str := StringReplace(str, Accents[i], NoAccents[i], [rfReplaceAll, rfIgnoreCase]);
+ end;
+
+ Result := str;
+end;
+
+function RGBToHex(R, G, B: integer): string;
+begin
+ Result := IntToHex(R, 2) + IntToHex(G, 2) + IntToHex(B, 2);
+end;
+
+function HexToRGB(Hex: string): TRGB;
+var
+ Col: TRGB;
+begin
+ Col.R := StrToInt('$'+Copy(Hex, 1, 2));
+ Col.G := StrToInt('$'+Copy(Hex, 3, 2));
+ Col.B := StrToInt('$'+Copy(Hex, 5, 2));
+
+ Result := Col;
+end;
+
// data used by the ...Locale() functions
{$IF Defined(Linux) or Defined(FreeBSD)}