I am trying to write a command line parser that would take a string as input
and build a list of arguments based on the following simple syntax:
 
An argument is either:
    
    [A-Za-z0-9]+ or
    "(anything but a ") with \" ignored followed by a closing "
 
So what is the best way in Ruby to do this?
 
def parseCommandLine(aString) --> array of strings
 
I know how I would do this in C (have done it many times)
    
    GetToken()
    {
        // eat leading spaces
        while (isspace(c = getchar()))
            ;
 
        while (c != EOF) {
            if (alnum(c)) {
                while (isalnum(c))
                    *pToken++ = c;
            }
            else if (c == DOUBLE_QUOTE) {
                done = false
                gotback = false
                while (!done) {
                    c = getchar();
                    if (c == EOF)
                        error("no ending double quote\n");
 
                    if (gotback) {
                        if (c == BACKSLASH || c == DOUBLE_QUOTE) {
                            *pToken++ = c
                        }
                        gotback = false
                    }
                    else {
                        if (c == BACKSLASH) {
                            gotback = true   
                        }
                        else if (c == DOUBLE_QUOTE) {
                            break;
                        }
                        else (
                            *pToken++ = c
                        }
                    }
                }
            }
 
            c = getchar();
        }
    }