public IniFileSectionStart(string content) : base(content) { formatting = ExtractFormat(content); content = content.TrimStart(); if (IniFileSettings.AllowInlineComments) { IniFileSettings.indexOfAnyResult indexOfAnyResult = IniFileSettings.indexOfAny(content, IniFileSettings.CommentChars); if (indexOfAnyResult.index > content.IndexOf(IniFileSettings.SectionCloseBracket)) { inlineComment = content.Substring(indexOfAnyResult.index + indexOfAnyResult.any.Length); inlineCommentChar = indexOfAnyResult.any; content = content.Substring(0, indexOfAnyResult.index); } } if (IniFileSettings.AllowTextOnTheRight) { int num = content.LastIndexOf(IniFileSettings.SectionCloseBracket); if (num != content.Length - 1) { textOnTheRight = content.Substring(num + 1); content = content.Substring(0, num); } } sectionName = content.Substring(IniFileSettings.SectionOpenBracket.Length, content.Length - IniFileSettings.SectionCloseBracket.Length - IniFileSettings.SectionOpenBracket.Length).Trim(); base.Content = content; Format(); }
public string ExtractFormat(string content) { feState feState = feState.BeforeEvery; string str = ""; StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < content.Length; i++) { char c = content[i]; if (char.IsLetterOrDigit(c)) { switch (feState) { case feState.BeforeEvery: stringBuilder.Append('?'); feState = feState.AfterKey; break; case feState.BeforeVal: stringBuilder.Append('$'); feState = feState.AfterVal; break; } } else if (feState == feState.AfterKey && content.Length - i >= IniFileSettings.EqualsString.Length && content.Substring(i, IniFileSettings.EqualsString.Length) == IniFileSettings.EqualsString) { stringBuilder.Append(str); feState = feState.BeforeVal; stringBuilder.Append('='); } else if (IniFileSettings.ofAny(i, content, IniFileSettings.CommentChars) != null) { stringBuilder.Append(str); stringBuilder.Append(';'); } else if (char.IsWhiteSpace(c)) { string str2 = (c != '\t' || IniFileSettings.TabReplacement == null) ? c.ToString() : IniFileSettings.TabReplacement; if (feState == feState.AfterKey || feState == feState.AfterVal) { str += str2; continue; } stringBuilder.Append(str2); } str = ""; } if (feState == feState.BeforeVal) { stringBuilder.Append('$'); feState = feState.AfterVal; } string text = stringBuilder.ToString(); if (text.IndexOf(';') == -1) { text += " ;"; } return(text); }
/// <summary>Initializes a new instance IniFileSectionStart</summary> /// <param name="content">Actual content of a line in an INI file. Initializer assumes that it is valid.</param> public IniFileSectionStart(string content) : base(content) { //content = Content; formatting = ExtractFormat(content); content = content.TrimStart(); if (IniFileSettings.AllowInlineComments) { IniFileSettings.indexOfAnyResult result = IniFileSettings.indexOfAny(content, IniFileSettings.CommentChars); if (result.index > content.IndexOf(IniFileSettings.SectionCloseBracket)) { inlineComment = content.Substring(result.index + result.any.Length); inlineCommentChar = result.any; content = content.Substring(0, result.index); } } if (IniFileSettings.AllowTextOnTheRight) { int closeBracketPos = content.LastIndexOf(IniFileSettings.SectionCloseBracket); if (closeBracketPos != content.Length - 1) { textOnTheRight = content.Substring(closeBracketPos + 1); content = content.Substring(0, closeBracketPos); } } sectionName = content.Substring(IniFileSettings.SectionOpenBracket.Length, content.Length - IniFileSettings.SectionCloseBracket.Length - IniFileSettings.SectionOpenBracket.Length).Trim(); Content = content; Format(); }
/// <summary>Initializes a new instance IniFileValue.</summary> /// <param name="content">Actual content of a line in an INI file. Initializer assumes that it is valid.</param> public IniFileValue(string content) : base(content) { string[] split = Content.Split(new string[] { IniFileSettings.EqualsString }, StringSplitOptions.None); formatting = ExtractFormat(content); string split0 = split[0].Trim(); string split1 = split.Length >= 1 ? split[1].Trim() : ""; if (split0.Length > 0) { if (IniFileSettings.AllowInlineComments) { IniFileSettings.indexOfAnyResult result = IniFileSettings.indexOfAny(split1, IniFileSettings.CommentChars); if (result.index != -1) { inlineComment = split1.Substring(result.index + result.any.Length); split1 = split1.Substring(0, result.index).TrimEnd(); inlineCommentChar = result.any; } } if (IniFileSettings.QuoteChar != null && split1.Length >= 2) { char quoteChar = (char)IniFileSettings.QuoteChar; if (split1[0] == quoteChar) { int lastQuotePos; if (IniFileSettings.AllowTextOnTheRight) { lastQuotePos = split1.LastIndexOf(quoteChar); if (lastQuotePos != split1.Length - 1) { textOnTheRight = split1.Substring(lastQuotePos + 1); } } else { lastQuotePos = split1.Length - 1; } if (lastQuotePos > 0) { if (split1.Length == 2) { split1 = ""; } else { split1 = split1.Substring(1, lastQuotePos - 1); } } } } key = split0; value = split1; } Format(); }
public static string ExtractFormat(string content) { bool flag = false; bool flag2 = false; bool flag3 = true; string text = ""; StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < content.Length; i++) { char c = content[i]; if (char.IsLetterOrDigit(c) && flag) { flag2 = true; flag = false; stringBuilder.Append('$'); } else if (flag2 && char.IsLetterOrDigit(c)) { text = ""; } else if (content.Length - i >= IniFileSettings.SectionOpenBracket.Length && content.Substring(i, IniFileSettings.SectionOpenBracket.Length) == IniFileSettings.SectionOpenBracket && flag3) { flag = true; flag3 = false; stringBuilder.Append('['); } else if (content.Length - i >= IniFileSettings.SectionCloseBracket.Length && content.Substring(i, IniFileSettings.SectionOpenBracket.Length) == IniFileSettings.SectionCloseBracket && flag2) { stringBuilder.Append(text); flag2 = false; stringBuilder.Append(IniFileSettings.SectionCloseBracket); } else if (IniFileSettings.ofAny(i, content, IniFileSettings.CommentChars) != null) { stringBuilder.Append(';'); } else if (char.IsWhiteSpace(c)) { if (flag2) { text += c; } else { stringBuilder.Append(c); } } } string text2 = stringBuilder.ToString(); if (text2.IndexOf(';') == -1) { text2 += " ;"; } return(text2); }
public IniFileValue(string content) : base(content) { string[] array = base.Content.Split(new string[1] { IniFileSettings.EqualsString }, StringSplitOptions.None); formatting = ExtractFormat(content); string text = array[0].Trim(); string text2 = (array.Length >= 1) ? array[1].Trim() : ""; if (text.Length > 0) { if (IniFileSettings.AllowInlineComments) { IniFileSettings.indexOfAnyResult indexOfAnyResult = IniFileSettings.indexOfAny(text2, IniFileSettings.CommentChars); if (indexOfAnyResult.index != -1) { inlineComment = text2.Substring(indexOfAnyResult.index + indexOfAnyResult.any.Length); text2 = text2.Substring(0, indexOfAnyResult.index).TrimEnd(); inlineCommentChar = indexOfAnyResult.any; } } if (((int?)IniFileSettings.QuoteChar).HasValue && text2.Length >= 2) { char c = IniFileSettings.QuoteChar.Value; if (text2[0] == c) { int num; if (IniFileSettings.AllowTextOnTheRight) { num = text2.LastIndexOf(c); if (num != text2.Length - 1) { textOnTheRight = text2.Substring(num + 1); } } else { num = text2.Length - 1; } if (num > 0) { text2 = ((text2.Length != 2) ? text2.Substring(1, num - 1) : ""); } } } key = text; value = text2; } Format(); }
/// <summary>Creates a formatting string basing on an actual content of a line.</summary> public static string ExtractFormat(string content) { bool beforeS = false; bool afterS = false; bool beforeEvery = true; char currC; string comChar; string insideWhiteChars = ""; StringBuilder form = new StringBuilder(); for (int i = 0; i < content.Length; i++) { currC = content[i]; if (char.IsLetterOrDigit(currC) && beforeS) { afterS = true; beforeS = false; form.Append('$'); } else if (afterS && char.IsLetterOrDigit(currC)) { insideWhiteChars = ""; } else if (content.Length - i >= IniFileSettings.SectionOpenBracket.Length && content.Substring(i, IniFileSettings.SectionOpenBracket.Length) == IniFileSettings.SectionOpenBracket && beforeEvery) { beforeS = true; beforeEvery = false; form.Append('['); } else if (content.Length - i >= IniFileSettings.SectionCloseBracket.Length && content.Substring(i, IniFileSettings.SectionOpenBracket.Length) == IniFileSettings.SectionCloseBracket && afterS) { form.Append(insideWhiteChars); afterS = false; form.Append(IniFileSettings.SectionCloseBracket); } else if ((comChar = IniFileSettings.ofAny(i, content, IniFileSettings.CommentChars)) != null) { form.Append(';'); } else if (char.IsWhiteSpace(currC)) { if (afterS) { insideWhiteChars += currC; } else { form.Append(currC); } } } string ret = form.ToString(); if (ret.IndexOf(';') == -1) { ret += " ;"; } return(ret); }
public IniFileCommentary(string content) : base(content) { if (IniFileSettings.CommentChars.Length == 0) { throw new NotSupportedException("Comments are disabled. Set the IniFileSettings.CommentChars property to turn them on."); } commentChar = IniFileSettings.startsWith(base.Content, IniFileSettings.CommentChars); if (base.Content.Length > commentChar.Length) { comment = base.Content.Substring(commentChar.Length); } else { comment = ""; } }
public static bool IsLineValid(string testString) { return(IniFileSettings.startsWith(testString.TrimStart(), IniFileSettings.CommentChars) != null); }
/// <summary>Creates a formatting string basing on an actual content of a line.</summary> public string ExtractFormat(string content) { //bool afterKey = false; bool beforeVal = false; bool beforeEvery = true; bool afterVal = false; //return IniFileSettings.DefaultValueFormatting; feState pos = feState.BeforeEvery; char currC; string comChar; string insideWhiteChars = ""; string theWhiteChar;; StringBuilder form = new StringBuilder(); for (int i = 0; i < content.Length; i++) { currC = content[i]; if (char.IsLetterOrDigit(currC)) { if (pos == feState.BeforeEvery) { form.Append('?'); pos = feState.AfterKey; //afterKey = true; beforeEvery = false; ; } else if (pos == feState.BeforeVal) { form.Append('$'); pos = feState.AfterVal; } } else if (pos == feState.AfterKey && content.Length - i >= IniFileSettings.EqualsString.Length && content.Substring(i, IniFileSettings.EqualsString.Length) == IniFileSettings.EqualsString) { form.Append(insideWhiteChars); pos = feState.BeforeVal; //afterKey = false; beforeVal = true; form.Append('='); } else if ((comChar = IniFileSettings.ofAny(i, content, IniFileSettings.CommentChars)) != null) { form.Append(insideWhiteChars); form.Append(';'); } else if (char.IsWhiteSpace(currC)) { if (currC == '\t' && IniFileSettings.TabReplacement != null) { theWhiteChar = IniFileSettings.TabReplacement; } else { theWhiteChar = currC.ToString(); } if (pos == feState.AfterKey || pos == feState.AfterVal) { insideWhiteChars += theWhiteChar; continue; } else { form.Append(theWhiteChar); } } insideWhiteChars = ""; } if (pos == feState.BeforeVal) { form.Append('$'); pos = feState.AfterVal; } string ret = form.ToString(); if (ret.IndexOf(';') == -1) { ret += " ;"; } return(ret); }