VuzitCL.ArgvParser.Extract C# (CSharp) Method

Extract() private method

Extract command line parameters and values stored in a string array
private Extract ( string args ) : void
args string
return void
        private void Extract(string[] args)
        {
            parameters = new Dictionary<string, string>();
            Regex splitter = new Regex (@"^([/-]|--){1}(?<name>\w+)([:=])?(?<value>.+)?$",
                                        RegexOptions.Compiled);
            char[] trimChars = {'"','\''};
            string parameter = null;
            Match part;

            // Valid parameters forms: {-,/,--}param{ , = ,:}((",')value(",'))
            // Examples: -param1 value1 --param2 /param3:"Test-:-work" 
            // /param4 = happy -param5 '-- = nice = --'
            foreach(string arg in args)
            {
                part = splitter.Match(arg);
                if (!part.Success) {
                    // Found a value (for the last parameter found (space separator))
                    if (parameter != null) {
                        parameters[parameter] = arg.Trim (trimChars);
                    }
                } else {
                    // Matched a name, optionally with inline value
                    parameter = part.Groups["name"].Value;
                    parameters.Add (parameter, 
                                    part.Groups["value"].Value.Trim (trimChars));
                }
            }
        }
        #endregion