Browse Source

[PATCH 092/188] scanning C number

From 17a1dcc3208ce1a4d3a4cd8028b40b2c0a8b6fda Mon Sep 17 00:00:00 2001
From: Dmitry Boyarintsev <[email protected]>
Date: Tue, 10 Mar 2020 09:06:51 -0400

git-svn-id: branches/wasm@46088 -
nickysn 5 years ago
parent
commit
9383c8af45
1 changed files with 27 additions and 0 deletions
  1. 27 0
      utils/wasmbin/parseutils.pas

+ 27 - 0
utils/wasmbin/parseutils.pas

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