|
@@ -42,10 +42,13 @@ const
|
|
|
|
|
|
{ GLOBAL HELPER FUNCTIONS }
|
|
|
|
|
|
+
|
|
|
function String2Hex(const Buffer: String): String;
|
|
|
-//function Hex2Bytes(const AHexString: String): TBytes; overload;
|
|
|
-//function TryHex2Bytes(const AHexString: String; out ABytes : TBytes): boolean; overload;
|
|
|
+function Hex2Bytes(const AHexString: String): TBytes; overload;
|
|
|
+{$IFDEF UNITTESTS}
|
|
|
+function TryHex2Bytes(const AHexString: String; out ABytes : TBytes): boolean; overload;
|
|
|
function Bytes2Hex(const ABytes: TBytes; AUsePrefix : boolean = false) : String;
|
|
|
+{$ENDIF}
|
|
|
function BinStrComp(const Str1, Str2 : String): Integer; // Binary-safe StrComp replacement. StrComp will return 0 for when str1 and str2 both start with NUL character.
|
|
|
function BytesCompare(const ABytes1, ABytes2: TBytes): integer;
|
|
|
function BytesEqual(const ABytes1, ABytes2 : TBytes) : boolean; inline;
|
|
@@ -442,13 +445,14 @@ begin
|
|
|
Result := AnsiLowerCase(Result + IntToHex(Ord(Buffer[n]), 2));
|
|
|
end;
|
|
|
|
|
|
-{function Hex2Bytes(const AHexString: String): TBytes;
|
|
|
+{$IFDEF UNITTESTS}
|
|
|
+function Hex2Bytes(const AHexString: String): TBytes;
|
|
|
begin
|
|
|
if NOT TryHex2Bytes(AHexString, Result) then
|
|
|
raise EArgumentOutOfRangeException.Create('Invalidly formatted hexadecimal string.');
|
|
|
end;
|
|
|
-}
|
|
|
-{function TryHex2Bytes(const AHexString: String; out ABytes : TBytes): boolean; overload;
|
|
|
+
|
|
|
+function TryHex2Bytes(const AHexString: String; out ABytes : TBytes): boolean; overload;
|
|
|
var
|
|
|
P : PAnsiChar;
|
|
|
LHexString : String;
|
|
@@ -457,7 +461,7 @@ begin
|
|
|
SetLength(ABytes, 0);
|
|
|
LHexLength := System.Length(AHexString);
|
|
|
LHexStart := 1;
|
|
|
- if {$IFDEF FPCAnsiStartsText{$ELSEStartsText{$ENDIF('0x', AHexString) then begin
|
|
|
+ if {$IFDEF FPC}AnsiStartsText{$ELSE}StartsText{$ENDIF}('0x', AHexString) then begin
|
|
|
|
|
|
// Special case: 0x0 = empty byte array
|
|
|
if (LHexLength = 3) AND (AHexString[3] = '0') then
|
|
@@ -477,7 +481,8 @@ begin
|
|
|
LHexString := LowerCase(AHexString);
|
|
|
LHexIndex := HexToBin(PAnsiChar(@LHexString[LHexStart]), P, System.Length(ABytes));
|
|
|
Result := (LHexIndex = (LHexLength DIV 2));
|
|
|
-end;}
|
|
|
+end;
|
|
|
+{$ENDIF}
|
|
|
|
|
|
function Bytes2Hex(const ABytes: TBytes; AUsePrefix : boolean = false) : String;
|
|
|
var
|