Beispiel #1
0
        internal void Exchange(ref LeftArray <T> value)
        {
            LeftArray <T> temp = value;

            value = this;
            this  = temp;
        }
        ///// <summary>
        ///// 字符替换
        ///// </summary>
        ///// <param name="value">原字符</param>
        ///// <param name="replaceChar">替换后的字符</param>
        //public void Replace(char value, char replaceChar)
        //{
        //    if (Length != 0)
        //    {
        //        fixed (char* valueFixed = String)
        //        {
        //            char* start = valueFixed + StartIndex, end = start + Length;
        //            if (*--end == value)
        //            {
        //                do
        //                {
        //                    while (*start != value) ++start;
        //                    *start = replaceChar;
        //                    if (start == end) return;
        //                    ++start;
        //                }
        //                while (true);
        //            }
        //            while (start != end)
        //            {
        //                if (*start == value) *start = replaceChar;
        //                ++start;
        //            }
        //        }
        //    }
        //}
        /// <summary>
        /// 分割字符串
        /// </summary>
        /// <param name="split">分割符</param>
        /// <returns>字符子串集合</returns>
        public LeftArray <SubString> Split(char split)
        {
            LeftArray <SubString> values = default(LeftArray <SubString>);

            if (String != null)
            {
                fixed(char *valueFixed = String)
                {
                    char *last = valueFixed + Start, end = last + Length;

                    for (char *start = last; start != end;)
                    {
                        if (*start == split)
                        {
                            values.PrepLength(1);
                            values.Array[values.Length++].Set(String, (int)(last - valueFixed), (int)(start - last));
                            last = ++start;
                        }
                        else
                        {
                            ++start;
                        }
                    }
                    values.PrepLength(1);
                    values.Array[values.Length++].Set(String, (int)(last - valueFixed), (int)(end - last));
                }
            }
            return(values);
        }
Beispiel #3
0
 /// <summary>
 /// 数组枚举器
 /// </summary>
 /// <param name="value">数组子串</param>
 public Array(LeftArray <valueType> value)
 {
     array        = value.Array;
     startIndex   = 0;
     endIndex     = value.Length;
     currentIndex = startIndex - 1;
 }
Beispiel #4
0
 /// <summary>
 /// 添加数据集合
 /// </summary>
 /// <param name="values">数据集合</param>
 public void Add(ref LeftArray <valueType> values)
 {
     if (values.Length != 0)
     {
         addToLength(Length + values.Length);
         System.Array.Copy(values.Array, 0, Array, Length, values.Length);
         Length += values.Length;
     }
 }
Beispiel #5
0
 /// <summary>
 /// 添加数据集合
 /// </summary>
 /// <param name="array">数据集合</param>
 public void Add(ref LeftArray <T> array)
 {
     if (array.Length != 0)
     {
         addToLength(Length + array.Length);
         array.Array.AsSpan(0, array.Length).CopyTo(Array.AsSpan(Length, array.Length));
         Length += array.Length;
     }
 }
Beispiel #6
0
 public void CallSerialize(LeftArray <byte> value)
 {
     if (value.Length == 0)
     {
         Stream.Write(0);
     }
     else
     {
         Serialize(Stream, ref value);
     }
 }
Beispiel #7
0
 /// <summary>
 /// 数组子串
 /// </summary>
 /// <param name="array">数组</param>
 internal SubArray(ref LeftArray <valueType> array)
 {
     if (array.Array == null)
     {
         Array = null;
         Start = Length = 0;
     }
     else
     {
         Array  = array.Array;
         Start  = 0;
         Length = array.Length;
     }
 }
Beispiel #8
0
        /// <summary>
        /// hosts 文件读写
        /// </summary>
        /// <param name="fileName">hosts 文件全名称,默认为 Environment.SpecialFolder.System\drivers\etc\hosts</param>
        /// <param name="domianCount">域名数量默认为 1</param>
        /// <param name="encoding">文件编码,默认为 Encoding.Default</param>
        public HostsFile(string fileName = null, int domianCount = 1, Encoding encoding = null)
        {
            this.fileName    = fileName ?? (Environment.GetFolderPath(Environment.SpecialFolder.System) + @"\drivers\etc\hosts");
            this.domianCount = Math.Min(Math.Max(domianCount, 6), 1);
            this.encoding    = encoding ?? Encoding.Default;
            string[] texts = File.ReadAllLines(this.fileName, this.encoding);
            lines = new LeftArray <FileLine>(texts.Length);
            int lineIndex = 0;

            foreach (string text in texts)
            {
                lines.Add(new FileLine(text, this, lineIndex++));
            }
        }
        static ReusableDictionary()
        {
            LeftArray <ushort> primes = new LeftArray <ushort>(4791);

            for (ushort mod = 3; mod != 3 * 3; mod += 2)
            {
                primes.Add(mod);
            }
            for (ushort max = (ushort)(int)Math.Sqrt(int.MaxValue), mod = 11; mod <= max; mod += 2)
            {
                if (isPrime(mod))
                {
                    primes.Add(mod);
                }
            }
            ReusableDictionary.primes = primes.ToArray();
        }
