Exemplo n.º 1
0
        ///// <summary>
        ///// 字符查找
        ///// </summary>
        ///// <param name="start">起始位置,不能为null</param>
        ///// <param name="end">结束位置,不能为null,长度必须大于0</param>
        ///// <param name="value">查找值</param>
        ///// <returns>字符位置,失败为null</returns>
        //internal static char* FindLastNotNull(char* start, char* end, char value)
        //{
        //    if (*start == value)
        //    {
        //        while (*--end != value);
        //        return end;
        //    }
        //    ++start;
        //    while (start != end)
        //    {
        //        if (*--end == value) return end;
        //    }
        //    return null;
        //}
        /// <summary>
        /// 比较字符串(忽略大小写)
        /// </summary>
        /// <param name="left"></param>
        /// <param name="right"></param>
        /// <returns></returns>
        internal static bool EqualCase(this SubString left, ref SubString right)
        {
            if (left.Length == right.Length)
            {
                if (left.Length != 0)
                {
                    if (object.ReferenceEquals(left.String, right.String))
                    {
                        if (left.Start == right.Start)
                            return(true);

                        fixed(char *leftFixed = left.GetFixedBuffer())
                        {
                            return(AutoCSer.Extensions.StringExtension.equalCaseNotNull(leftFixed + left.Start, leftFixed + right.Start, left.Length));
                        }
                    }

                    fixed(char *leftFixed = left.GetFixedBuffer(), rightFixed = right.GetFixedBuffer())
                    {
                        return(AutoCSer.Extensions.StringExtension.equalCaseNotNull(leftFixed + left.Start, rightFixed + right.Start, left.Length));
                    }
                }
                return(right.String == null ? left.String == null : left.String != null);
            }
            return(false);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 判断连接地址是否以 http:// 或者 https:// 或者 // 开头
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        private unsafe static bool isHttpOrDefalut(SubString url)
        {
            if (url.Length > 7 && url[6] == '/')
            {
                fixed(char *urlFixed = url.GetFixedBuffer())
                {
                    char *start = urlFixed + url.Start;

                    if ((*(int *)start | 0x200020) == 'h' + ('t' << 16) && (*(int *)(start + 2) | 0x200020) == 't' + ('p' << 16))
                    {
                        if (*(int *)(start + 4) == ':' + ('/' << 16))
                        {
                            return(true);
                        }
                        else if ((*(int *)(start + 4) | 0x20) == 's' + (':' << 16) && start[7] == '/')
                        {
                            return(true);
                        }
                    }
                }
            }
            if (url.Length > 2)
            {
                return(url[0] == '/' && url[1] == '/');
            }
            return(false);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 格式化样式表
        /// </summary>
        /// <param name="style">样式表</param>
        /// <returns>样式表</returns>
        private static unsafe string formatStyle(SubString style)
        {
            if (style.Length != 0)
            {
                LeftArray <KeyValue <SubString, SubString> > values = new LeftArray <KeyValue <SubString, SubString> >(0);
                LeftArray <SubString> styles     = style.Split(';');
                SubString[]           styleArray = styles.Array;
                for (int index = 0; index != styles.Length; ++index)
                {
                    int valueIndex = styleArray[index].IndexOf(':');
                    if (valueIndex > 0)
                    {
                        SubString name = styleArray[index].GetSub(0, valueIndex);
                        if (SafeStyleAttributeName.Names.Contains(name))
                        {
                            styleArray[index].MoveStart(valueIndex + 1);
                            values.Add(new KeyValue <SubString, SubString>(ref name, ref styleArray[index]));
                        }
                    }
                }
                if (values.Length != 0)
                {
                    int length = (values.Count << 1) - 1;
                    foreach (KeyValue <SubString, SubString> value in values)
                    {
                        length += value.Key.Length + value.Value.Length;
                    }
                    string newStyle = AutoCSer.Extensions.StringExtension.FastAllocateString(length);
                    byte * bits     = Node.Bits.Byte;
                    fixed(char *newStyleFixed = newStyle, styleFixed = style.GetFixedBuffer())
                    {
                        char *write = newStyleFixed;

                        foreach (KeyValue <SubString, SubString> value in values)
                        {
                            if (write != newStyleFixed)
                            {
                                *write++ = ';';
                            }
                            for (char *start = styleFixed + value.Key.Start, end = start + value.Key.Length; start != end; *write++ = *start++)
                            {
                                ;
                            }
                            *write++ = ':';
                            for (char *start = styleFixed + value.Value.Start, end = start + value.Value.Length; start != end; ++start)
                            {
                                *write++ = ((bits[*(byte *)start] & Node.CssFilterBit) | *(((byte *)start) + 1)) == 0 ? ' ' : *start;
                            }
                        }
                    }

                    return(newStyle);
                }
            }
            return(null);
        }
Exemplo n.º 4
0
        public void LeftRightMatchs(ref SubString text, ref LeftArray <KeyValue <int, int> > matchs)
        {
            if (text.Length != 0)
            {
                fixed(char *valueFixed = text.GetFixedBuffer())
                {
                    char *start = valueFixed + text.Start;

                    leftRightMatchs(start, start + text.Length, ref matchs);
                }
            }
        }
Exemplo n.º 5
0
        internal int SearchLower(ref SubString value)
        {
            if (value.Length != 0)
            {
                fixed(char *valueFixed = value.GetFixedBuffer())
                {
                    char *start = valueFixed + value.Start;

                    return(SearchLower(start, start + value.Length));
                }
            }
            return(-1);
        }
Exemplo n.º 6
0
        public void WriteJson(ref SubString value, char nullChar = ' ')
        {
            if (value.Length != 0)
            {
                Write('"');

                fixed(char *valueFixed = value.GetFixedBuffer()) WriteJson(valueFixed + value.Start, value.Length, nullChar);

                Write('"');
            }
            else
            {
                WriteJsonEmptyString();
            }
        }
Exemplo n.º 7
0
 /// <summary>
 /// 获取属性索引位置
 /// </summary>
 /// <param name="nameStart"></param>
 /// <param name="nameSize"></param>
 /// <param name="index"></param>
 /// <returns></returns>
 internal unsafe bool GetAttribute(char *nameStart, int nameSize, ref Range index)
 {
     if (attributes != null)
     {
         foreach (KeyValue <Range, Range> attribute in attributes)
         {
             if (attribute.Key.Length == nameSize)
             {
                 fixed(char *xmlFixed = String.GetFixedBuffer())
                 {
                     if (AutoCSer.Memory.Common.SimpleEqualNotNull((byte *)(xmlFixed + attribute.Key.StartIndex), (byte *)nameStart, nameSize << 1))
                     {
                         index = attribute.Value;
                         return(true);
                     }
                 }
             }
         }
     }
     return(false);
 }