Esempio n. 1
0
        private TokenType SkipNumber(char ch, StringBuilder buffer, ref int hash)
        {
            StringHasher hasher = StringHasher.Create();

            if (ch == '-')
            {
                hasher.AddChar(ch);
                buffer?.Append(ch);
                ch = this.NextChar();
            }

            if (!Tokenizer.IsDigit(ch))
            {
                return(TokenType.Error);
            }

            ch = this.SkipDigits(ch, buffer, ref hasher);

            if (ch == '.')
            {
                hasher.AddChar(ch);
                buffer?.Append(ch);
                ch = this.NextChar();

                if (!Tokenizer.IsDigit(ch))
                {
                    return(TokenType.Error);
                }

                ch = this.SkipDigits(ch, buffer, ref hasher);
            }

            if (ch == 'e' || ch == 'E')
            {
                hasher.AddChar(ch);
                buffer?.Append(ch);
                ch = this.NextChar();

                if (ch == '-' || ch == '+')
                {
                    hasher.AddChar(ch);
                    buffer?.Append(ch);
                    ch = this.NextChar();
                }

                if (!Tokenizer.IsDigit(ch))
                {
                    return(TokenType.Error);
                }

                this.SkipDigits(ch, buffer, ref hasher);
            }

            hash = hasher.HashValue;
            Debug.Assert(buffer == null || StringHasher.HashSubstring(buffer.ToString(), 0, buffer.Length) == hash);

            return(TokenType.Number);
        }
        public HasherResolver(EqualityContext context, MembersProvider membersProvider, IConfigurationProvider configuration)
        {
            _configuration = configuration;

            _hashersFactories = new Func <IVariable, IHasherEmitter>[] {
                variable => NullableHasher.Create(this, variable),
                variable => StringHasher.Create(_configuration, variable),
                BasicHasher.Create,
                variable => MembersHasher.Create(this, membersProvider, _configuration, variable),
                variable => ArrayHasher.Create(this, _configuration, variable),
                variable => EnumerablesHasher.Create(this, _configuration, variable),
                variable => IndirectHasher.Create(context, variable)
            };
        }
Esempio n. 3
0
        private TokenType SkipString(StringBuilder buffer, ref int hash)
        {
            TokenType    type   = TokenType.String;
            StringHasher hasher = StringHasher.Create();
            char         ch     = this.NextChar();

            while (true)
            {
                if (ch == '\"')
                {
                    _ = this.NextChar();
                    break;
                }
                else if (ch == '\\')
                {
                    type = TokenType.EncodedString;
                    hasher.AddChar(ch);
                    buffer?.Append(ch);
                    ch = this.NextChar();

                    switch (ch)
                    {
                    case '\"':
                    case '\\':
                    case '/':
                    case 'b':
                    case 'f':
                    case 'n':
                    case 'r':
                    case 't':
                        hasher.AddChar(ch);
                        buffer?.Append(ch);
                        ch = this.NextChar();
                        break;

                    case 'u':
                        hasher.AddChar(ch);
                        buffer?.Append(ch);
                        ch = this.NextChar();
                        if (!Tokenizer.IsHexDigit(ch))
                        {
                            return(TokenType.Error);
                        }

                        hasher.AddChar(ch);     // 1
                        buffer?.Append(ch);
                        ch = this.NextChar();
                        if (!Tokenizer.IsHexDigit(ch))
                        {
                            return(TokenType.Error);
                        }

                        hasher.AddChar(ch);     // 2
                        buffer?.Append(ch);
                        ch = this.NextChar();
                        if (!Tokenizer.IsHexDigit(ch))
                        {
                            return(TokenType.Error);
                        }

                        hasher.AddChar(ch);     // 3
                        buffer?.Append(ch);
                        ch = this.NextChar();
                        if (!Tokenizer.IsHexDigit(ch))
                        {
                            return(TokenType.Error);
                        }

                        hasher.AddChar(ch);     // 4
                        buffer?.Append(ch);
                        ch = this.NextChar();
                        break;

                    default:
                        return(TokenType.Error);
                    }
                }
                else if (ch < ' ')
                {
                    return(TokenType.Error);
                }
                else
                {
                    hasher.AddChar(ch);
                    buffer?.Append(ch);
                    ch = this.NextChar();
                }
            }

            hash = hasher.HashValue;
            Debug.Assert(buffer == null || StringHasher.HashSubstring(buffer.ToString(), 0, buffer.Length) == hash);

            return(type);
        }