[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:
nickysn 2020-08-03 13:01:22 +00:00
parent 6419413641
commit 1a34ca2ea0
2 changed files with 40 additions and 6 deletions

View File

@ -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.

View File

@ -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);