浏览代码

* Fix bug #31176: (Try)StrToBool should accept localized floats

git-svn-id: trunk@35331 -
michael 8 年之前
父节点
当前提交
b5fb706a65
共有 2 个文件被更改,包括 23 次插入2 次删除
  1. 20 2
      rtl/objpas/sysutils/sysstr.inc
  2. 3 0
      rtl/objpas/sysutils/sysstrh.inc

+ 20 - 2
rtl/objpas/sysutils/sysstr.inc

@@ -1909,7 +1909,13 @@ end;
 
 function StrToBool(const S: string): Boolean;
 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]);
 end;
 
@@ -1957,7 +1963,19 @@ begin
     Result:=Default;
 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;
+
+begin
+  Result:=TryStrToBool(S,Value,DefaultFormatSettings);
+end;
+
+function TryStrToBool(const S: string; out Value: Boolean; const FormatSettings: TFormatSettings): Boolean;
 Var
   Temp : String;
   I    : Longint;
@@ -1971,7 +1989,7 @@ begin
   Temp:=upcase(S);
   Val(temp,D,code);
   Result:=true;
-  If Code=0 then
+  If (Code=0) or TryStrToFloat(S,D,FormatSettings) then
 {$ifdef FPUNONE}
     Value:=(D<>0)
 {$else}

+ 3 - 0
rtl/objpas/sysutils/sysstrh.inc

@@ -223,10 +223,13 @@ Function FormatCurr(const Format: string; Value: Currency; Const FormatSettings:
 {$endif}
 
 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;const TrueS,FalseS:string): string; inline;
 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; Const FormatSettings: TFormatSettings): Boolean;
 
 function LastDelimiter(const Delimiters, S: string): SizeInt;
 function StringReplace(const S, OldPattern, NewPattern: string;  Flags: TReplaceFlags): string;