def _split_command_line(self, command_line):
        arg_list = []
        arg = ''
        state_quote = 0
        state_doublequote = 0
        state_esc = 0
        for c in command_line:
            if c == '\\': # Escape the next character
                state_esc = 1
            elif c == r"'": # Handle single quote
                if state_esc:
                    state_esc = 0
                elif not state_quote:
                    state_quote = 1
                else:
                    state_quote = 0
            elif c == r'"': # Handle double quote
                if state_esc:
                    state_esc = 0
                elif not state_doublequote:
                    state_doublequote = 1
                else:
                    state_doublequote = 0
    
            # Add arg to arg_list unless in some other state.
            elif c == ' 'and not state_quote and not state_doublequote and not state_esc:
                if arg != '':
                    arg_list.append(arg)
                arg = ''
            else:
                arg = arg + c
                if c != '\\'and state_esc: # escape mode lasts for one character.
                    state_esc = 0
    
        # Handle last argument.        
        if arg != '':
            arg_list.append(arg)
        
        return arg_list

# **************************************************************************************************
This splits a command line into a list of arguments.
dataset/ETHPy150Open joehewitt/devon/devon/spawn.py/SpawnPty._split_command_line