[Csmail-patches] CVS: csmail/src/CSMail.Utils ChangeLog,1.2,1.3 Properties.cs,1.2,1.3
Status: Pre-Alpha
Brought to you by:
mastergaurav
From: Gaurav V. <mas...@us...> - 2002-08-29 07:03:10
|
Update of /cvsroot/csmail/csmail/src/CSMail.Utils In directory usw-pr-cvs1:/tmp/cvs-serv4311/CSMail.Utils Modified Files: ChangeLog Properties.cs Log Message: 2002-08-29 * CSMail/ProviderCollection.cs : Renamed to ProviderList * CSMail/ProviderList.cs : Renamed version of ProviderCollection * CSMail/Session.cs : Stubbed LoadProviders, LoadAddressMap * CSMail.Utils/Properties.cs : Indexer - Implemented : LoadFrom(string) - Implemented : LoadFrom(TextReader) - Implemented Index: ChangeLog =================================================================== RCS file: /cvsroot/csmail/csmail/src/CSMail.Utils/ChangeLog,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- ChangeLog 28 Aug 2002 11:46:38 -0000 1.2 +++ ChangeLog 29 Aug 2002 07:03:04 -0000 1.3 @@ -1,6 +1,12 @@ 2002-08-28 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> + * Properties.cs : Indexer - Implemented + : LoadFrom(string) - Implemented + : LoadFrom(TextReader) - Implemented + +2002-08-28 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> + * Properties.cs : Stubbed "this[string]" property. 2002-06-20 Gaurav Vaish <mastergaurav AT users DOT sf DOT net> Index: Properties.cs =================================================================== RCS file: /cvsroot/csmail/csmail/src/CSMail.Utils/Properties.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- Properties.cs 28 Aug 2002 11:44:20 -0000 1.2 +++ Properties.cs 29 Aug 2002 07:03:04 -0000 1.3 @@ -9,27 +9,79 @@ */ using System; +using System.Collections; +using System.IO; using CSMail; namespace CSMail.Utils { - public class Properties + /// <summary> + /// key = value + /// key : value + /// </summary> + public class Properties : Hashtable { - public Properties() + public static readonly char[] Separators = new char[] { + ':', + '=' + }; + + public Properties() : base() { } - [MailTODO] public string this[string key] { get { - throw new NotImplementedException(); + return (string)base[key]; } set { - throw new NotImplementedException(); + base[key] = value; + } + } + + public static Properties LoadFrom(string filename) + { + return LoadFrom(new StreamReader(filename)); + } + + public static Properties LoadFrom(TextReader reader) + { + string currentLine; + string key; + string value; + Properties retVal = new Properties(); + + while((currentLine = reader.ReadLine()) != null) + { + currentLine = currentLine.Trim(); + if(currentLine[0] != '#') + { + GetKeyValue(currentLine, out key, out value); + if(key != null && value != null) + { + retVal[key] = value; + } + } + } + return retVal; + } + + private static void GetKeyValue(string line, out string key, + out string value) + { + int colon = line.IndexOfAny(Separators); + key = null; + value = null; + if(colon > 0) + { + key = line.Substring(0, colon); + key = key.Trim(); + value = line.Substring(colon + 1); + value = value.Trim(); } } } -} +} \ No newline at end of file |