* only allow decimalseparator to be used as decimal separator in

texttofloat() and friends, rather than both '.' and decimalseparator
    (mantis )

git-svn-id: trunk@11069 -
This commit is contained in:
Jonas Maebe 2008-05-24 08:49:34 +00:00
parent fb3242b2f7
commit e60e078eb5
3 changed files with 52 additions and 3 deletions
.gitattributes
rtl/objpas/sysutils
tests/webtbs

1
.gitattributes vendored
View File

@ -9133,6 +9133,7 @@ tests/webtbs/tw9098.pp svneol=native#text/plain
tests/webtbs/tw9107.pp svneol=native#text/plain
tests/webtbs/tw9108.pp svneol=native#text/plain
tests/webtbs/tw9113.pp svneol=native#text/plain
tests/webtbs/tw9126.pp svneol=native#text/plain
tests/webtbs/tw9128.pp svneol=native#text/plain
tests/webtbs/tw9139.pp svneol=native#text/plain
tests/webtbs/tw9139a.pp svneol=native#text/plain

View File

@ -1024,9 +1024,19 @@ Var
Begin
S:=StrPas(Buffer);
P:=Pos(FormatSettings.DecimalSeparator,S);
If (P<>0) Then
S[P] := '.';
if (FormatSettings.DecimalSeparator<>'.') then
begin
{ only decimalseparator may appear in the string }
P:=Pos('.',S);
if (P<>0) then
begin
result:=false;
exit;
end;
P:=Pos(FormatSettings.DecimalSeparator,S);
If (P<>0) Then
S[P] := '.';
end;
Val(trim(S),Value,E);
Result:=(E=0);
End;

38
tests/webtbs/tw9126.pp Normal file
View File

@ -0,0 +1,38 @@
{$ifdef fpc}
{$mode delphi}
{$endif}
uses sysutils;
var
failed : boolean;
procedure testconvert(s : string; shouldsucceed: boolean);
var
succeeded: boolean;
begin
succeeded:=true;
try
writeln(strtofloat(s));
except
on EConvertError do begin
writeln('Failed to convert ', s, ' to a float value');
succeeded := false;
end;
end;
failed:=failed or (succeeded<>shouldsucceed);
end;
begin
failed := false;
thousandseparator := '.';
decimalseparator := ',';
testconvert('1.200',false); // fails
testconvert('1,200',true); // working
testconvert('1.200,23',false); // fails
testconvert('1.200.300',false); // fails
if (failed) then halt(1);
end.