mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-05 10:46:19 +02:00
* Fix bug #31176: (Try)StrToBool should accept localized floats
git-svn-id: trunk@35331 -
This commit is contained in:
parent
27329429d9
commit
b5fb706a65
@ -1909,7 +1909,13 @@ end;
|
|||||||
|
|
||||||
function StrToBool(const S: string): Boolean;
|
function StrToBool(const S: string): Boolean;
|
||||||
begin
|
begin
|
||||||
if not(TryStrToBool(S,Result)) then
|
if not(TryStrToBool(S,Result,DefaultFormatSettings)) then
|
||||||
|
Raise EConvertError.CreateFmt(SInvalidBoolean,[S]);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function StrToBool(const S: string; const FormatSettings: TFormatSettings): Boolean;
|
||||||
|
begin
|
||||||
|
if not(TryStrToBool(S,Result,FormatSettings)) then
|
||||||
Raise EConvertError.CreateFmt(SInvalidBoolean,[S]);
|
Raise EConvertError.CreateFmt(SInvalidBoolean,[S]);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -1957,7 +1963,19 @@ begin
|
|||||||
Result:=Default;
|
Result:=Default;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function StrToBoolDef(const S: string; Default: Boolean; const FormatSettings: TFormatSettings): Boolean;
|
||||||
|
begin
|
||||||
|
if not(TryStrToBool(S,Result,FormatSettings)) then
|
||||||
|
Result:=Default;
|
||||||
|
end;
|
||||||
|
|
||||||
function TryStrToBool(const S: string; out Value: Boolean): Boolean;
|
function TryStrToBool(const S: string; out Value: Boolean): Boolean;
|
||||||
|
|
||||||
|
begin
|
||||||
|
Result:=TryStrToBool(S,Value,DefaultFormatSettings);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TryStrToBool(const S: string; out Value: Boolean; const FormatSettings: TFormatSettings): Boolean;
|
||||||
Var
|
Var
|
||||||
Temp : String;
|
Temp : String;
|
||||||
I : Longint;
|
I : Longint;
|
||||||
@ -1971,7 +1989,7 @@ begin
|
|||||||
Temp:=upcase(S);
|
Temp:=upcase(S);
|
||||||
Val(temp,D,code);
|
Val(temp,D,code);
|
||||||
Result:=true;
|
Result:=true;
|
||||||
If Code=0 then
|
If (Code=0) or TryStrToFloat(S,D,FormatSettings) then
|
||||||
{$ifdef FPUNONE}
|
{$ifdef FPUNONE}
|
||||||
Value:=(D<>0)
|
Value:=(D<>0)
|
||||||
{$else}
|
{$else}
|
||||||
|
@ -223,10 +223,13 @@ Function FormatCurr(const Format: string; Value: Currency; Const FormatSettings:
|
|||||||
{$endif}
|
{$endif}
|
||||||
|
|
||||||
function StrToBool(const S: string): Boolean;
|
function StrToBool(const S: string): Boolean;
|
||||||
|
function StrToBool(const S: string; Const FormatSettings: TFormatSettings): Boolean;
|
||||||
function BoolToStr(B: Boolean;UseBoolStrs:Boolean=False): string;
|
function BoolToStr(B: Boolean;UseBoolStrs:Boolean=False): string;
|
||||||
function BoolToStr(B: Boolean;const TrueS,FalseS:string): string; inline;
|
function BoolToStr(B: Boolean;const TrueS,FalseS:string): string; inline;
|
||||||
function StrToBoolDef(const S: string; Default: Boolean): Boolean;
|
function StrToBoolDef(const S: string; Default: Boolean): Boolean;
|
||||||
|
function StrToBoolDef(const S: string; Default: Boolean; Const FormatSettings: TFormatSettings): Boolean;
|
||||||
function TryStrToBool(const S: string; out Value: Boolean): Boolean;
|
function TryStrToBool(const S: string; out Value: Boolean): Boolean;
|
||||||
|
function TryStrToBool(const S: string; out Value: Boolean; Const FormatSettings: TFormatSettings): Boolean;
|
||||||
|
|
||||||
function LastDelimiter(const Delimiters, S: string): SizeInt;
|
function LastDelimiter(const Delimiters, S: string): SizeInt;
|
||||||
function StringReplace(const S, OldPattern, NewPattern: string; Flags: TReplaceFlags): string;
|
function StringReplace(const S, OldPattern, NewPattern: string; Flags: TReplaceFlags): string;
|
||||||
|
Loading…
Reference in New Issue
Block a user