Beispiel #10
0
 public void Append(ref LeftArray <string> values)
 {
     array.Add(ref values);
 }
Beispiel #11
0
 /// <summary>
 /// 单向动态数据
 /// </summary>
 /// <param name="array">数据数组</param>
 internal ListArray(ref LeftArray <T> array)
 {
     Array = array;
 }
Beispiel #12
0
 /// <summary>
 /// 单向动态数据
 /// </summary>
 /// <param name="array">数据数组</param>
 internal ListArray(T[] array)
 {
     Array = new LeftArray <T>(array);
 }
Beispiel #13
0
 /// <summary>
 /// 单向动态数组
 /// </summary>
 /// <param name="capacity">容器大小</param>
 public ListArray(int capacity = 0)
 {
     Array = new LeftArray <T>(capacity);
 }
Beispiel #14
0
 /// <summary>
 /// 数组子串
 /// </summary>
 /// <param name="array">数组</param>
 internal SubArray(ref LeftArray <T> array)
 {
     Array  = array.Array;
     Start  = 0;
     Length = array.Length;
 }
Beispiel #15
0
 public void CallDeSerialize(ref Node value)
 {
     space();
     if (State != DeSerializeState.Success)
     {
         return;
     }
     if (*current == '<')
     {
         char code = *(current + 1);
         if (((bits[code & 0xff] & targetStartCheckBit) | (code & 0xff00)) == 0)
         {
             if (code == '/')
             {
                 value.SetString(string.Empty);
                 return;
             }
             if (code == '!')
             {
                 searchCData2();
                 if (State == DeSerializeState.Success)
                 {
                     value.SetString(xml, (int)(valueStart - xmlFixed), valueSize);
                 }
                 return;
             }
             State = DeSerializeState.NotFoundTagStart;
             return;
         }
         char *nameStart;
         LeftArray <KeyValue <SubString, Node> > nodes = new LeftArray <KeyValue <SubString, Node> >(0);
         KeyValue <Range, Range>[] attributes;
         int nameSize = 0;
         do
         {
             nameStart = getName(ref nameSize);
             if (State != DeSerializeState.Success)
             {
                 return;
             }
             if (nameStart == null)
             {
                 value.SetNode(ref nodes);
                 return;
             }
             nodes.PrepLength(1);
             nodes.Array[nodes.Length].Key.Set(xml, (int)(nameStart - xmlFixed), nameSize);
             attributes = Config.IsAttribute && this.attributes.Length != 0 ? this.attributes.GetArray() : null;
             if (isTagEnd == 0)
             {
                 CallDeSerialize(ref nodes.Array[nodes.Length].Value);
                 if (State != DeSerializeState.Success || CheckNameEnd(nameStart, nameSize) == 0)
                 {
                     return;
                 }
             }
             if (attributes != null)
             {
                 nodes.Array[nodes.Length].Value.SetAttribute(xml, attributes);
             }
             ++nodes.Length;
         }while (true);
     }
     else
     {
         valueStart = current;
         value.Type = NodeType.String;
         do
         {
             if (*current == '<')
             {
                 value.String.Set(xml, (int)(valueStart - xmlFixed), (int)(endSpace() - valueStart));
                 if (Config.IsTempString && value.Type == NodeType.EncodeString)
                 {
                     value.Type = NodeType.TempString;
                 }
                 return;
             }
             if (*current == '&')
             {
                 value.Type = NodeType.EncodeString;
                 while (*++current != ';')
                 {
                     if (*current == '<')
                     {
                         State = DeSerializeState.DecodeError;
                         return;
                     }
                 }
             }
             ++current;
         }while (true);
     }
 }
Beispiel #16
0
 /// <summary>
 /// 单向动态数据
 /// </summary>
 /// <param name="array"></param>
 internal ListArray(LeftArray <valueType> array)
 {
     Array  = array.Array ?? NullValue <valueType> .Array;
     Length = array.Length;
 }