X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fcarfire;a=blobdiff_plain;f=CarFire%2FCarFire%2FCarFire%2FParse.cs;h=4c2abcc416fd972cc14fef4f03b3fb279c2d2b33;hp=169cf30a7b8340b59af9aa61aae521c9e7c04ad8;hb=d167160264cd2c33de81a71039eddbb959c40bb2;hpb=7fa101e60a4bc35dfd5dabf8f66811e3f8cfa673 diff --git a/CarFire/CarFire/CarFire/Parse.cs b/CarFire/CarFire/CarFire/Parse.cs index 169cf30..4c2abcc 100644 --- a/CarFire/CarFire/CarFire/Parse.cs +++ b/CarFire/CarFire/CarFire/Parse.cs @@ -9,7 +9,8 @@ namespace CarFire { /// /// Class with handy static methods taking strings and returning objects - /// parsed from those strings. + /// parsed from those strings. For all of these functions, white space is + /// generally ignored, but superfluous characters are not allowed. /// public class Parse { @@ -25,6 +26,18 @@ namespace CarFire return null; } + /// + /// Parses a comment of an INI file. + /// + /// Text. + /// The comment, or null if parsing failed. + 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. /// @@ -96,6 +109,18 @@ namespace CarFire return null; } + /// + /// Parses a single character. + /// + /// Text. + /// The character, or null if parsing failed. + public static char? Char(string atom) + { + string str = String(atom); + if (str != null && str.Length == 1) return str[0]; + return null; + } + /// /// Parses a constant from an enum. /// @@ -106,7 +131,7 @@ namespace CarFire { try { - return (T)System.Enum.Parse(typeof(T), String(atom), true); + return (T)System.Enum.Parse(typeof(T), String(atom)); } #pragma warning disable 0168 catch (System.Exception ex) @@ -156,7 +181,7 @@ namespace CarFire /// Parses a function. /// /// Text. - /// An array two strings containing the function name and + /// An array with two strings containing the function name and /// parameter-list, in that order, or null if parsing failed. public static string[] Function(string atom) { @@ -182,7 +207,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); }