internal IniRow(RowType type, string arg0, string arg1 = null, StringUtil.EscapeHint hint = StringUtil.EscapeHint.None) { this.rowType = type; this.arg0 = arg0; this.arg1 = arg1; this.hint = hint; }
public bool ParseLine(TextReader reader) { var line = reader.ReadLine(); if (line == null) { return(false); } Match m; m = reSection.Match(line); if (m.Success) { var sectionName = m.Groups[1].Value; rows.Add(IniRow.Section(sectionName)); return(true); } m = reComment.Match(line); if (m.Success) { var commentText = m.Groups[1].Value; rows.Add(IniRow.Comment(commentText)); return(true); } StringUtil.EscapeHint hint = StringUtil.EscapeHint.Escaped; if (line.Contains("=")) { var args = line.Split('='); string key = args[0].Trim(); string value = args[1].Trim(); if (value.StartsWith("\"\"\"")) { if (!(value.Length > 3 && value.EndsWith("\"\"\""))) { hint = StringUtil.EscapeHint.TripleDoubleQuoted; value += ReadToTerminator("\"\"\"", reader); } } else if (value.StartsWith("'''")) { if (!(value.Length > 3 && value.EndsWith("'''"))) { hint = StringUtil.EscapeHint.TripleQuoted; value += ReadToTerminator("'''", reader); } } else if (value.StartsWith("\"")) { hint = StringUtil.EscapeHint.DoubleQuoted; } else if (value.StartsWith("'")) { hint = StringUtil.EscapeHint.Quoted; } else if (value.EndsWith("\\")) { value = value.TrimEnd("\\") + "\n" + ReadForContinuation("\\", reader); } rows.Add(IniRow.KeyValue(key, value.Dequote(), hint)); return(true); } rows.Add(IniRow.Invalid(line)); return(true); }
internal static IniRow KeyValue(string key, string value, StringUtil.EscapeHint escapeHint) { return(new IniRow(RowType.KeyValue, key, value, escapeHint)); }