public void IsCharHexDigitTest()
 {
     Assert.False(UriParserHelper.IsCharHexDigit(' '));
     Assert.True(UriParserHelper.IsCharHexDigit('0'));
     Assert.True(UriParserHelper.IsCharHexDigit('1'));
     Assert.True(UriParserHelper.IsCharHexDigit('9'));
     Assert.False(UriParserHelper.IsCharHexDigit(':'));
     Assert.True(UriParserHelper.IsCharHexDigit('A'));
     Assert.True(UriParserHelper.IsCharHexDigit('B'));
     Assert.True(UriParserHelper.IsCharHexDigit('F'));
     Assert.False(UriParserHelper.IsCharHexDigit('G'));
     Assert.True(UriParserHelper.IsCharHexDigit('a'));
     Assert.True(UriParserHelper.IsCharHexDigit('b'));
     Assert.True(UriParserHelper.IsCharHexDigit('f'));
     Assert.False(UriParserHelper.IsCharHexDigit('g'));
 }
示例#2
0
 public void IsCharHexDigitTest()
 {
     UriParserHelper.IsCharHexDigit(' ').Should().BeFalse();
     UriParserHelper.IsCharHexDigit('0').Should().BeTrue();
     UriParserHelper.IsCharHexDigit('1').Should().BeTrue();
     UriParserHelper.IsCharHexDigit('9').Should().BeTrue();
     UriParserHelper.IsCharHexDigit(':').Should().BeFalse();
     UriParserHelper.IsCharHexDigit('A').Should().BeTrue();
     UriParserHelper.IsCharHexDigit('B').Should().BeTrue();
     UriParserHelper.IsCharHexDigit('F').Should().BeTrue();
     UriParserHelper.IsCharHexDigit('G').Should().BeFalse();
     UriParserHelper.IsCharHexDigit('a').Should().BeTrue();
     UriParserHelper.IsCharHexDigit('b').Should().BeTrue();
     UriParserHelper.IsCharHexDigit('f').Should().BeTrue();
     UriParserHelper.IsCharHexDigit('g').Should().BeFalse();
 }
示例#3
0
        /// <summary>Parses a token that starts with a digit.</summary>
        /// <returns>The kind of token recognized.</returns>
        private ExpressionTokenKind ParseFromDigit()
        {
            Debug.Assert(this.IsValidDigit || ('-' == this.ch), "this.IsValidDigit || ('-' == this.ch)");
            ExpressionTokenKind result;
            int  tokenPos  = this.textPos;
            char startChar = this.ch.Value;

            this.NextChar();
            if (startChar == '0' && (this.ch == 'x' || this.ch == 'X'))
            {
                result = ExpressionTokenKind.BinaryLiteral;
                do
                {
                    this.NextChar();
                }while (this.ch.HasValue && UriParserHelper.IsCharHexDigit(this.ch.Value));
            }
            else
            {
                result = ExpressionTokenKind.IntegerLiteral;
                while (this.IsValidDigit)
                {
                    this.NextChar();
                }

                // DateTimeOffset, Date and Guids will have '-' in them
                if (this.ch == '-')
                {
                    if (this.TryParseDateTimeoffset(tokenPos))
                    {
                        return(ExpressionTokenKind.DateTimeOffsetLiteral);
                    }
                    else if (this.TryParseGuid(tokenPos))
                    {
                        return(ExpressionTokenKind.GuidLiteral);
                    }
                }

                // TimeOfDay will have ":" in them
                if (this.ch == ':')
                {
                    if (this.TryParseTimeOfDay(tokenPos))
                    {
                        return(ExpressionTokenKind.TimeOfDayLiteral);
                    }
                }

                // Guids will have alpha-numeric characters along with '-', so if a letter is encountered
                // try to see if this is Guid or not.
                if (this.ch.HasValue && Char.IsLetter(this.ch.Value))
                {
                    if (this.TryParseGuid(tokenPos))
                    {
                        return(ExpressionTokenKind.GuidLiteral);
                    }
                }

                if (this.ch == '.')
                {
                    result = ExpressionTokenKind.DoubleLiteral;
                    this.NextChar();
                    this.ValidateDigit();

                    do
                    {
                        this.NextChar();
                    }while (this.IsValidDigit);
                }

                if (this.ch == 'E' || this.ch == 'e')
                {
                    result = ExpressionTokenKind.DoubleLiteral;
                    this.NextChar();
                    if (this.ch == '+' || this.ch == '-')
                    {
                        this.NextChar();
                    }

                    this.ValidateDigit();
                    do
                    {
                        this.NextChar();
                    }while (this.IsValidDigit);
                }

                if (this.ch == 'M' || this.ch == 'm')
                {
                    result = ExpressionTokenKind.DecimalLiteral;
                    this.NextChar();
                }
                else if (this.ch == 'd' || this.ch == 'D')
                {
                    result = ExpressionTokenKind.DoubleLiteral;
                    this.NextChar();
                }
                else if (this.ch == 'L' || this.ch == 'l')
                {
                    result = ExpressionTokenKind.Int64Literal;
                    this.NextChar();
                }
                else if (this.ch == 'f' || this.ch == 'F')
                {
                    result = ExpressionTokenKind.SingleLiteral;
                    this.NextChar();
                }
                else
                {
                    string valueStr = this.Text.Substring(tokenPos, this.textPos - tokenPos);
                    result = MakeBestGuessOnNoSuffixStr(valueStr, result);
                }
            }

            return(result);
        }