mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-18 14:49:11 +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);
|
procedure GetCssAbsBoundsRect(Css: TStrings; var r: TRect);
|
||||||
function CssValInt(const s: String; Def: integer): Integer;
|
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
|
implementation
|
||||||
|
|
||||||
@ -233,11 +237,13 @@ begin
|
|||||||
Result:=Copy(s, i, index-i);
|
Result:=Copy(s, i, index-i);
|
||||||
end;
|
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
|
var
|
||||||
ch : char;
|
ch : char;
|
||||||
|
sec : string;
|
||||||
begin
|
begin
|
||||||
Result := false;
|
Result := nfError;
|
||||||
|
|
||||||
if buf[idx] in SignChars then begin
|
if buf[idx] in SignChars then begin
|
||||||
ch:=buf[idx];
|
ch:=buf[idx];
|
||||||
inc(idx);
|
inc(idx);
|
||||||
@ -247,14 +253,23 @@ begin
|
|||||||
if (idx<length(buf)) and (buf[idx]='0') and (buf[idx+1]='x') then begin
|
if (idx<length(buf)) and (buf[idx]='0') and (buf[idx+1]='x') then begin
|
||||||
inc(idx,2);
|
inc(idx,2);
|
||||||
numberText:='0x'+ScanWhile(buf, idx, HexChars);
|
numberText:='0x'+ScanWhile(buf, idx, HexChars);
|
||||||
end else
|
Result := nfHex;
|
||||||
|
end else begin
|
||||||
numberText:=ScanWhile(buf, idx, NumericChars);
|
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 (ch<>#0) then begin
|
||||||
if (numberText = '') then Exit;
|
if (numberText = '') then Exit;
|
||||||
numberText:=ch+numberText;
|
numberText:=ch+numberText;
|
||||||
end;
|
end;
|
||||||
Result := true;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
@ -24,6 +24,14 @@ type
|
|||||||
weElem, weData, weOffset
|
weElem, weData, weOffset
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// used only for weNumber
|
||||||
|
TWatNumberFormat = (
|
||||||
|
wnfNo, // other than number
|
||||||
|
wnfInteger, // 00
|
||||||
|
wnfHex, // 0xABC
|
||||||
|
wnfFloat // 0.000
|
||||||
|
);
|
||||||
|
|
||||||
{ TWatScanner }
|
{ TWatScanner }
|
||||||
|
|
||||||
TWatScanner = class(TObject)
|
TWatScanner = class(TObject)
|
||||||
@ -37,6 +45,7 @@ type
|
|||||||
instrCode : byte;
|
instrCode : byte;
|
||||||
ofs : integer;
|
ofs : integer;
|
||||||
token : TWatToken;
|
token : TWatToken;
|
||||||
|
numformat : TWatNumberFormat;
|
||||||
resText : string;
|
resText : string;
|
||||||
asmCmd : string;
|
asmCmd : string;
|
||||||
|
|
||||||
@ -200,7 +209,9 @@ function TWatScanner.Next: Boolean;
|
|||||||
var
|
var
|
||||||
cmt : string;
|
cmt : string;
|
||||||
done: boolean;
|
done: boolean;
|
||||||
|
fmt : TCNumberFormat;
|
||||||
begin
|
begin
|
||||||
|
numformat := wnfNo;
|
||||||
Result := idx<=length(buf);
|
Result := idx<=length(buf);
|
||||||
if not Result then Exit;
|
if not Result then Exit;
|
||||||
|
|
||||||
@ -240,11 +251,19 @@ begin
|
|||||||
token:=weIdent;
|
token:=weIdent;
|
||||||
resText:=ScanWhile(buf, idx, IdBody);
|
resText:=ScanWhile(buf, idx, IdBody);
|
||||||
end else if buf[idx] in SignNumericChars then begin
|
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;
|
token := weError;
|
||||||
Exit;
|
Exit;
|
||||||
end else
|
end else
|
||||||
token:=weNumber;
|
token:=weNumber;
|
||||||
|
case fmt of
|
||||||
|
nfFloat: numformat := wnfFloat;
|
||||||
|
nfHex: numformat := wnfHex;
|
||||||
|
else
|
||||||
|
numformat := wnfInteger;
|
||||||
|
end;
|
||||||
|
|
||||||
end else if buf[idx] in AlphaNumChars then begin
|
end else if buf[idx] in AlphaNumChars then begin
|
||||||
resText:=ScanWhile(buf, idx, GrammarChars);
|
resText:=ScanWhile(buf, idx, GrammarChars);
|
||||||
GetGrammar(resText, token, instrCode);
|
GetGrammar(resText, token, instrCode);
|
||||||
|
Loading…
Reference in New Issue
Block a user