瀏覽代碼

Tests: delphi compatibility

Herman Schoenfeld 7 年之前
父節點
當前提交
32fd502afd
共有 2 個文件被更改,包括 14 次插入14 次删除
  1. 14 13
      src/libraries/sphere10/UCommon.pas
  2. 0 1
      src/tests/URandomHashTests.Delphi.pas

+ 14 - 13
src/libraries/sphere10/UCommon.pas

@@ -38,10 +38,10 @@ const
 { GLOBAL FUNCTIONS }
 { GLOBAL FUNCTIONS }
 
 
 { Converts a string to hexidecimal format }
 { Converts a string to hexidecimal format }
-function String2Hex(const Buffer: String): String;
-function Hex2Bytes(const AHexString: String): TBytes; overload;
-function TryHex2Bytes(const AHexString: String; out ABytes : TBytes): boolean; overload;
-function Bytes2Hex(const ABytes: TBytes; AUsePrefix : boolean = false) : String;
+function String2Hex(const Buffer: AnsiString): AnsiString;
+function Hex2Bytes(const AHexString: AnsiString): TBytes; overload;
+function TryHex2Bytes(const AHexString: AnsiString; out ABytes : TBytes): boolean; overload;
+function Bytes2Hex(const ABytes: TBytes; AUsePrefix : boolean = false) : AnsiString;
 
 
 { Binary-safe StrComp replacement. StrComp will return 0 for when str1 and str2 both start with NUL character. }
 { Binary-safe StrComp replacement. StrComp will return 0 for when str1 and str2 both start with NUL character. }
 function BinStrComp(const Str1, Str2 : String): Integer;
 function BinStrComp(const Str1, Str2 : String): Integer;
@@ -375,7 +375,7 @@ resourcestring
 
 
 implementation
 implementation
 
 
-uses dateutils;
+uses dateutils, {$IFDEF FPC}StrUtils{$ELSE}System.AnsiStrings{$ENDIF};
 
 
 { CONSTANTS }
 { CONSTANTS }
 const
 const
@@ -405,31 +405,32 @@ var
 
 
 {%region Global functions }
 {%region Global functions }
 
 
-function String2Hex(const Buffer: String): String;
+function String2Hex(const Buffer: AnsiString): AnsiString;
 var
 var
   n: Integer;
   n: Integer;
 begin
 begin
   Result := '';
   Result := '';
   for n := 1 to Length(Buffer) do
   for n := 1 to Length(Buffer) do
-    Result := LowerCase(Result + IntToHex(Ord(Buffer[n]), 2));
+    Result := AnsiLowerCase(Result + IntToHex(Ord(Buffer[n]), 2));
 end;
 end;
 
 
-function Hex2Bytes(const AHexString: String): TBytes;
+function Hex2Bytes(const AHexString: AnsiString): TBytes;
 begin
 begin
   if NOT TryHex2Bytes(AHexString, Result) then
   if NOT TryHex2Bytes(AHexString, Result) then
     raise EArgumentOutOfRangeException.Create('Invalidly formatted hexadecimal string.');
     raise EArgumentOutOfRangeException.Create('Invalidly formatted hexadecimal string.');
 end;
 end;
 
 
-function TryHex2Bytes(const AHexString: String; out ABytes : TBytes): boolean; overload;
+function TryHex2Bytes(const AHexString: AnsiString; out ABytes : TBytes): boolean; overload;
 var
 var
   P : PAnsiChar;
   P : PAnsiChar;
-  LHexString : String;
+  LHexString : AnsiString;
   LHexIndex, LHexLength, LHexStart : Integer;
   LHexIndex, LHexLength, LHexStart : Integer;
 begin
 begin
   SetLength(ABytes, 0);
   SetLength(ABytes, 0);
   LHexLength := System.Length(AHexString);
   LHexLength := System.Length(AHexString);
   LHexStart := 1;
   LHexStart := 1;
-  if AHexString.StartsWith('0x') then begin
+  if AnsiStartsText('0x', AHexString) then begin
+
     // Special case: 0x0 = empty byte array
     // Special case: 0x0 = empty byte array
     if (LHexLength = 3) AND (AHexString[3] = '0') then
     if (LHexLength = 3) AND (AHexString[3] = '0') then
       Exit(true);
       Exit(true);
@@ -450,10 +451,10 @@ begin
   Result := (LHexIndex = (LHexLength DIV 2));
   Result := (LHexIndex = (LHexLength DIV 2));
 end;
 end;
 
 
-function Bytes2Hex(const ABytes: TBytes; AUsePrefix : boolean = false) : String;
+function Bytes2Hex(const ABytes: TBytes; AUsePrefix : boolean = false) : AnsiString;
 var
 var
   i, LStart, LLen : Integer;
   i, LStart, LLen : Integer;
-  s : String;
+  s : AnsiString;
   b : Byte;
   b : Byte;
 begin
 begin
   LLen := System.Length(ABytes)*2;
   LLen := System.Length(ABytes)*2;

+ 0 - 1
src/tests/URandomHashTests.Delphi.pas

@@ -35,7 +35,6 @@ const
     '0x3cc5de8f601ce1ec7adbd765884d6c0f486de4c3a535a36a8658253edb2a80f3'
     '0x3cc5de8f601ce1ec7adbd765884d6c0f486de4c3a535a36a8658253edb2a80f3'
   );
   );
 
 
-
 { TRandomHashTest }
 { TRandomHashTest }
 
 
 procedure TRandomHashTest.TestRandomHash_Standard;
 procedure TRandomHashTest.TestRandomHash_Standard;