common: create unified version of COM_Parse for merging

Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
This commit is contained in:
Kevin Shanahan 2012-11-28 17:37:16 +10:30
parent 9574035063
commit b0720156b8
2 changed files with 39 additions and 7 deletions

View File

@ -816,8 +816,10 @@ COM_Parse
Parse a token out of a string
==============
*/
const char *
COM_Parse(const char *data)
static const char single_chars[] = "{})(':";
static const char *
COM_Parse_(const char *data, qboolean split_single_chars)
{
int c;
int len;
@ -856,7 +858,7 @@ COM_Parse(const char *data)
}
}
// parse single characters
if (c == '{' || c == '}' || c == ')' || c == '(' || c == '\'' || c == ':') {
if (split_single_chars && strchr(single_chars, c)) {
com_token[len] = c;
len++;
com_token[len] = 0;
@ -868,8 +870,7 @@ COM_Parse(const char *data)
data++;
len++;
c = *data;
if (c == '{' || c == '}' || c == ')' || c == '(' || c == '\''
|| c == ':')
if (split_single_chars && strchr(single_chars, c))
break;
} while (c > 32);
@ -877,6 +878,16 @@ COM_Parse(const char *data)
return data;
}
const char *
COM_Parse(const char *data)
{
#ifdef NQ_HACK
return COM_Parse_(data, true);
#endif
#ifdef QW_HACK
return COM_Parse_(data, false);
#endif
}
/*
================

View File

@ -919,8 +919,10 @@ COM_Parse
Parse a token out of a string
==============
*/
const char *
COM_Parse(const char *data)
static const char single_chars[] = "{})(':";
static const char *
COM_Parse_(const char *data, qboolean split_single_chars)
{
int c;
int len;
@ -958,18 +960,37 @@ COM_Parse(const char *data)
len++;
}
}
// parse single characters
if (split_single_chars && strchr(single_chars, c)) {
com_token[len] = c;
len++;
com_token[len] = 0;
return data + 1;
}
// parse a regular word
do {
com_token[len] = c;
data++;
len++;
c = *data;
if (split_single_chars && strchr(single_chars, c))
break;
} while (c > 32);
com_token[len] = 0;
return data;
}
const char *
COM_Parse(const char *data)
{
#ifdef NQ_HACK
return COM_Parse_(data, true);
#endif
#ifdef QW_HACK
return COM_Parse_(data, false);
#endif
}
/*
================