Advertisement
Guest User

Pascal Version

a guest
Aug 29th, 2015
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.97 KB | None | 0 0
  1.  const
  2.     ParseRegexPattern: String = '(?<Sign>[+-]?)((?<BaseHex>\$)|(?<BaseOct>0))?';
  3.     var
  4.         ParseRegex: TRegEx;
  5.         sMatch: TMatch;
  6.         numberBase: UInt32;
  7.         checkFormat: Boolean;
  8.   begin
  9.  
  10. ParseRegex := TRegEx.Create(ParseRegexPattern, [roCompiled]);
  11.  
  12.    if (sMatch.Groups['Sign'].Value = '-') then
  13.     begin
  14.       negative := True;
  15.     end;
  16.  
  17.      if (smatch.Groups['BaseHex'].Length <> 0) then
  18.     begin
  19.       if (checkFormat) then
  20.       begin
  21.         // $ before the number - this is hex number
  22.         numberBase := UInt32(16);
  23.       end
  24.       else
  25.       begin
  26.         // This is an error
  27.         raise Exception.Create(Strings.ParseInvalidChar);
  28.       end
  29.     end  
  30.  
  31.     else
  32.  
  33.  if (smatch.Groups['BaseOct'].Length <> 0) then
  34.     begin
  35.       if (checkFormat) then
  36.       begin
  37.         // 0 before the number - this is octal number
  38.         numberBase := UInt32(8);
  39.       end;
  40.  
  41.       stringNotEmpty := True;
  42.     end;
  43.  
  44.    end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement