Exemple #1
0
        /// <summary>
        /// 根据HTML获取模板树
        /// </summary>
        /// <param name="html">HTML</param>
        protected unsafe void create(string html)
        {
            if (html != null)
            {
                if (html.Length >= 3)
                {
                    MemoryMap atFixedMap = atMap;
                    byte *    commandUniqueHashDataFixed = commandUniqueHashData.Byte;
                    fixed(char *htmlFixed = html)
                    {
                        char *start = htmlFixed, end = htmlFixed + html.Length - 1, current = htmlFixed;
                        char  endChar = *end;

                        do
                        {
                            for (*end = '<'; *current != '<'; ++current)
                            {
                                ;
                            }
                            if (current == end)
                            {
                                break;
                            }
                            if (*++current == '!' && *(int *)++current == ('-' | ('-' << 16)))
                            {
                                char *tagStart = current += 2;
                                for (*end = '>'; *current != '>'; ++current)
                                {
                                    ;
                                }
                                if (current == end && endChar != '>')
                                {
                                    break;
                                }
                                if (*(int *)(current -= 2) == ('-' | ('-' << 16)))
                                {
                                    char *contentStart = tagStart;
                                    for (*current = ':'; *contentStart != ':'; ++contentStart)
                                    {
                                        ;
                                    }
                                    *current = '-';
                                    int   tagLength = (int)(contentStart - tagStart), tagIndex = (((*tagStart >> 1) ^ (tagStart[tagLength >> 2] >> 2)) & ((1 << 4) - 1));
                                    byte *hashData = commandUniqueHashDataFixed + (tagIndex * commandUniqueHashDataSize);
                                    if (*(int *)hashData == tagLength && Memory.SimpleEqualNotNull((byte *)tagStart, hashData + sizeof(int), tagLength << 1))
                                    {
                                        ViewTreeTag tag = new ViewTreeTag
                                        {
                                            Type    = ViewTreeTagType.Note,
                                            Command = new SubString {
                                                String = html, Start = (int)(tagStart - htmlFixed), Length = (int)(contentStart - tagStart)
                                            },
                                            Content = contentStart == current ? new SubString {
                                                String = html
                                            } : new SubString {
                                                String = html, Start = (int)(++contentStart - htmlFixed), Length = (int)(current - contentStart)
                                            }
                                        };
                                        #region =@取值解析
                                        if (start != (tagStart -= 4))
                                        {
                                            contentStart = start;
                                            *tagStart = '@';
                                            do
                                            {
                                                while (*++contentStart != '@')
                                                {
                                                    ;
                                                }
                                                if (contentStart == tagStart)
                                                {
                                                    break;
                                                }
                                                if (*--contentStart == '=' && *(contentStart + 2) != '[')
                                                {
                                                    if (start != contentStart)
                                                    {
                                                        appendHtml(new SubString {
                                                            String = html, Start = (int)(start - htmlFixed), Length = (int)(contentStart - start)
                                                        });
                                                    }
                                                    start = (contentStart += 2);
                                                    if (contentStart == tagStart)
                                                    {
                                                        appendAtNode(new SubString {
                                                            String = html
                                                        });
                                                        break;
                                                    }
                                                    if (*contentStart == '$')
                                                    {
                                                        appendAtNode(new SubString {
                                                            String = html, Start = (int)(start - htmlFixed), Length = 1
                                                        });
                                                        ++contentStart;
                                                    }
                                                    else
                                                    {
                                                        if (*contentStart == '@' || *contentStart == '*')
                                                        {
                                                            if (++contentStart == tagStart)
                                                            {
                                                                appendAtNode(new SubString {
                                                                    String = html, Start = (int)(start - htmlFixed), Length = 1
                                                                });
                                                                ++start;
                                                                break;
                                                            }
                                                        }
                                                        while (*contentStart < atMapSize && atFixedMap.Get(*contentStart) != 0)
                                                        {
                                                            ++contentStart;
                                                        }
                                                        if (*contentStart == '#' && (*(contentStart + 1) < atMapSize && atFixedMap.Get(*(contentStart + 1)) != 0))
                                                        {
                                                            for (contentStart += 2; *contentStart < atMapSize && atFixedMap.Get(*contentStart) != 0; ++contentStart)
                                                            {
                                                                ;
                                                            }
                                                        }
                                                        appendAtNode(new SubString {
                                                            String = html, Start = (int)(start - htmlFixed), Length = (int)(contentStart - start)
                                                        });
                                                        if (*contentStart == '$')
                                                        {
                                                            ++contentStart;
                                                        }
                                                    }
                                                    start = contentStart;
                                                }
                                                else
                                                {
                                                    contentStart += 2;
                                                }
                                            }while (contentStart != tagStart);
                                            *tagStart = '<';
                                            if (start != tagStart)
                                            {
                                                appendHtml(new SubString {
                                                    String = html, Start = (int)(start - htmlFixed), Length = (int)(tagStart - start)
                                                });
                                            }
                                        }
                                        #endregion
                                        appendNode(tagIndex, tag);
                                        start = current + 3;
                                    }
                                }
                                current += 3;
                            }
                        }while (current < end);
                        #region 最后=@取值解析
                        if (current <= end)
                        {
                            current = start;
                            *end = '@';
                            do
                            {
                                while (*current != '@')
                                {
                                    ++current;
                                }
                                if (current == end)
                                {
                                    break;
                                }
                                if (*--current == '=')
                                {
                                    if (start != current)
                                    {
                                        appendHtml(new SubString {
                                            String = html, Start = (int)(start - htmlFixed), Length = (int)(current - start)
                                        });
                                    }
                                    start = (current += 2);
                                    if (current == end)
                                    {
                                        appendAtNode(new SubString {
                                            String = html
                                        });
                                        break;
                                    }
                                    if (*current == '@' || *current == '*')
                                    {
                                        if (++current == end)
                                        {
                                            appendAtNode(new SubString {
                                                String = html, Start = (int)(start - htmlFixed), Length = 1
                                            });
                                            ++start;
                                            break;
                                        }
                                    }
                                    while (*current < atMapSize && atFixedMap.Get(*current) != 0)
                                    {
                                        ++current;
                                    }
                                    if (*current == '#' && (*(current + 1) < atMapSize && atFixedMap.Get(*(current + 1)) != 0))
                                    {
                                        for (current += 2; *current < atMapSize && atFixedMap.Get(*current) != 0; ++current)
                                        {
                                            ;
                                        }
                                    }
                                    appendAtNode(new SubString {
                                        String = html, Start = (int)(start - htmlFixed), Length = (int)(current - start)
                                    });
                                    start = current;
                                }
                                else
                                {
                                    current += 2;
                                }
                            }while (current != end);
                            *end = endChar;
                            appendHtml(new SubString {
                                String = html, Start = (int)(start - htmlFixed), Length = (int)(end - start) + 1
                            });
                        }
                        #endregion
                        *end = endChar;
                    }
                }
                else
                {
                    appendHtml(html);
                }
                onCreated();
            }
        }
Exemple #2
0
 internal unsafe bool IsCommand(int index)
 {
     return(commands.Map == null || commands.Get(index) != 0);
 }
Exemple #3
0
 internal unsafe bool IsCommand(int index)
 {
     return(commands.Map == null || (commands.Get(index) != 0 && commandData.Data != null));
 }
Exemple #4
0
        /// <summary>
        /// URL编码
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static unsafe string Encode(string value)
        {
            if (!string.IsNullOrEmpty(value))
            {
                MemoryMap map = urlMap;
                fixed(char *valueFixed = value)
                {
                    char *start = valueFixed, end = valueFixed + value.Length;
                    int   length = 0, isSpace = 0;

                    do
                    {
                        if (*((byte *)start + 1) == 0)
                        {
                            if (map.Get(*(byte *)start) == 0)
                            {
                                if (*start == ' ')
                                {
                                    isSpace = 1;
                                }
                                else
                                {
                                    length += 2;
                                }
                            }
                        }
                        else
                        {
                            length += 5;
                        }
                    }while (++start != end);
                    if ((length | isSpace) != 0)
                    {
                        string url = AutoCSer.Extensions.StringExtension.FastAllocateString(value.Length + length);
                        fixed(char *urlFixed = url)
                        {
                            char *write = urlFixed;

                            start = valueFixed;
                            do
                            {
                                if (*((byte *)start + 1) == 0)
                                {
                                    if (map.Get(*(byte *)start) != 0)
                                    {
                                        *write++ = *start;
                                    }
                                    else if (*start == ' ')
                                    {
                                        *write++ = '+';
                                    }
                                    else
                                    {
                                        *   write = '%';
                                        int code  = *((byte *)start) >> 4;
                                        *(write + 1) = (char)(code + (code < 10 ? '0' : ('0' + 'A' - '9' - 1)));
                                        code         = *((byte *)start) & 0xf;
                                        *(write + 2) = (char)(code + (code < 10 ? '0' : ('0' + 'A' - '9' - 1)));
                                        write       += 3;
                                    }
                                }
                                else
                                {
                                    int code = *((byte *)start + 1) >> 4;
                                    *(int *)write = '%' + ('u' << 16);
                                    *(write + 2)  = (char)(code + (code < 10 ? '0' : ('0' + 'A' - '9' - 1)));
                                    code          = *((byte *)start + 1) & 0xf;
                                    *(write + 3)  = (char)(code + (code < 10 ? '0' : ('0' + 'A' - '9' - 1)));
                                    code          = *((byte *)start) >> 4;
                                    *(write + 4)  = (char)(code + (code < 10 ? '0' : ('0' + 'A' - '9' - 1)));
                                    code          = *((byte *)start) & 0xf;
                                    *(write + 5)  = (char)(code + (code < 10 ? '0' : ('0' + 'A' - '9' - 1)));
                                    write        += 6;
                                }
                            }while (++start != end);
                        }

                        return(url);
                    }
                }
            }
            return(value);
        }