Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const string ParseRegexPattern = "(?<Sign>[+-]?)((?<BaseHex>0[Xx])|(?<BaseOct>0))?";
- static readonly Regex ParseRegex = new Regex(ParseRegexPattern, RegexOptions.Compiled);
- Match match = ParseRegex.Match(value, startIndex, endIndex - startIndex + 1);
- bool negative = false; // number sign
- bool stringNotEmpty = false; // true if string is already guaranteed to be non-empty
- // Determine sign and/or base
- Match match = ParseRegex.Match(value, startIndex, endIndex - startIndex + 1);
- if (match.Groups["Sign"].Value == "-")
- {
- negative = true;
- }
- if (match.Groups["BaseHex"].Length != 0)
- {
- if (checkFormat)
- {
- // 0x before the number - this is hex number
- numberBase = 16U;
- }
- else
- {
- // This is an error
- throw new FormatException(Strings.ParseInvalidChar);
- }
- }
- else if (match.Groups["BaseOct"].Length != 0)
- {
- if (checkFormat)
- {
- // 0 before the number - this is octal number
- numberBase = 8U;
- }
- stringNotEmpty = true;
- }
Advertisement
Add Comment
Please, Sign In to add comment