All pastes #930536 Raw Edit

Something

public cpp v1 · immutable
·published 2008-03-06 17:57 UTC
rendered paste body
vector<char*> *splitArgs(char *command) {	vector<char*> args;	int len = (int)strlen(command);	bool inQuotes = false;	int lastIndex = 0;	for(int i = 0; i < len; i++) {		if(command[i] == ' ') {			if(!inQuotes) {				args.push_back(substring(command, lastIndex, i));				lastIndex = i + 1;			}		} else if(command[i] == '\"') {			if(!inQuotes) {				lastIndex = i;				inQuotes = true;			} else {				args.push_back(substring(command, lastIndex + 1, i));				lastIndex = (i++);				inQuotes = false;			}		} else if((i + 1) == len) {			args.push_back(substring(command, lastIndex + 1, i + 1));		}	}	return *args;}