void PerformInputBoxReplacement(string line, string replacement, CommandArgument activeArgument)
        {
            //extend the argument accordingly
            CommandArgument modifiedArgument = new CommandArgument(replacement);
            string middle = modifiedArgument.Escape();
            string left = line.Substring(0, activeArgument.Offset);
            int rightOffset = activeArgument.Offset + activeArgument.Length();
            string right = line.Substring(rightOffset);
            string newLine = left + middle + right;
            int newCursorOffset = activeArgument.Offset + replacement.Length;

            //need to fix the cursor position, it should be at the end of the current argument
            MainForm.InputBox.Text = newLine;
            MainForm.InputBox.SelectionStart = newCursorOffset;
        }
        void ProcessLine(string line)
        {
            List<CommandArgument> tokens = new List<CommandArgument>();
            string currentToken = "";
            int currentTokenOffset = 0;
            bool quoteMode = false;
            char lastChar = '\x00';
            ArgumentHasQuotes = false;

            for(int i = 0; i < line.Length; i++)
            {
                char input = line[i];
                bool wasQuote = i > 0 && lastChar == '"';
                bool quoteError = !quoteMode && wasQuote;

                switch (input)
                {
                    case ' ':
                        if(quoteMode)
                            currentToken += input;
                        else
                        {
                            if(currentToken.Length > 0)
                            {
                                ProcessResult(currentToken, currentTokenOffset, tokens);
                                currentToken = "";
                            }
                        }
                        break;

                    case '"':
                        if (lastChar == '\\')
                        {
                            currentToken.Remove(currentToken.Length - 1);
                            currentToken += input;
                            break;
                        }
                        if (quoteError)
                            throw new ArgumentException("Encountered a quote right after a terminating quote");
                        quoteMode = !quoteMode;
                        if (quoteMode)
                        {
                            ArgumentHasQuotes = true;
                            currentTokenOffset = i;
                        }
                        break;

                    default:
                        if (quoteError)
                            throw new ArgumentException("Encountered a printable character after a terminating quote");
                        if(currentToken.Length == 0)
                            currentTokenOffset = i;
                        currentToken += input;
                        break;
                }
                lastChar = input;
            }

            if (quoteMode)
                throw new ArgumentException("Missing quote");

            if (currentToken.Length > 0)
                ProcessResult(currentToken, currentTokenOffset, tokens);

            Command = tokens[0];
            Arguments = tokens.GetRange(1, tokens.Count - 1).ToArray();
        }
 void ProcessResult(string currentToken, int currentTokenOffset, List<CommandArgument> tokens)
 {
     CommandArgument newResult = new CommandArgument(currentToken, currentTokenOffset, ArgumentHasQuotes);
     tokens.Add(newResult);
     ArgumentHasQuotes = false;
 }