mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-05-29 03:23:47 +02:00
parent
705033284e
commit
215b870f5e
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -6244,6 +6244,7 @@ tests/test/units/sysutils/execansi.pp svneol=native#text/plain
|
|||||||
tests/test/units/sysutils/execedbya.pp svneol=native#text/plain
|
tests/test/units/sysutils/execedbya.pp svneol=native#text/plain
|
||||||
tests/test/units/sysutils/extractquote.pp svneol=native#text/plain
|
tests/test/units/sysutils/extractquote.pp svneol=native#text/plain
|
||||||
tests/test/units/sysutils/tsscanf.pp svneol=native#text/plain
|
tests/test/units/sysutils/tsscanf.pp svneol=native#text/plain
|
||||||
|
tests/test/units/sysutils/tstrtobool.pp svneol=native#text/plain
|
||||||
tests/test/uprocext1.pp svneol=native#text/plain
|
tests/test/uprocext1.pp svneol=native#text/plain
|
||||||
tests/test/uprocext2.pp svneol=native#text/plain
|
tests/test/uprocext2.pp svneol=native#text/plain
|
||||||
tests/test/utasout.pp svneol=native#text/plain
|
tests/test/utasout.pp svneol=native#text/plain
|
||||||
|
@ -1345,26 +1345,14 @@ begin
|
|||||||
Result:=Default;
|
Result:=Default;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
function StrToBool(const S: string): Boolean;
|
function StrToBool(const S: string): Boolean;
|
||||||
|
|
||||||
Var
|
|
||||||
Temp : String;
|
|
||||||
D : Double;
|
|
||||||
Code: word;
|
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Temp:=upcase(S);
|
if not(TryStrToBool(S,Result)) then
|
||||||
Val(temp,D,code);
|
|
||||||
If Code=0 then
|
|
||||||
Result:=(D<>0.0)
|
|
||||||
else If Temp='TRUE' then
|
|
||||||
result:=true
|
|
||||||
else if Temp='FALSE' then
|
|
||||||
result:=false
|
|
||||||
else
|
|
||||||
Raise EConvertError.CreateFmt(SInvalidBoolean,[S]);
|
Raise EConvertError.CreateFmt(SInvalidBoolean,[S]);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
function BoolToStr(B: Boolean): string;
|
function BoolToStr(B: Boolean): string;
|
||||||
begin
|
begin
|
||||||
If B then
|
If B then
|
||||||
@ -1373,6 +1361,34 @@ begin
|
|||||||
Result:='FALSE';
|
Result:='FALSE';
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
function StrToBoolDef(const S: string; Default: Boolean): Boolean;
|
||||||
|
begin
|
||||||
|
if not(TryStrToBool(S,Result)) then
|
||||||
|
Result:=Default;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
function TryStrToBool(const S: string; out Value: Boolean): Boolean;
|
||||||
|
Var
|
||||||
|
Temp : String;
|
||||||
|
D : Double;
|
||||||
|
Code: word;
|
||||||
|
begin
|
||||||
|
Temp:=upcase(S);
|
||||||
|
Val(temp,D,code);
|
||||||
|
Result:=true;
|
||||||
|
If Code=0 then
|
||||||
|
Value:=(D<>0.0)
|
||||||
|
else If Temp='TRUE' then
|
||||||
|
Value:=true
|
||||||
|
else if Temp='FALSE' then
|
||||||
|
Value:=false
|
||||||
|
else
|
||||||
|
Result:=false;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
Function FloatToTextFmt(Buffer: PChar; Value: Extended; format: PChar): Integer;
|
Function FloatToTextFmt(Buffer: PChar; Value: Extended; format: PChar): Integer;
|
||||||
|
|
||||||
Var
|
Var
|
||||||
|
@ -153,12 +153,17 @@ Function FloatToText(Buffer: PChar; Value: Extended; format: TFloatFormat; Preci
|
|||||||
Function FloatToDateTime (Const Value : Extended) : TDateTime;
|
Function FloatToDateTime (Const Value : Extended) : TDateTime;
|
||||||
Function FloattoCurr (Const Value : Extended) : Currency;
|
Function FloattoCurr (Const Value : Extended) : Currency;
|
||||||
function TryFloatToCurr(const Value: Extended; var AResult: Currency): Boolean;
|
function TryFloatToCurr(const Value: Extended; var AResult: Currency): Boolean;
|
||||||
|
|
||||||
Function CurrToStr(Value: Currency): string;
|
Function CurrToStr(Value: Currency): string;
|
||||||
function StrToCurr(const S: string): Currency;
|
function StrToCurr(const S: string): Currency;
|
||||||
function TryStrToCurr(const S: string;Var Value : Currency): Boolean;
|
function TryStrToCurr(const S: string;Var Value : Currency): Boolean;
|
||||||
function StrToCurrDef(const S: string; Default : Currency): Currency;
|
function StrToCurrDef(const S: string; Default : Currency): Currency;
|
||||||
|
|
||||||
function StrToBool(const S: string): Boolean;
|
function StrToBool(const S: string): Boolean;
|
||||||
function BoolToStr(B: Boolean): string;
|
function BoolToStr(B: Boolean): string;
|
||||||
|
function StrToBoolDef(const S: string; Default: Boolean): Boolean;
|
||||||
|
function TryStrToBool(const S: string; out Value: Boolean): Boolean;
|
||||||
|
|
||||||
function LastDelimiter(const Delimiters, S: string): Integer;
|
function LastDelimiter(const Delimiters, S: string): Integer;
|
||||||
function StringReplace(const S, OldPattern, NewPattern: string; Flags: TReplaceFlags): string;
|
function StringReplace(const S, OldPattern, NewPattern: string; Flags: TReplaceFlags): string;
|
||||||
Function FloatToTextFmt(Buffer: PChar; Value: Extended; format: PChar): Integer;
|
Function FloatToTextFmt(Buffer: PChar; Value: Extended; format: PChar): Integer;
|
||||||
|
71
tests/test/units/sysutils/tstrtobool.pp
Normal file
71
tests/test/units/sysutils/tstrtobool.pp
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
uses
|
||||||
|
sysutils;
|
||||||
|
var
|
||||||
|
b : boolean;
|
||||||
|
begin
|
||||||
|
if not TryStrToBool('true',b) then
|
||||||
|
halt(1);
|
||||||
|
if not b then
|
||||||
|
halt(1);
|
||||||
|
if not TryStrToBool('false',b) then
|
||||||
|
halt(1);
|
||||||
|
if b then
|
||||||
|
halt(1);
|
||||||
|
|
||||||
|
if not TryStrToBool('True',b) then
|
||||||
|
halt(1);
|
||||||
|
if not b then
|
||||||
|
halt(1);
|
||||||
|
if not TryStrToBool('False',b) then
|
||||||
|
halt(1);
|
||||||
|
if b then
|
||||||
|
halt(1);
|
||||||
|
|
||||||
|
if not TryStrToBool('truE',b) then
|
||||||
|
halt(1);
|
||||||
|
if not b then
|
||||||
|
halt(1);
|
||||||
|
if not TryStrToBool('falsE',b) then
|
||||||
|
halt(1);
|
||||||
|
if b then
|
||||||
|
halt(1);
|
||||||
|
|
||||||
|
if not TryStrToBool('TRUE',b) then
|
||||||
|
halt(1);
|
||||||
|
if not b then
|
||||||
|
halt(1);
|
||||||
|
if not TryStrToBool('FALSE',b) then
|
||||||
|
halt(1);
|
||||||
|
if b then
|
||||||
|
halt(1);
|
||||||
|
|
||||||
|
if not TryStrToBool('3.1415',b) then
|
||||||
|
halt(1);
|
||||||
|
if not b then
|
||||||
|
halt(1);
|
||||||
|
if not TryStrToBool('0.0',b) then
|
||||||
|
halt(1);
|
||||||
|
if b then
|
||||||
|
halt(1);
|
||||||
|
|
||||||
|
if TryStrToBool('',b) then
|
||||||
|
halt(1);
|
||||||
|
|
||||||
|
if TryStrToBool('asdf',b) then
|
||||||
|
halt(1);
|
||||||
|
|
||||||
|
b:=StrToBool('truE');
|
||||||
|
if not b then
|
||||||
|
halt(1);
|
||||||
|
b:=StrToBool('falsE');
|
||||||
|
if b then
|
||||||
|
halt(1);
|
||||||
|
|
||||||
|
if not(StrToBoolDef('',true)) then
|
||||||
|
halt(1);
|
||||||
|
|
||||||
|
if StrToBoolDef('asdf',false) then
|
||||||
|
halt(1);
|
||||||
|
|
||||||
|
writeln('ok');
|
||||||
|
end.
|
Loading…
Reference in New Issue
Block a user