Browse Source

rtl: added overload TryStrToInt64 with int64, TryStrToQWord with QWord, TryStrToUInt64 with UInt64

mattias 4 years ago
parent
commit
45abbd53bf
2 changed files with 23 additions and 5 deletions
  1. 1 0
      packages/rtl/classes.pas
  2. 22 5
      packages/rtl/sysutils.pas

+ 1 - 0
packages/rtl/classes.pas

@@ -692,6 +692,7 @@ type
     function ReadData(var Buffer: NativeLargeInt; Count: NativeInt): NativeInt; overload;
     function ReadData(var Buffer: NativeLargeInt; Count: NativeInt): NativeInt; overload;
     function ReadData(var Buffer: NativeLargeUInt): NativeInt; overload;
     function ReadData(var Buffer: NativeLargeUInt): NativeInt; overload;
     function ReadData(var Buffer: NativeLargeUInt; Count: NativeInt): NativeInt; overload;
     function ReadData(var Buffer: NativeLargeUInt; Count: NativeInt): NativeInt; overload;
+    // Note: a ReadData with Int64 would be Delphi/FPC incompatible
     function ReadData(var Buffer: Double): NativeInt; overload;
     function ReadData(var Buffer: Double): NativeInt; overload;
     function ReadData(var Buffer: Double; Count: NativeInt): NativeInt; overload;
     function ReadData(var Buffer: Double; Count: NativeInt): NativeInt; overload;
     procedure ReadBuffer(var Buffer: TBytes; Count: NativeInt); overload;
     procedure ReadBuffer(var Buffer: TBytes; Count: NativeInt); overload;

+ 22 - 5
packages/rtl/sysutils.pas

@@ -15,7 +15,7 @@ unit SysUtils;
 {$mode objfpc}
 {$mode objfpc}
 {$modeswitch typehelpers}
 {$modeswitch typehelpers}
 {$modeswitch advancedrecords}
 {$modeswitch advancedrecords}
-
+{$WARN 5078 off : }
 interface
 interface
 
 
 uses
 uses
@@ -249,13 +249,16 @@ Function StrToNativeInt(const S : String) : NativeInt;
 // For compatibility
 // For compatibility
 Function StrToInt64(const S : String) : NativeLargeInt;
 Function StrToInt64(const S : String) : NativeLargeInt;
 Function StrToInt64Def(const S : String; ADefault : NativeLargeInt) : NativeLargeInt;
 Function StrToInt64Def(const S : String; ADefault : NativeLargeInt) : NativeLargeInt;
-Function TryStrToInt64(const S : String; Out res : NativeLargeInt) : Boolean;
+Function TryStrToInt64(const S : String; Out res : NativeLargeInt) : Boolean; overload;
+Function TryStrToInt64(const S : String; Out res : Int64) : Boolean; unimplemented; overload; // only 53 bits
 Function StrToQWord(const S : String) : NativeLargeUInt;
 Function StrToQWord(const S : String) : NativeLargeUInt;
 Function StrToQWordDef(const S : String; ADefault : NativeLargeUInt) : NativeLargeUInt;
 Function StrToQWordDef(const S : String; ADefault : NativeLargeUInt) : NativeLargeUInt;
-Function TryStrToQWord(const S : String; Out res : NativeLargeUInt) : Boolean;
+Function TryStrToQWord(const S : String; Out res : NativeLargeUInt) : Boolean; overload;
+Function TryStrToQWord(const S : String; Out res : QWord) : Boolean; unimplemented; overload; // only 52 bits
 Function StrToUInt64(const S : String) : NativeLargeUInt;
 Function StrToUInt64(const S : String) : NativeLargeUInt;
 Function StrToUInt64Def(const S : String; ADefault : NativeLargeUInt) : NativeLargeUInt;
 Function StrToUInt64Def(const S : String; ADefault : NativeLargeUInt) : NativeLargeUInt;
-Function TryStrToUInt64(const S : String; Out res : NativeLargeUInt) : Boolean;
+Function TryStrToUInt64(const S : String; Out res : NativeLargeUInt) : Boolean; overload;
+Function TryStrToUInt64(const S : String; Out res : UInt64) : Boolean; unimplemented; overload; // only 52 bits
 Function StrToDWord(const S : String) : DWord;
 Function StrToDWord(const S : String) : DWord;
 Function StrToDWordDef(const S : String; ADefault : DWord) : DWord;
 Function StrToDWordDef(const S : String; ADefault : DWord) : DWord;
 Function TryStrToDWord(const S : String; Out res : DWord) : Boolean;
 Function TryStrToDWord(const S : String; Out res : DWord) : Boolean;
@@ -4495,6 +4498,11 @@ begin
     Res:=R;
     Res:=R;
 end;
 end;
 
 
+function TryStrToInt64(const S: String; out res: Int64): Boolean;
+begin
+  Result:=TryStrToInt64(S,NativeLargeInt(res));
+end;
+
 function StrToInt64Def(const S: String; ADefault: NativeLargeInt
 function StrToInt64Def(const S: String; ADefault: NativeLargeInt
   ): NativeLargeInt;
   ): NativeLargeInt;
 
 
@@ -4526,6 +4534,11 @@ begin
     Res:=R;
     Res:=R;
 end;
 end;
 
 
+function TryStrToQWord(const S: String; out res: QWord): Boolean;
+begin
+  Result:=TryStrToQWord(S,NativeLargeUInt(res));
+end;
+
 function StrToQWordDef(const S: String; ADefault: NativeLargeUInt
 function StrToQWordDef(const S: String; ADefault: NativeLargeUInt
   ): NativeLargeUInt;
   ): NativeLargeUInt;
 
 
@@ -4534,7 +4547,6 @@ begin
     Result:=ADefault;
     Result:=ADefault;
 end;
 end;
 
 
-
 function StrToUInt64(const S: String): NativeLargeUInt;
 function StrToUInt64(const S: String): NativeLargeUInt;
 
 
 Var
 Var
@@ -4557,6 +4569,11 @@ begin
     Res:=R;
     Res:=R;
 end;
 end;
 
 
+function TryStrToUInt64(const S: String; out res: UInt64): Boolean;
+begin
+  Result:=TryStrToUInt64(S,NativeLargeUInt(res));
+end;
+
 function StrToUInt64Def(const S: String; ADefault: NativeLargeUInt
 function StrToUInt64Def(const S: String; ADefault: NativeLargeUInt
   ): NativeLargeUInt;
   ): NativeLargeUInt;