Esempio n. 1
0
        private static int FindSection(string config, string section)
        {
            TextPtr ptr = new TextPtr(config);

            if (!MatchesSection(ref ptr, section))
            {
                while (!ptr.IsOutOfBounds())
                {
                    ptr = TextPtr.op_Increment(ptr.Find("\n"));
                    if (ptr.Char == '[')
                    {
                        if (MatchesSection(ref ptr, section))
                        {
                            return(ptr.Index);
                        }
                    }
                    else if (ptr.StartsWith("---"))
                    {
                        ptr = (ptr + 3).SkipWhitespace(false);
                        if (ptr.IsEndOfLine())
                        {
                            break;
                        }
                    }
                }
            }
            else
            {
                return(ptr.Index);
            }
            return(-1);
        }
Esempio n. 2
0
 private void Realize(ref MyIniKey key, ref StringSegment value)
 {
     if (!value.IsCached)
     {
         string  text = value.Text;
         TextPtr ptr  = new TextPtr(text, value.Start);
         if ((value.Length > 0) && ptr.IsNewLine())
         {
             StringBuilder tmpValueBuilder = this.TmpValueBuilder;
             try
             {
                 ptr = TextPtr.op_Increment(ptr.FindEndOfLine(true));
                 int count = (value.Start + value.Length) - ptr.Index;
                 tmpValueBuilder.Append(text, ptr.Index, count);
                 tmpValueBuilder.Replace("\n|", "\n");
                 this.m_items[key] = value = new StringSegment(tmpValueBuilder.ToString());
             }
             finally
             {
                 tmpValueBuilder.Clear();
             }
         }
         else
         {
             this.m_items[key] = value = new StringSegment(value.ToString());
         }
     }
 }
Esempio n. 3
0
        private StringSegment ParseQuoted(ref TextPtr ptr)
        {
            TextPtr ptr3;
            TextPtr ptr4;
            TextPtr ptr2 = ptr;
            bool    flag = ptr2.Char == '"';

            if (flag)
            {
                ptr2 = TextPtr.op_Increment(ptr2);
            }
            for (ptr3 = ptr2; !ptr3.IsOutOfBounds(); ptr3 = TextPtr.op_Increment(ptr3))
            {
                if (ptr3.Char == '"')
                {
                    flag = !flag;
                }
                if (!flag && char.IsWhiteSpace(ptr3.Char))
                {
                    ptr  = ptr3;
                    ptr4 = ptr3 - 1;
                    if (ptr4.Char == '"')
                    {
                        ptr3 = ptr4;
                    }
                    return(new StringSegment(ptr2.Content, ptr2.Index, ptr3.Index - ptr2.Index));
                }
            }
            ptr3 = new TextPtr(ptr.Content, ptr.Content.Length);
            ptr  = ptr3;
            ptr4 = ptr3 - 1;
            if (ptr4.Char == '"')
            {
                ptr3 = ptr4;
            }
            return(new StringSegment(ptr2.Content, ptr2.Index, ptr3.Index - ptr2.Index));
        }
Esempio n. 4
0
        private bool TryParseSection(ref TextPtr ptr, ref MyIniParseResult result, bool parseEndContent)
        {
            StringSegment segment;
            TextPtr       ptr2 = ptr;

            this.ReadPrefix(ref ptr2, out segment);
            this.m_endComment = segment;
            if (ptr2.Char != '[')
            {
                if (result.IsDefined)
                {
                    result = new MyIniParseResult(ptr, "Expected [section] definition");
                }
                return(false);
            }
            TextPtr ptr3 = ptr2.FindEndOfLine(false);

            while ((ptr3.Index > ptr2.Index) && (ptr3.Char != ']'))
            {
                ptr3 = TextPtr.op_Decrement(ptr3);
            }
            if (ptr3.Char != ']')
            {
                if (result.IsDefined)
                {
                    result = new MyIniParseResult(ptr, "Expected [section] definition");
                }
                return(false);
            }
            ptr2 = TextPtr.op_Increment(ptr2);
            StringSegment segment2 = new StringSegment(ptr2.Content, ptr2.Index, ptr3.Index - ptr2.Index);
            string        str      = MyIniKey.ValidateSection(ref segment2);

            if (str == null)
            {
                ptr2 = (ptr3 + 1).SkipWhitespace(false);
                if (!ptr2.IsEndOfLine())
                {
                    if (result.IsDefined)
                    {
                        result = new MyIniParseResult(ptr2, "Expected newline");
                    }
                    return(false);
                }
                ptr2 = ptr2.FindEndOfLine(true);
                this.AddSection(ref segment2);
                if (!segment.IsEmpty)
                {
                    this.m_sectionComments[segment2] = segment;
                    this.m_endComment = new StringSegment();
                }
                while (this.TryParseItem(ref segment2, ref ptr2, ref result, parseEndContent))
                {
                }
                if (result.IsDefined && !result.Success)
                {
                    return(false);
                }
                ptr = ptr2;
                return(true);
            }
            if (result.IsDefined)
            {
                result = new MyIniParseResult(ptr2, $"Section {str}");
            }
            return(false);
        }
Esempio n. 5
0
 private void RealizeComment(ref StringSegment comment)
 {
     if (!comment.IsCached)
     {
         string  text = comment.Text;
         TextPtr ptr  = new TextPtr(text, comment.Start);
         if (comment.Length > 0)
         {
             StringBuilder tmpValueBuilder = this.TmpValueBuilder;
             try
             {
                 TextPtr ptr2 = ptr + comment.Length;
                 for (bool flag = false; ptr < ptr2; flag = true)
                 {
                     if (flag)
                     {
                         tmpValueBuilder.Append('\n');
                     }
                     if (ptr.Char == ';')
                     {
                         ptr = TextPtr.op_Increment(ptr);
                         TextPtr ptr3  = ptr.FindEndOfLine(false);
                         int     count = ptr3.Index - ptr.Index;
                         tmpValueBuilder.Append(ptr.Content, ptr.Index, count);
                         ptr = ptr3.SkipWhitespace(false);
                         if (ptr.IsEndOfLine())
                         {
                             if (ptr.Char == '\r')
                             {
                                 ptr += 2;
                             }
                             else
                             {
                                 ptr = TextPtr.op_Increment(ptr);
                             }
                         }
                     }
                     else
                     {
                         ptr = ptr.SkipWhitespace(false);
                         if (!ptr.IsEndOfLine())
                         {
                             break;
                         }
                         if (ptr.Char == '\r')
                         {
                             ptr += 2;
                         }
                         else
                         {
                             ptr = TextPtr.op_Increment(ptr);
                         }
                     }
                 }
                 comment = new StringSegment(tmpValueBuilder.ToString());
             }
             finally
             {
                 tmpValueBuilder.Clear();
             }
         }
     }
 }