public static KeyValues FromStream(Stream stream, KeyValuesFlags flags = KeyValuesFlags.Default) { using (var reader = new StreamReader(stream)) { return(Parse(reader.ReadToEnd(), flags)); } }
private KeyValues(ParseResult result, KeyValuesFlags flags) { AssertParser(result, ".Document"); _root = new Entry(); _root.AddValue(result[0], flags); }
internal void AddValue(ParseResult result, KeyValuesFlags flags) { var entry = new Entry(); entry.AddValue(result, flags); _entries.Add(entry); }
private KeyValues(ParseResult result, KeyValuesFlags flags) { AssertParser(result, ".Definition.List"); _root = new Entry(); _root.AddValue(result, flags); }
public static IEnumerable <KeyValues> ListFromStream(Stream stream, KeyValuesFlags flags = KeyValuesFlags.Default) { using (var reader = new StreamReader(stream)) { return(ParseList(reader.ReadToEnd(), flags)); } }
internal void AddValue(ParseResult result, KeyValuesFlags flags) { if (result.Parser.ElementName.EndsWith(".String")) { _value = ReadString(result, flags); return; } AssertParser(result, ".Definition.List"); if (result.Length == 0) { return; } if (_subEntries == null) { _subEntries = new Dictionary <string, EntryCollection>(StringComparer.InvariantCultureIgnoreCase); } foreach (var def in result) { var key = ReadString(def[0], flags); if (!_subEntries.TryGetValue(key, out var existing)) { _subEntries.Add(key, existing = new EntryCollection()); } existing.AddValue(def[1], flags); } }
public static KeyValues Parse(string value, KeyValuesFlags flags = KeyValuesFlags.Default) { var parser = (flags & KeyValuesFlags.UsesEscapeSequences) != 0 ? _sEscapedParser : _sUnescapedParser; var result = parser.Parse(value); if (!result.Success) { throw new KeyValuesParserException(result); } return(new KeyValues(result, flags)); }
public static bool TryParse(string value, out KeyValues result, KeyValuesFlags flags = KeyValuesFlags.Default) { try { result = Parse(value, flags); return(true); } catch { result = null; return(false); } }
public static IEnumerable <KeyValues> ParseList(string value, KeyValuesFlags flags = KeyValuesFlags.Default) { value = value.TrimEnd('\0'); var parser = (flags & KeyValuesFlags.UsesEscapeSequences) != 0 ? _sEscapedParser : _sUnescapedParser; var result = parser.Parse(value); if (!result.Success) { throw new KeyValuesParserException(result); } foreach (var parsed in result) { yield return(new KeyValues(parsed, flags)); } }
private static string ReadString(ParseResult result, KeyValuesFlags flags) { AssertParser(result, ".String"); var rawValue = result[0].Value; if ((flags & KeyValuesFlags.UsesEscapeSequences) != 0) { var builder = _sBuilder ?? (_sBuilder = new StringBuilder()); builder.Remove(0, builder.Length); for (var i = 0; i < rawValue.Length; ++i) { var c = rawValue[i]; switch (c) { case '\\': switch (c = rawValue[++i]) { case 'n': builder.Append('\n'); break; case 't': builder.Append('\t'); break; case '"': case '\\': builder.Append(c); break; } break; default: builder.Append(c); break; } } return(builder.ToString()); } return(rawValue); }
public static KeyValues Parse(string value, KeyValuesFlags flags = KeyValuesFlags.Default) { value = value.TrimEnd('\0').ToLower(); var parser = (flags & KeyValuesFlags.UsesEscapeSequences) != 0 ? _sEscapedParser : _sUnescapedParser; var result = parser.Parse(value); try { if (!result.Success) { throw new Exception(result.ErrorMessage); } } catch (Exception ex) { UnityEngine.Debug.LogError("EOF: " + ex); return(new KeyValues(result.First(), flags)); } return(new KeyValues(result.First(), flags)); }