return null;\r
}\r
\r
+ /// <summary>\r
+ /// Parses a comment of an INI file.\r
+ /// </summary>\r
+ /// <param name="line">Text.</param>\r
+ /// <returns>The comment.</returns>\r
+ public static string IniComment(string line)\r
+ {\r
+ Match match = Regex.Match(line, @"^;\s*(.*)\s*$");\r
+ if (match.Success) return match.Groups[1].Value;\r
+ return null;\r
+ }\r
+\r
/// <summary>\r
/// Parses a key-value pair.\r
/// </summary>\r
/// </summary>\r
/// <typeparam name="T">An enumeration.</typeparam>\r
/// <param name="atom">Text.</param>\r
- /// <returns>The constant, or null if parsing failed.</returns>\r
+ /// <returns>The constant, or default(T) if parsing failed.</returns>\r
public static T Constant<T>(string atom)\r
{\r
- string constant = String(atom);\r
- if (constant != null)\r
+ try\r
{\r
- foreach (string enumConstant in System.Enum.GetNames(typeof(T)))\r
- {\r
- if (constant == enumConstant)\r
- {\r
- return (T)System.Enum.Parse(typeof(T), constant);\r
- }\r
- }\r
+ return (T)System.Enum.Parse(typeof(T), String(atom), true);\r
+ }\r
+#pragma warning disable 0168\r
+ catch (System.Exception ex)\r
+#pragma warning restore 0168\r
+ {\r
+ return default(T);\r
}\r
- return default(T);\r
}\r
\r
/// <summary>\r
return null;\r
}\r
\r
- /// <summary>\r
- /// Parses a comma-separated list of atoms.\r
- /// </summary>\r
- /// <param name="text">Text.</param>\r
- /// <returns>An array of strings containing the atoms, or null\r
- /// if parsing failed.</returns>\r
- public static string[] ParameterList(string text)\r
- {\r
- return null;\r
- }\r
-\r
/// <summary>\r
/// Parses a whitespace-separated list of atoms.\r
/// </summary>\r
// FIXME: This may barf all over itself if there are nested parentheses, doublequotes, brackets, etc.\r
foreach (Match match in matches)\r
{\r
- Console.WriteLine("matched: " + match.Value);\r
list.Add(match.Value);\r
}\r
\r