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); }
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); }
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(); } } } }