23
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
29
using System.Collections.Generic;
29
31
namespace MonoDevelop.Core.Execution
138
static string GetArgument (StringBuilder builder, string buf, int startIndex, out int endIndex, out Exception ex)
140
bool escaped = false;
141
char qchar, c = '\0';
145
switch (buf[startIndex]) {
146
case '\'': qchar = '\''; i++; break;
147
case '"': qchar = '"'; i++; break;
148
default: qchar = '\0'; break;
151
while (i < buf.Length) {
154
if (c == qchar && !escaped) {
155
// unescaped qchar means we've reached the end of the argument
162
} else if (escaped) {
165
} else if (qchar == '\0' && (c == ' ' || c == '\t')) {
174
if (escaped || (qchar != '\0' && c != qchar)) {
175
ex = new FormatException (escaped ? "Incomplete escape sequence." : "No matching quote found.");
183
return builder.ToString ();
186
static bool TryParse (string commandline, out string[] argv, out Exception ex)
188
StringBuilder builder = new StringBuilder ();
189
List<string> args = new List<string> ();
194
while (i < commandline.Length) {
196
if (c != ' ' && c != '\t') {
197
if ((argument = GetArgument (builder, commandline, i, out j, out ex)) == null) {
209
argv = args.ToArray ();
215
public static bool TryParse (string commandline, out string[] argv)
219
return TryParse (commandline, out argv, out ex);
222
public static string[] Parse (string commandline)
227
if (!TryParse (commandline, out argv, out ex))