public CommandLine(CommandLineTypes commandLineType, string command, string[] args) { CommandLineType = commandLineType; command = command.Trim(); switch (CommandLineType) { case CommandLineTypes.Comment: if (command.Substring(0, 2) != "//") { command = "// " + command; } Command = command; Arguments = null; break; case CommandLineTypes.WhiteSpace: Command = string.Empty; Arguments = null; break; case CommandLineTypes.SectionHeader: // if the "[" was passed in, strip it for this type if (command.Substring(0, 1) == "[") { command = command.Substring(1); } // if the "]" was passed in, strip it for this type if (command.Substring(command.Length - 1, 1) == "]") { command = command.Substring(0, command.Length - 1); } Command = command; Arguments = null; break; case CommandLineTypes.Command: Command = command; Arguments = args; break; default: Command = string.Empty; Arguments = null; break; } }
public CommandLine(CommandLineTypes commandLineType, string command, string[] args) { CommandLineType = commandLineType; command = command.Trim(); switch (CommandLineType) { case CommandLineTypes.Comment: if (command.Substring(0, 2) != "//") command = "// " + command; Command = command; Arguments = null; break; case CommandLineTypes.WhiteSpace: Command = string.Empty; Arguments = null; break; case CommandLineTypes.SectionHeader: // if the "[" was passed in, strip it for this type if (command.Substring(0, 1) == "[") command = command.Substring(1); // if the "]" was passed in, strip it for this type if (command.Substring(command.Length - 1, 1) == "]") command = command.Substring(0, command.Length - 1); Command = command; Arguments = null; break; case CommandLineTypes.Command: Command = command; Arguments = args; break; default: Command = string.Empty; Arguments = null; break; } }
public CommandLine(string line) { // trim the line before parsing it string tmp = line.Trim(); if (tmp.Length == 0) { Command = string.Empty; Arguments = null; CommandLineType = CommandLineTypes.WhiteSpace; } else { if (tmp.Substring(0, 1) == "[") { Command = line.Substring(1, line.Length - 2); Arguments = null; CommandLineType = CommandLineTypes.SectionHeader; } else { if (tmp.Substring(0, 2) == "//") { // this is a Comment line Command = line; Arguments = null; CommandLineType = CommandLineTypes.Comment; } else { // this is a Command CommandLineType = CommandLineTypes.Command; int idx = tmp.IndexOf(':'); // Command is the text to the left of the ":" if (idx > 0) Command = tmp.Substring(0, idx).Trim(); else Command = string.Empty; // Arguments is the array of values to the right of the ":" tmp = line.Substring(idx + 1); if (idx > 0) { // split out the args string[] args = tmp.Split(','); // trim each arg for (int i = 0; i < args.Length; i++) args[i] = args[i].Trim(); Arguments = args; } else Arguments = null; } } } }
public CommandLine(string line) { // trim the line before parsing it string tmp = line.Trim(); if (tmp.Length == 0) { Command = string.Empty; Arguments = null; CommandLineType = CommandLineTypes.WhiteSpace; } else { if (tmp.Substring(0, 1) == "[") { Command = line.Substring(1, line.Length - 2); Arguments = null; CommandLineType = CommandLineTypes.SectionHeader; } else { if (tmp.Substring(0, 2) == "//") { // this is a Comment line Command = line; Arguments = null; CommandLineType = CommandLineTypes.Comment; } else { // this is a Command CommandLineType = CommandLineTypes.Command; int idx = tmp.IndexOf(':'); // Command is the text to the left of the ":" if (idx > 0) { Command = tmp.Substring(0, idx).Trim(); } else { Command = string.Empty; } // Arguments is the array of values to the right of the ":" tmp = line.Substring(idx + 1); if (idx > 0) { // split out the args string[] args = tmp.Split(','); // trim each arg for (int i = 0; i < args.Length; i++) { args[i] = args[i].Trim(); } Arguments = args; } else { Arguments = null; } } } } }