mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-09-13 06:31:36 +02:00
pastojs: fixed removing leading zeroes from hex numbers
git-svn-id: trunk@39010 -
This commit is contained in:
parent
77dc0597e9
commit
0fcec04382
@ -6277,11 +6277,27 @@ function TPasToJSConverter.ConvertPrimitiveExpression(El: TPrimitiveExpr;
|
|||||||
|
|
||||||
function DeleteLeadingZeroes(const s: string): string;
|
function DeleteLeadingZeroes(const s: string): string;
|
||||||
// Note: 01 is in JS octal, and in strict mode forbidden
|
// Note: 01 is in JS octal, and in strict mode forbidden
|
||||||
|
// $00ff00 -> $ff00
|
||||||
|
// 00E001 -> 0E1
|
||||||
|
// 0.001 -> 0.001
|
||||||
|
// 0.00E1 -> 0.00E1
|
||||||
var
|
var
|
||||||
i: Integer;
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
Result:=s;
|
Result:=s;
|
||||||
i:=1;
|
i:=1;
|
||||||
|
if Result[1]='$' then
|
||||||
|
// hexadecimal -> can not be a float, 'E' is a hexdigit
|
||||||
|
while i<length(Result) do
|
||||||
|
begin
|
||||||
|
if (Result[i]='0') and (Result[i+1] in ['0'..'9','A'..'F','a'..'f'])
|
||||||
|
and ((i=1) or not (Result[i-1] in ['0'..'9','A'..'F','a'..'f'])) then
|
||||||
|
Delete(Result,i,1)
|
||||||
|
else
|
||||||
|
inc(i);
|
||||||
|
end
|
||||||
|
else
|
||||||
|
// decimal, can be a float, 'E' is a start of a new number
|
||||||
while i<length(Result) do
|
while i<length(Result) do
|
||||||
begin
|
begin
|
||||||
if (Result[i]='0') and (Result[i+1] in ['0'..'9'])
|
if (Result[i]='0') and (Result[i+1] in ['0'..'9'])
|
||||||
@ -6338,7 +6354,8 @@ begin
|
|||||||
// number was rounded -> we lost precision
|
// number was rounded -> we lost precision
|
||||||
DoError(20161024230812,nInvalidNumber,sInvalidNumber,[El.Value],El);
|
DoError(20161024230812,nInvalidNumber,sInvalidNumber,[El.Value],El);
|
||||||
L:=CreateLiteralNumber(El,Number);
|
L:=CreateLiteralNumber(El,Number);
|
||||||
S:=DeleteLeadingZeroes(copy(El.Value,2,length(El.Value)));
|
S:=DeleteLeadingZeroes(El.Value);
|
||||||
|
S:=copy(S,2,length(S));
|
||||||
case El.Value[1] of
|
case El.Value[1] of
|
||||||
'$': S:='0x'+S;
|
'$': S:='0x'+S;
|
||||||
'&': if TargetProcessor=ProcessorECMAScript5 then
|
'&': if TargetProcessor=ProcessorECMAScript5 then
|
||||||
|
@ -2154,6 +2154,7 @@ begin
|
|||||||
Add(' i8: byte = 00;');
|
Add(' i8: byte = 00;');
|
||||||
Add(' u8: nativeuint = $fffffffffffff;');
|
Add(' u8: nativeuint = $fffffffffffff;');
|
||||||
Add(' u9: nativeuint = $0000000000000;');
|
Add(' u9: nativeuint = $0000000000000;');
|
||||||
|
Add(' u10: nativeuint = $00ff00;');
|
||||||
Add('begin');
|
Add('begin');
|
||||||
ConvertProgram;
|
ConvertProgram;
|
||||||
CheckSource('TestVarBaseTypes',
|
CheckSource('TestVarBaseTypes',
|
||||||
@ -2175,7 +2176,8 @@ begin
|
|||||||
'this.i7 =-0x10000000000000;',
|
'this.i7 =-0x10000000000000;',
|
||||||
'this.i8 = 0;',
|
'this.i8 = 0;',
|
||||||
'this.u8 = 0xfffffffffffff;',
|
'this.u8 = 0xfffffffffffff;',
|
||||||
'this.u9 = 0x0;'
|
'this.u9 = 0x0;',
|
||||||
|
'this.u10 = 0xff00;'
|
||||||
]),
|
]),
|
||||||
'');
|
'');
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user