Game Development Reference
In-Depth Information
to the current token string. If it is a space or tab then the current token
string has a terminating zero added to the end. Then we move through the
line string until no more spaces or tabs are found. The gap between
tokens can contain multiple spaces, which need to be removed. If some
spaces or tabs are removed in this loop then we need to back up the
character index, i , by one so that when the loop is incremented in the 'for'
statement it points to the correct next character. Then the token count is
incremented and tested against the value for maximum tokens. If the
token count equals the maximum tokens then the function returns
because the token count is a zero index count. The loop uses a variable
string to bypass the parsing of spaces if this is a token nested between
inverted commas.
int C3DSAscii::ParseTokens(CString &line, TOKEN *tokens, int
maxtokens)
{
char c;
int count = 0, index = 0, tmp;
BOOL string = FALSE;
line.TrimLeft();
line.TrimRight();
for(int i=0; i<line.GetLength(); i++){
c = line.GetAt(i);
if ((c==' '&&!string)||c=='\t'){
if (index){
tokens[count].name[index]=0;
count++;
tmp = i;
while(line.GetAt(tmp)==' '|| line.GetAt(tmp)==\t')
tmp++;
if (tmp!=i) i=tmp-1;
if (count>=maxtokens) return count;
index = 0;
}
}else{
if (c=='"'){
string=(string)?FALSE:TRUE;
}else{
tokens[count].name[index++]=c;
}
Search Nedrilad ::




Custom Search