Created
June 13, 2013 05:52
-
-
Save ecere/5771515 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public int Tokenize(char * string, int maxTokens, char* tokens[], BackSlashEscaping esc) | |
{ | |
int count = 0; | |
bool quoted = false; | |
byte * start = null; | |
bool escaped = false; | |
char * output = string; | |
for(; *string && count < maxTokens; string++, output++) | |
{ | |
if(output != string) | |
*output = *string; | |
if(start) | |
{ | |
if(escaped) | |
{ | |
escaped = false; | |
output--; | |
// ADDED THIS HERE... | |
if(output != string) | |
*output = *string; | |
} | |
else if(*string == '\\' && (esc == true || | |
(esc == forArgsPassing && (*(string+1) == '\"' || *(string+1) == ' ')))) | |
escaped = true; | |
else if(*string == '\"') | |
{ | |
if(quoted) | |
{ | |
output--; | |
// *output = '\0'; | |
quoted = false; | |
} | |
else | |
{ | |
/*memmove(start + 1, start, string - (char *)start); | |
start++;*/ | |
quoted = true; | |
output--; | |
} | |
} | |
else if(*string == ' ' && !quoted) | |
{ | |
tokens[count++] = start; | |
*output = '\0'; | |
start = null; | |
} | |
} | |
else if(*string != ' ') | |
{ | |
if(*string == '\"') | |
{ | |
quoted = true; | |
start = output + 1; | |
} | |
else | |
{ | |
start = output; | |
if(*string == '\\' && (esc == true || | |
(esc == forArgsPassing && (*(string+1) == '\"' || *(string+1) == ' ')))) | |
escaped = true; | |
} | |
} | |
} | |
if(start && count < maxTokens) | |
{ | |
tokens[count++] = start; | |
*output = '\0'; | |
} | |
return count; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment