mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-21 20:09:25 +02:00
[PATCH 092/188] scanning C number
From 17a1dcc3208ce1a4d3a4cd8028b40b2c0a8b6fda Mon Sep 17 00:00:00 2001 From: Dmitry Boyarintsev <skalogryz.lists@gmail.com> Date: Tue, 10 Mar 2020 09:06:51 -0400 git-svn-id: branches/wasm@46088 -
This commit is contained in:
parent
bce20892c9
commit
9383c8af45
@ -17,6 +17,7 @@ const
|
||||
WhiteSpaceChars = SpaceChars;
|
||||
SpaceEolnChars = EoLnChars+SpaceChars;
|
||||
NumericChars = ['0'..'9'];
|
||||
HexChars = ['0'..'9','a'..'f','A'..'F'];
|
||||
SignChars = ['+','-'];
|
||||
SignNumericChars = NumericChars + SignChars;
|
||||
AlphabetChars = ['a'..'z','A'..'Z'];
|
||||
@ -44,6 +45,8 @@ 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;
|
||||
|
||||
implementation
|
||||
|
||||
function CssValInt(const s: String; Def: integer): Integer;
|
||||
@ -230,5 +233,29 @@ begin
|
||||
Result:=Copy(s, i, index-i);
|
||||
end;
|
||||
|
||||
function ScanNumberC(const buf: string; var idx: Integer; var numberText: string): Boolean;
|
||||
var
|
||||
ch : char;
|
||||
begin
|
||||
Result := false;
|
||||
if buf[idx] in SignChars then begin
|
||||
ch:=buf[idx];
|
||||
inc(idx);
|
||||
end else
|
||||
ch := #0;
|
||||
|
||||
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
|
||||
numberText:=ScanWhile(buf, idx, NumericChars);
|
||||
|
||||
if (ch<>#0) then begin
|
||||
if (numberText = '') then Exit;
|
||||
numberText:=ch+numberText;
|
||||
end;
|
||||
Result := true;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user