Exemplo n.º 1
0
        /// <summary>
        /// 根据字符串查找目标索引
        /// </summary>
        /// <param name="jsonDeSerializer">JSON 解析器</param>
        /// <param name="value">第一个字符</param>
        /// <returns>目标索引,null返回-1</returns>
        internal int searchString(JsonDeSerializer jsonDeSerializer, char value)
        {
            byte *currentState = State;

            do
            {
                char *prefix = (char *)(currentState + *(int *)currentState);
                if (*prefix != 0)
                {
                    if (value != *prefix)
                    {
                        return(-1);
                    }
                    while (*++prefix != 0)
                    {
                        if (jsonDeSerializer.NextStringChar() != *prefix)
                        {
                            return(-1);
                        }
                    }
                    value = jsonDeSerializer.NextStringChar();
                }
                if (value == 0)
                {
                    return(jsonDeSerializer.DeSerializeState == DeSerializeState.Success ? *(int *)(currentState + sizeof(int) * 2) : -1);
                }
                if (*(int *)(currentState + sizeof(int)) == 0)
                {
                    return(-1);
                }
                int   index = value < 128 ? (int)*(ushort *)(charsAscii + (value << 1)) : getCharIndex(value);
                byte *table = currentState + *(int *)(currentState + sizeof(int));
                if (tableType == 0)
                {
                    if ((index = *(table + index)) == 0)
                    {
                        return(-1);
                    }
                    currentState = State + index * 3 * sizeof(int);
                }
                else if (tableType == 1)
                {
                    if ((index = (int)*(ushort *)(table + index * sizeof(ushort))) == 0)
                    {
                        return(-1);
                    }
                    currentState = State + index * 3 * sizeof(int);
                }
                else
                {
                    if ((index = *(int *)(table + index * sizeof(int))) == 0)
                    {
                        return(-1);
                    }
                    currentState = State + index;
                }
                value = jsonDeSerializer.NextStringChar();
            }while (true);
        }