mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-22 00:09:25 +02:00
[PATCH 128/188] adding number format support
From 7e195a3ab44683fb375c7a960b6e486619a077ab Mon Sep 17 00:00:00 2001 From: Dmitry Boyarintsev <skalogryz.lists@gmail.com> Date: Tue, 24 Mar 2020 14:50:10 -0400 git-svn-id: branches/wasm@46124 -
This commit is contained in:
parent
6419413641
commit
1a34ca2ea0
@ -45,7 +45,11 @@ procedure ParseCSSValues(const s: String; css: TStrings);
|
||||
procedure GetCssAbsBoundsRect(Css: TStrings; var r: TRect);
|
||||
function CssValInt(const s: String; Def: integer): Integer;
|
||||
|
||||
function ScanNumberC(const buf: string; var idx: Integer; var numberText: string): Boolean;
|
||||
type
|
||||
TCNumberFormat = (nfError, nfInteger, nfHex, nfFloat);
|
||||
|
||||
function ScanNumberC(const buf: string; var idx: Integer;
|
||||
var numberText: string): TCNumberFormat;
|
||||
|
||||
implementation
|
||||
|
||||
@ -233,11 +237,13 @@ begin
|
||||
Result:=Copy(s, i, index-i);
|
||||
end;
|
||||
|
||||
function ScanNumberC(const buf: string; var idx: Integer; var numberText: string): Boolean;
|
||||
function ScanNumberC(const buf: string; var idx: Integer; var numberText: string): TCNumberFormat;
|
||||
var
|
||||
ch : char;
|
||||
sec : string;
|
||||
begin
|
||||
Result := false;
|
||||
Result := nfError;
|
||||
|
||||
if buf[idx] in SignChars then begin
|
||||
ch:=buf[idx];
|
||||
inc(idx);
|
||||
@ -247,14 +253,23 @@ begin
|
||||
if (idx<length(buf)) and (buf[idx]='0') and (buf[idx+1]='x') then begin
|
||||
inc(idx,2);
|
||||
numberText:='0x'+ScanWhile(buf, idx, HexChars);
|
||||
end else
|
||||
Result := nfHex;
|
||||
end else begin
|
||||
numberText:=ScanWhile(buf, idx, NumericChars);
|
||||
if ((idx<=length(buf)) and (buf[idx]='.')) then begin
|
||||
inc(idx);
|
||||
sec := ScanWhile(buf, idx, NumericChars);
|
||||
if (sec = '') then Exit;
|
||||
numberText:=NumberText+'.'+sec;
|
||||
Result := nfFloat;
|
||||
end else
|
||||
Result := nfInteger;
|
||||
end;
|
||||
|
||||
if (ch<>#0) then begin
|
||||
if (numberText = '') then Exit;
|
||||
numberText:=ch+numberText;
|
||||
end;
|
||||
Result := true;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
@ -24,6 +24,14 @@ type
|
||||
weElem, weData, weOffset
|
||||
);
|
||||
|
||||
// used only for weNumber
|
||||
TWatNumberFormat = (
|
||||
wnfNo, // other than number
|
||||
wnfInteger, // 00
|
||||
wnfHex, // 0xABC
|
||||
wnfFloat // 0.000
|
||||
);
|
||||
|
||||
{ TWatScanner }
|
||||
|
||||
TWatScanner = class(TObject)
|
||||
@ -37,6 +45,7 @@ type
|
||||
instrCode : byte;
|
||||
ofs : integer;
|
||||
token : TWatToken;
|
||||
numformat : TWatNumberFormat;
|
||||
resText : string;
|
||||
asmCmd : string;
|
||||
|
||||
@ -200,7 +209,9 @@ function TWatScanner.Next: Boolean;
|
||||
var
|
||||
cmt : string;
|
||||
done: boolean;
|
||||
fmt : TCNumberFormat;
|
||||
begin
|
||||
numformat := wnfNo;
|
||||
Result := idx<=length(buf);
|
||||
if not Result then Exit;
|
||||
|
||||
@ -240,11 +251,19 @@ begin
|
||||
token:=weIdent;
|
||||
resText:=ScanWhile(buf, idx, IdBody);
|
||||
end else if buf[idx] in SignNumericChars then begin
|
||||
if not ScanNumberC(buf, idx, resText) then begin
|
||||
fmt := ScanNumberC(buf, idx, resText);
|
||||
if fmt = nfError then begin
|
||||
token := weError;
|
||||
Exit;
|
||||
end else
|
||||
token:=weNumber;
|
||||
case fmt of
|
||||
nfFloat: numformat := wnfFloat;
|
||||
nfHex: numformat := wnfHex;
|
||||
else
|
||||
numformat := wnfInteger;
|
||||
end;
|
||||
|
||||
end else if buf[idx] in AlphaNumChars then begin
|
||||
resText:=ScanWhile(buf, idx, GrammarChars);
|
||||
GetGrammar(resText, token, instrCode);
|
||||
|
Loading…
Reference in New Issue
Block a user