protected virtual void StoreKeyValue() { string key = _reader.ReadToken(":", @"\", false, false, true, true); string val = ""; _reader.ConsumeWhiteSpace(); // If starting with " then possibly multi-line. if (_reader.CurrentChar == "\"") { val = _reader.ReadToken("\"", @"\", false, true, true, true); } else { val = _reader.ReadToEol(); } if (!_settings.IsCaseSensitive) { key = key.ToLower(); } // This allow multiple values for the same key. // Multiple values are stored using List<object>. _currentSection.AddMulti(key, val, false); _lastLineType = IniLineType.KeyValue; }
private void StoreKeyValue() { string key = TokenParser.ReadKey(this); string value = TokenParser.ReadValue(this); _currentSection.Add(new KeyValueItem <string, string>(key, value)); _lastLineType = IniLineType.KeyValue; }
/// <summary> /// Initializes a new instance of the <see cref="IniParseResult"/> class with the given extracted data. /// </summary> /// <param name="type">The type of the extracted data.</param> /// <param name="primaryContent">The primary text of the extracted data.</param> /// <param name="secondaryContent">The secondary text of the extracted data.</param> /// <param name="linesRead">The number of lines read for extracting data.</param> internal IniParseResult(IniLineType type, string primaryContent, string secondaryContent, int linesRead) { Type = type; PrimaryContent = primaryContent; SecondaryContent = secondaryContent; LinesRead = linesRead; }
private bool CurrentLineIsA(IniLineType lineType, string currentLine) { return(lineType switch { IniLineType.Section => currentLine.StartsWith('[') && currentLine.EndsWith(']'), IniLineType.KeyValue => currentLine.Contains('=') && !currentLine.StartsWith(';'), IniLineType.Comment => currentLine.StartsWith(';'), _ => throw new InvalidOperationException("An unrecognized line type was provided and cannot be analyzed"), });
protected IniLineData(IniLineType lineType, string?existingText) { if (!Enum.IsDefined(typeof(IniLineType), lineType)) { throw new InvalidEnumArgumentException(nameof(lineType), (int)lineType, typeof(IniLineType)); } LineType = lineType; ExistingText = existingText; }
private void StoreGroup() { // Push the last one into the list. if (_currentSection.Count > 0) { _sections.Add(_currentSection); } string group = TokenParser.ReadGroup(this); this.ReadTokenToEndOfLine(); // Create a new section using the name of the group. _currentSection = new IniSection(group, null); _lastLineType = IniLineType.Group; }
public static ExpandoObject Parse(string path) { using var fs = File.OpenRead(path); using var reader = new StreamReader(fs); string line; string lastSectionName = null; var iniFile = new ExpandoObject(); var iniObjects = (IDictionary <string, object>)iniFile; while ((line = reader.ReadLine()) != null) { IniLineType type = IniParseHelper.GetLineType(line); switch (type) { case IniLineType.Section: { string sectionName = IniParseHelper.GetSectionName(line); lastSectionName = sectionName; iniObjects.Add(sectionName, new ExpandoObject()); break; } case IniLineType.Property: { (string name, object value) = IniParseHelper.GetProperty(line); if (lastSectionName != null) { ((IDictionary <string, object>)iniObjects[lastSectionName]).Add(name, value); } else { iniObjects.Add(name, value); } break; } case IniLineType.Comment: case IniLineType.Empty: case IniLineType.Unknown: continue; } } return(iniFile); }
protected virtual void StoreGroup() { // Push the last one into the list. if (_currentSection.Count > 0) { _sections.Add(_currentSection); } string group = _reader.ReadToken("]", @"\", false, true, true, true); if (!_settings.IsCaseSensitive) { group = group.ToLower(); } // Create a new section using the name of the group. _currentSection = new IniSection() { Name = group }; _lastLineType = IniLineType.Group; }
// Метод, разделяющий информацию, считанную из ini-файла, и представляющий её в виде сортированных словарей. // Возвращает словарь формата "название-секции : содержание-секции(параметр : значение)". private static SortedDictionary <string, SortedDictionary <string, string> > SeparateIniFileContent(string[] fileContent) { SortedDictionary <string, SortedDictionary <string, string> > iniContent = new SortedDictionary <string, SortedDictionary <string, string> >(); string sectionName = ""; for (int i = 0; i < fileContent.Length; i++) { if (fileContent[i].IndexOf(";") >= 0) { fileContent[i] = fileContent[i].Split(";")[0]; } if (fileContent[i].IndexOf("#") >= 0) { fileContent[i] = fileContent[i].Split("#")[0]; } IniLineType lineType = GetIniLineType(fileContent[i]); switch (lineType) { case IniLineType.EmptyLine: continue; case IniLineType.SectionName: sectionName = fileContent[i].Trim()[1..^ 1].Trim();
private void StoreComment() { string comment = ReadTokenToEndOfLine(); _lastLineType = IniLineType.Comment; }