Guest User

CSharp Version

a guest
Aug 29th, 2015
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.08 KB | None | 0 0
  1. const string ParseRegexPattern = "(?<Sign>[+-]?)((?<BaseHex>0[Xx])|(?<BaseOct>0))?";
  2.  
  3. static readonly Regex ParseRegex = new Regex(ParseRegexPattern, RegexOptions.Compiled);
  4.  
  5. Match match = ParseRegex.Match(value, startIndex, endIndex - startIndex + 1);
  6.  
  7. bool negative = false; // number sign
  8.             bool stringNotEmpty = false; // true if string is already guaranteed to be non-empty
  9.            
  10.             // Determine sign and/or base
  11.            
  12.             Match match = ParseRegex.Match(value, startIndex, endIndex - startIndex + 1);
  13.            
  14.             if (match.Groups["Sign"].Value == "-")
  15.             {
  16.                 negative = true;
  17.             }
  18.             if (match.Groups["BaseHex"].Length != 0)
  19.             {
  20.                 if (checkFormat)
  21.                 {
  22.                     // 0x before the number - this is hex number
  23.                     numberBase = 16U;
  24.                 }
  25.                 else
  26.                 {
  27.                     // This is an error
  28.                     throw new FormatException(Strings.ParseInvalidChar);
  29.                 }
  30.             }
  31.             else if (match.Groups["BaseOct"].Length != 0)
  32.             {
  33.                 if (checkFormat)
  34.                 {
  35.                     // 0 before the number - this is octal number
  36.                     numberBase = 8U;
  37.                 }
  38.  
  39.                 stringNotEmpty = true;
  40.             }
Advertisement
Add Comment
Please, Sign In to add comment