mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-20 09:49:08 +02:00
* patch by Bart B: fixes fpc_val_word_shortstr() and refactors fpc_val_longword_shortstr() so that it uses the same algorithm and naming conventions as the other unsigned val-helpers.
This commit is contained in:
parent
5f089afdfb
commit
2f8750924f
@ -1483,7 +1483,7 @@ end;
|
|||||||
base : byte;
|
base : byte;
|
||||||
negative : boolean;
|
negative : boolean;
|
||||||
|
|
||||||
const maxlongword=longword($ffffffff);
|
const UpperLimit=High(longword);
|
||||||
|
|
||||||
begin
|
begin
|
||||||
fpc_val_longword_shortstr:=0;
|
fpc_val_longword_shortstr:=0;
|
||||||
@ -1498,22 +1498,20 @@ end;
|
|||||||
end;
|
end;
|
||||||
while Code<=Length(s) do
|
while Code<=Length(s) do
|
||||||
begin
|
begin
|
||||||
case s[Code] of
|
u:=16;
|
||||||
'0'..'9' : u:=Ord(S[Code])-Ord('0');
|
case s[code] of
|
||||||
'A'..'F' : u:=Ord(S[Code])-(Ord('A')-10);
|
'0'..'f' : u:=ValValueArray[S[Code]];
|
||||||
'a'..'f' : u:=Ord(S[Code])-(Ord('a')-10);
|
|
||||||
#0 : break;
|
#0 : break;
|
||||||
else
|
else
|
||||||
u:=16;
|
;
|
||||||
end;
|
end;
|
||||||
prev := fpc_val_longword_shortstr;
|
|
||||||
If (u>=base) or
|
If (u>=base) or
|
||||||
((LongWord(maxlongword-u) div LongWord(base))<prev) then
|
(ValUInt(UpperLimit-u) div ValUInt(Base)<fpc_val_longword_shortstr) then
|
||||||
Begin
|
begin
|
||||||
fpc_val_longword_shortstr := 0;
|
fpc_val_longword_shortstr:=0;
|
||||||
Exit
|
exit;
|
||||||
End;
|
end;
|
||||||
fpc_val_longword_shortstr:=fpc_val_longword_shortstr*LongWord(base) + u;
|
fpc_val_longword_shortstr:=fpc_val_longword_shortstr*ValUInt(base) + u;
|
||||||
inc(code);
|
inc(code);
|
||||||
end;
|
end;
|
||||||
code := 0;
|
code := 0;
|
||||||
@ -1582,7 +1580,7 @@ end;
|
|||||||
base : byte;
|
base : byte;
|
||||||
negative : boolean;
|
negative : boolean;
|
||||||
|
|
||||||
const maxlongword=longword($ffffffff);
|
const UpperLimit=High(Word); //this preserves 3.2 (and earlier) behaviour
|
||||||
|
|
||||||
begin
|
begin
|
||||||
fpc_val_word_shortstr:=0;
|
fpc_val_word_shortstr:=0;
|
||||||
@ -1600,22 +1598,20 @@ end;
|
|||||||
end;
|
end;
|
||||||
while Code<=Length(s) do
|
while Code<=Length(s) do
|
||||||
begin
|
begin
|
||||||
case s[Code] of
|
u:=16;
|
||||||
'0'..'9' : u:=Ord(S[Code])-Ord('0');
|
case s[code] of
|
||||||
'A'..'F' : u:=Ord(S[Code])-(Ord('A')-10);
|
'0'..'f' : u:=ValValueArray[S[Code]];
|
||||||
'a'..'f' : u:=Ord(S[Code])-(Ord('a')-10);
|
|
||||||
#0 : break;
|
#0 : break;
|
||||||
else
|
else
|
||||||
u:=16;
|
;
|
||||||
end;
|
end;
|
||||||
prev := fpc_val_word_shortstr;
|
|
||||||
If (u>=base) or
|
If (u>=base) or
|
||||||
((LongWord(maxlongword-u) div LongWord(base))<prev) then
|
(ValUInt(UpperLimit-u) div ValUInt(Base)<fpc_val_word_shortstr) then
|
||||||
Begin
|
begin
|
||||||
fpc_val_word_shortstr := 0;
|
fpc_val_word_shortstr:=0;
|
||||||
Exit
|
exit;
|
||||||
End;
|
end;
|
||||||
fpc_val_word_shortstr:=fpc_val_word_shortstr*LongWord(base) + u;
|
fpc_val_word_shortstr:=fpc_val_word_shortstr*ValUInt(base) + u;
|
||||||
inc(code);
|
inc(code);
|
||||||
end;
|
end;
|
||||||
code := 0;
|
code := 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user