sockscape/server_old/Libraries/Glove/INI/Instance.cs

47 lines
1.3 KiB
C#
Raw Normal View History

2017-06-05 12:20:39 +00:00
using System;
2017-06-07 21:02:29 +00:00
using System.Collections;
2017-06-05 12:20:39 +00:00
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
2017-07-22 19:27:41 +00:00
namespace Glove.INI {
2017-06-07 21:02:29 +00:00
public class Instance : IEnumerable<KeyValuePair<string, Value>> {
2017-08-21 21:03:32 +00:00
private readonly Dictionary<string, Value> Data
2017-06-07 21:02:29 +00:00
= new Dictionary<string, Value>(StringComparer.OrdinalIgnoreCase);
2017-06-06 21:13:25 +00:00
2017-06-07 21:02:29 +00:00
internal Instance() { }
2017-06-05 12:20:39 +00:00
2017-06-07 21:02:29 +00:00
internal void Push(string line) {
2017-08-22 20:59:41 +00:00
if(line.Trim() == "")
return;
2017-06-07 21:02:29 +00:00
if(line.Contains('=')) {
2017-08-21 21:03:32 +00:00
var parts = line.Split(new[] { '=' }, 2);
2017-06-07 21:02:29 +00:00
Data.Add(parts[0].Trim(), new Value(parts[1].Trim()));
} else
throw new FormatException("Line is not a key-value pair delimited by an equals sign.");
}
public Value this[string key] {
get {
if(Data.ContainsKey(key))
return Data[key];
else return null;
}
}
public bool ContainsKey(string key) {
return Data.ContainsKey(key);
}
IEnumerator IEnumerable.GetEnumerator() {
return Data.GetEnumerator();
}
IEnumerator<KeyValuePair<string, Value>> IEnumerable<KeyValuePair<string, Value>>.GetEnumerator() {
return Data.GetEnumerator();
}
2017-06-05 12:20:39 +00:00
}
}