Changes required to work with mono 1.2.6 and recent unixodbc.
[schedulator.git] / wvini.cs
blob7b44a67d33c0972feee893ced79b06939368fc61
1 using System;
2 using System.IO;
3 using System.Collections;
4 using System.Collections.Specialized;
6 namespace Wv.Utils
8 /// Well, it's not exactly UniConf, but...
9 public class Ini
11 Hashtable sections
12 = new Hashtable(10, new CaseInsensitiveHashCodeProvider(),
13 new CaseInsensitiveComparer());
15 public Ini(string filename)
17 StreamReader r;
19 try
21 r = File.OpenText(filename);
23 catch (IOException)
25 return; // I guess there's no file!
28 string section = "";
29 string s;
30 while ((s = r.ReadLine()) != null)
32 s = s.Trim();
33 if (s.Length == 0) continue; // blank line
34 if (s[0] == '#') continue; // comment
35 if (s[0] == '[' && s[s.Length-1]==']') // section
37 section = s.Substring(1, s.Length-2);
39 else if (s.IndexOf('=') >= 0)
41 string[] a = s.Split(new char[] {'='}, 2);
42 this[section][a[0].Trim()] = a[1].Trim();
44 else
45 continue; // whatever
49 public StringDictionary this[string sectname]
51 get
53 if (!sections.Contains(sectname))
54 sections.Add(sectname, new StringDictionary());
55 return (StringDictionary)sections[sectname];