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.pas25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/base/UCommon.pas b/src/base/UCommon.pas
index fa0faf3c..18022337 100644
--- a/src/base/UCommon.pas
+++ b/src/base/UCommon.pas
@@ -45,6 +45,7 @@ uses
type
TStringDynArray = array of string;
+ TUTF8StringDynArray = array of UTF8String;
const
SepWhitespace = [#9, #10, #13, ' ']; // tab, lf, cr, space
@@ -88,6 +89,8 @@ procedure MergeSort(List: TList; CompareFunc: TListSortCompare);
function GetAlignedMem(Size: cardinal; Alignment: integer): pointer;
procedure FreeAlignedMem(P: pointer);
+function GetArrayIndex(const SearchArray: array of UTF8String; Value: string; CaseInsensitiv: boolean = false): integer;
+
implementation
@@ -514,6 +517,28 @@ begin
TempList.Free;
end;
+(**
+ * Returns the index of Value in SearchArray
+ * or -1 if Value is not in SearchArray.
+ *)
+function GetArrayIndex(const SearchArray: array of UTF8String; Value: string;
+ CaseInsensitiv: boolean = false): integer;
+var
+ i: integer;
+begin
+ Result := -1;
+
+ for i := 0 to High(SearchArray) do
+ begin
+ if (SearchArray[i] = Value) or
+ (CaseInsensitiv and (CompareText(SearchArray[i], Value) = 0)) then
+ begin
+ Result := i;
+ Break;
+ end;
+ end;
+end;
+
type
// stores the unaligned pointer of data allocated by GetAlignedMem()