|
@@ -7,7 +7,8 @@
|
|
historical operations.
|
|
historical operations.
|
|
|
|
|
|
CREDITS:
|
|
CREDITS:
|
|
- [2017-06-29] Herman Schoenfeld ([email protected]): Created unit, added IFF methods
|
|
|
|
|
|
+ [2017-06-29] Herman Schoenfeld ([email protected]): Created unit, added IFF functions
|
|
|
|
+ [2017-08-10] Herman Schoenfeld ([email protected]): Added String2Hex, BinStrComp functions
|
|
}
|
|
}
|
|
|
|
|
|
unit UCommon;
|
|
unit UCommon;
|
|
@@ -18,6 +19,12 @@ unit UCommon;
|
|
|
|
|
|
interface
|
|
interface
|
|
|
|
|
|
|
|
+{ Converts a string to hexidecimal format }
|
|
|
|
+function String2Hex(const Buffer: AnsiString): AnsiString;
|
|
|
|
+
|
|
|
|
+{ Binary-safe StrComp replacement. StrComp will return 0 for when str1 and str2 both start with NUL character. }
|
|
|
|
+function BinStrComp(const Str1, Str2 : AnsiString): Integer;
|
|
|
|
+
|
|
{ Language-level tools }
|
|
{ Language-level tools }
|
|
function IIF(const ACondition: Boolean; const ATrueResult, AFalseResult: Cardinal): Cardinal; overload;
|
|
function IIF(const ACondition: Boolean; const ATrueResult, AFalseResult: Cardinal): Cardinal; overload;
|
|
function IIF(const ACondition: Boolean; const ATrueResult, AFalseResult: Integer): Integer; overload;
|
|
function IIF(const ACondition: Boolean; const ATrueResult, AFalseResult: Integer): Integer; overload;
|
|
@@ -30,7 +37,40 @@ function IIF(const ACondition: Boolean; const ATrueResult, AFalseResult: variant
|
|
implementation
|
|
implementation
|
|
|
|
|
|
uses
|
|
uses
|
|
- Classes, SysUtils;
|
|
|
|
|
|
+ Classes, SysUtils, Math;
|
|
|
|
+
|
|
|
|
+function String2Hex(const Buffer: AnsiString): AnsiString;
|
|
|
|
+var
|
|
|
|
+ n: Integer;
|
|
|
|
+begin
|
|
|
|
+ Result := '';
|
|
|
|
+ for n := 1 to Length(Buffer) do
|
|
|
|
+ Result := LowerCase(Result + IntToHex(Ord(Buffer[n]), 2));
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+function BinStrComp(const Str1, Str2: AnsiString): integer;
|
|
|
|
+var Str1Len, Str2Len, i : Integer;
|
|
|
|
+begin
|
|
|
|
+ Str1Len := Length(Str1);
|
|
|
|
+ Str2Len := Length(Str2);
|
|
|
|
+ if (Str1Len < Str2Len) then
|
|
|
|
+ Result := -1
|
|
|
|
+ else if (Str1Len > Str2Len) then
|
|
|
|
+ Result := 1
|
|
|
|
+ else begin
|
|
|
|
+ Result := 0;
|
|
|
|
+ For i:= 1 to Str1Len do begin
|
|
|
|
+ if Str1[i] < Str2[i] then begin
|
|
|
|
+ Result := -1;
|
|
|
|
+ break;
|
|
|
|
+ end else if Str1[i] > Str2[i] then begin
|
|
|
|
+ Result := 1;
|
|
|
|
+ break;
|
|
|
|
+ end
|
|
|
|
+ end;
|
|
|
|
+ end;
|
|
|
|
+End;
|
|
|
|
|
|
{%region Language-level tools }
|
|
{%region Language-level tools }
|
|
function IIF(const ACondition: Boolean; const ATrueResult, AFalseResult: Cardinal): Cardinal;
|
|
function IIF(const ACondition: Boolean; const ATrueResult, AFalseResult: Cardinal): Cardinal;
|