X-Git-Url: https://git.brokenzipper.com/gitweb?a=blobdiff_plain;f=CarFire%2FCarFire%2FCarFire%2FParse.cs;h=b9320778babcbcdfb62d685aec9306ce2639d6c7;hb=26bf916b7a42c6b33ae720aa9a41e3de752961d1;hp=e1a482eb6a08c55398650186bdefd3f45d9fd527;hpb=c5daf1d9adca0c3a826dfa2ac7b6d4f8a64c84a3;p=chaz%2Fcarfire
diff --git a/CarFire/CarFire/CarFire/Parse.cs b/CarFire/CarFire/CarFire/Parse.cs
index e1a482e..b932077 100644
--- a/CarFire/CarFire/CarFire/Parse.cs
+++ b/CarFire/CarFire/CarFire/Parse.cs
@@ -25,6 +25,18 @@ namespace CarFire
return null;
}
+ ///
+ /// Parses a comment of an INI file.
+ ///
+ /// Text.
+ /// The comment.
+ public static string IniComment(string line)
+ {
+ Match match = Regex.Match(line, @"^;\s*(.*)\s*$");
+ if (match.Success) return match.Groups[1].Value;
+ return null;
+ }
+
///
/// Parses a key-value pair.
///
@@ -101,21 +113,19 @@ namespace CarFire
///
/// An enumeration.
/// Text.
- /// The constant, or null if parsing failed.
+ /// The constant, or default(T) if parsing failed.
public static T Constant(string atom)
{
- string constant = String(atom);
- if (constant != null)
+ try
{
- foreach (string enumConstant in System.Enum.GetNames(typeof(T)))
- {
- if (constant == enumConstant)
- {
- return (T)System.Enum.Parse(typeof(T), constant);
- }
- }
+ return (T)System.Enum.Parse(typeof(T), String(atom), true);
+ }
+#pragma warning disable 0168
+ catch (System.Exception ex)
+#pragma warning restore 0168
+ {
+ return default(T);
}
- return default(T);
}
///
@@ -171,17 +181,6 @@ namespace CarFire
return null;
}
- ///
- /// Parses a comma-separated list of atoms.
- ///
- /// Text.
- /// An array of strings containing the atoms, or null
- /// if parsing failed.
- public static string[] ParameterList(string text)
- {
- return null;
- }
-
///
/// Parses a whitespace-separated list of atoms.
///
@@ -195,7 +194,6 @@ namespace CarFire
// FIXME: This may barf all over itself if there are nested parentheses, doublequotes, brackets, etc.
foreach (Match match in matches)
{
- Console.WriteLine("matched: " + match.Value);
list.Add(match.Value);
}