internal static IniSection FromStream(ref string line, StreamReader stream) { if (line != null) { line = line.Trim(); IniSection section = null; // return section being comment if (line.StartsWith(";")) { section = new IniSection(line.Substring(1)); section._isComment = true; // proceed to the next line line = stream.ReadLine(); return(section); } if (line.StartsWith("[") && line.EndsWith("]")) { section = new IniSection(line.Substring(1, line.Length - 2)); } // proceed to the next line line = stream.ReadLine(); if (line != null) { line = line.Trim(); } while (line != null && !(line.StartsWith("[") && line.EndsWith("]"))) { IniKey key = IniKey.FromStream(ref line, stream); if (key != null) { section._keys.Add(key); key.OnChange += new EventHandler(section._keys_OnChange); } // Trim returned line if (line != null) { line = line.Trim(); } } return(section); } return(null); }
internal static IniKey FromStream(ref string line, StreamReader stream) { if (line != null) { IniKey key = null; if (line.Trim().Length == 0) { // proceed to the next line line = stream.ReadLine(); return null; } if (line.StartsWith(";")) { key = new IniKey(); key.Value = line.Substring(1); key._isComment = true; // proceed to the next line line = stream.ReadLine(); return key; } int pos = line.IndexOf('='); if (pos > 0) { key = new IniKey(); key.Name = line.Substring(0, pos); string rest = line.Substring(pos + 1); if (rest.Trim() == "<<--") { key._multiline = true; List<string> values = new List<string>(); // proceed to the next line line = stream.ReadLine(); while (line != null && line.Trim() != "--") { values.Add(line); // proceed to the next line line = stream.ReadLine(); } key._values = values.ToArray(); if (line != null) line = stream.ReadLine(); return key; } else { key._value = rest; // proceed to the next line line = stream.ReadLine(); return key; } } else { // This is key without value... key = new IniKey(); key.Name = line.Trim(); // proceed to the next line line = stream.ReadLine(); return key; } } return null; }
internal static IniKey FromStream(ref string line, StreamReader stream) { if (line != null) { IniKey key = null; if (line.Trim().Length == 0) { // proceed to the next line line = stream.ReadLine(); return(null); } if (line.StartsWith(";")) { key = new IniKey(); key.Value = line.Substring(1); key._isComment = true; // proceed to the next line line = stream.ReadLine(); return(key); } int pos = line.IndexOf('='); if (pos > 0) { key = new IniKey(); key.Name = line.Substring(0, pos); string rest = line.Substring(pos + 1); if (rest.Trim() == "<<--") { key._multiline = true; List <string> values = new List <string>(); // proceed to the next line line = stream.ReadLine(); while (line != null && line.Trim() != "--") { values.Add(line); // proceed to the next line line = stream.ReadLine(); } key._values = values.ToArray(); if (line != null) { line = stream.ReadLine(); } return(key); } else { key._value = rest; // proceed to the next line line = stream.ReadLine(); return(key); } } else { // This is key without value... key = new IniKey(); key.Name = line.Trim(); // proceed to the next line line = stream.ReadLine(); return(key); } } return(null); }
public void SetKeyValue(string sectionName, string keyName, string value) { // Get / create section IniSection section = this[sectionName]; if (section == null) { section = new IniSection(sectionName); this.Sections.Add(section); } // Get / create Key IniKey key = section[keyName]; if (key == null) { key = new IniKey(); key.Name = keyName; section.Keys.Add(key); key.OnChange += new EventHandler(_sections_OnChange); } // Set new Value key.Value = value; SetChanged(); }
public void SetKeyValue(string sectionName, string keyName, int lineIndex, string value) { // Get / create section IniSection section = this[sectionName]; if (section == null) { section = new IniSection(sectionName); this.Sections.Add(section); } // Get / create Key IniKey key = section[keyName]; if (key == null) { key = new IniKey(); key.Name = keyName; key.OnChange += new EventHandler(_sections_OnChange); section.Keys.Add(key); } // Calculate new values array int arrayDim = lineIndex + 1; if (key.Multiline) { arrayDim = Math.Max(arrayDim, key.Values.Length); } else { if (arrayDim < 1) arrayDim = 1; } string[] array = new string[arrayDim]; // Copy old values if (key.Multiline) { for (int i = 0; i < key.Values.Length; i++) array[i] = key.Values[i]; } else array[0] = key.Value; // insert new value array[lineIndex] = value; // Keep new values array in Key key.Values = array; SetChanged(); }
public void SetKeyValuesDimension(string sectionName, string keyName, int newDimension) { // Get / create section IniSection section = this[sectionName]; if (section == null) { section = new IniSection(sectionName); this.Sections.Add(section); } // Get / create Key IniKey key = section[keyName]; if (key == null) { key = new IniKey(); key.Name = keyName; key.OnChange += new EventHandler(_sections_OnChange); section.Keys.Add(key); } // Setting dimension 0 - causes to not use multiple values if (newDimension < 1) { key.Values = null; key.Value = null; return; } // Create new array with values string[] array = new string[newDimension]; // Copy old values if (key.Multiline) { for (int i = 0; i < Math.Min(key.Values.Length, newDimension); i++) array[i] = key.Values[i]; } else array[0] = key.Value; // Keep new values array in Key key.Values = array; SetChanged(); }