mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-08 03:48:07 +02:00
* use TrueBoolStrs/FalseBoolStrs for *StrToBool* (mantis #16848)
git-svn-id: trunk@15764 -
This commit is contained in:
parent
45b11561cf
commit
89be8d45e3
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -10577,6 +10577,7 @@ tests/webtbs/tw16787.pp svneol=native#text/plain
|
||||
tests/webtbs/tw16803.pp svneol=native#text/plain
|
||||
tests/webtbs/tw1681.pp svneol=native#text/plain
|
||||
tests/webtbs/tw16820.pp svneol=native#text/plain
|
||||
tests/webtbs/tw16848.pp svneol=native#text/plain
|
||||
tests/webtbs/tw16861.pp svneol=native#text/plain
|
||||
tests/webtbs/tw16863.pp svneol=native#text/plain
|
||||
tests/webtbs/tw16874.pp svneol=native#text/plain
|
||||
|
@ -1732,9 +1732,7 @@ begin
|
||||
Raise EConvertError.CreateFmt(SInvalidBoolean,[S]);
|
||||
end;
|
||||
|
||||
function BoolToStr(B: Boolean;UseBoolStrs:Boolean=False): string;
|
||||
|
||||
procedure CheckStrs;
|
||||
procedure CheckBoolStrs;
|
||||
begin
|
||||
If Length(TrueBoolStrs)=0 then
|
||||
begin
|
||||
@ -1748,10 +1746,12 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
function BoolToStr(B: Boolean;UseBoolStrs:Boolean=False): string;
|
||||
begin
|
||||
if UseBoolStrs Then
|
||||
begin
|
||||
CheckStrs;
|
||||
CheckBoolStrs;
|
||||
if B then
|
||||
Result:=TrueBoolStrs[0]
|
||||
else
|
||||
@ -1779,6 +1779,7 @@ end;
|
||||
function TryStrToBool(const S: string; out Value: Boolean): Boolean;
|
||||
Var
|
||||
Temp : String;
|
||||
I : Longint;
|
||||
{$ifdef FPUNONE}
|
||||
D : Longint;
|
||||
{$else}
|
||||
@ -1795,12 +1796,23 @@ begin
|
||||
{$else}
|
||||
Value:=(D<>0.0)
|
||||
{$endif}
|
||||
else If Temp='TRUE' then
|
||||
Value:=true
|
||||
else if Temp='FALSE' then
|
||||
Value:=false
|
||||
else
|
||||
Result:=false;
|
||||
begin
|
||||
CheckBoolStrs;
|
||||
for I:=low(TrueBoolStrs) to High(TrueBoolStrs) do
|
||||
if Temp=upcase(TrueBoolStrs[I]) then
|
||||
begin
|
||||
Value:=true;
|
||||
exit;
|
||||
end;
|
||||
for I:=low(FalseBoolStrs) to High(FalseBoolStrs) do
|
||||
if Temp=upcase(FalseBoolStrs[I]) then
|
||||
begin
|
||||
Value:=false;
|
||||
exit;
|
||||
end;
|
||||
Result:=false;
|
||||
end;
|
||||
end;
|
||||
|
||||
{$ifndef FPUNONE}
|
||||
|
51
tests/webtbs/tw16848.pp
Normal file
51
tests/webtbs/tw16848.pp
Normal file
@ -0,0 +1,51 @@
|
||||
{$ifdef fpc}
|
||||
{$mode objfpc}{$H+}
|
||||
{$endif}
|
||||
uses
|
||||
Classes, SysUtils;
|
||||
|
||||
var
|
||||
B: Boolean;
|
||||
S: String;
|
||||
begin
|
||||
WriteLn('BoolToStr(False, True): ' + BoolToStr(False, True));
|
||||
if BoolToStr(False, True)<>'False' then
|
||||
halt(1);
|
||||
WriteLn('BoolToStr(True, True): ' + BoolToStr(True, True));
|
||||
if BoolToStr(True, True)<>'True' then
|
||||
halt(2);
|
||||
|
||||
SetLength(TrueBoolStrs, 1);
|
||||
SetLength(FalseBoolStrs, 1);
|
||||
TrueBoolStrs[0] := 'Sim';
|
||||
FalseBoolStrs[0] := 'Não';
|
||||
|
||||
WriteLn('BoolStrs = Não;Sim');
|
||||
|
||||
WriteLn('BoolToStr(False, True): ' + BoolToStr(False, True));
|
||||
WriteLn('BoolToStr(True, True): ' + BoolToStr(True, True));
|
||||
|
||||
S := BoolToStr(False, True);
|
||||
if S<>'Não' then
|
||||
halt(3);
|
||||
B := StrToBool(S);
|
||||
if b<>false then
|
||||
halt(4);
|
||||
|
||||
WriteLn('StrToBool(' + S +') = ' + BoolToStr(B, True));
|
||||
if BoolToStr(B, True)<>'Não' then
|
||||
halt(5);
|
||||
S := BoolToStr(True, True);
|
||||
if s<>'Sim' then
|
||||
halt(6);
|
||||
B := StrToBool(S);
|
||||
if b<>true then
|
||||
halt(7);
|
||||
WriteLn('StrToBool(' + S +') = ' + BoolToStr(B, True));
|
||||
if BoolToStr(B, True)<>'Sim' then
|
||||
halt(8);
|
||||
|
||||
{ should give exception }
|
||||
if TryStrToBool('True',B) then
|
||||
halt(9);
|
||||
end.
|
Loading…
Reference in New Issue
Block a user