enable quoted tokens in the token enumerator

This commit is contained in:
Tobias Brunner
2008-12-03 10:03:59 +00:00
parent f4bcf49bcb
commit c3bdc3cd7f
2 changed files with 42 additions and 18 deletions
@@ -231,6 +231,8 @@ bool test_enumerate_token()
{" abc 1:2 cde;3 4efg5. ", ":;.,", " 12345"}, {" abc 1:2 cde;3 4efg5. ", ":;.,", " 12345"},
{"abc.cde,efg", ",.", ""}, {"abc.cde,efg", ",.", ""},
{" abc cde efg ", " ", " "}, {" abc cde efg ", " ", " "},
{"a'abc' c 'cde' cefg", " ", " abcd"},
{"'abc' abc 'cde'd 'efg'", " ", " abcd"},
}, tests2[] = { }, tests2[] = {
{"a, b, c", ",", " "}, {"a, b, c", ",", " "},
{"a,b,c", ",", " "}, {"a,b,c", ",", " "},
+23 -1
View File
@@ -1,4 +1,5 @@
/* /*
* Copyright (C) 2008 Tobias Brunner
* Copyright (C) 2007 Martin Willi * Copyright (C) 2007 Martin Willi
* Hochschule fuer Technik Rapperswil * Hochschule fuer Technik Rapperswil
* *
@@ -215,7 +216,25 @@ static bool enumerate_token_enum(token_enum_t *this, char **token)
} }
} }
/* find separators */ switch (*this->pos)
{
case '"':
case '\'':
{
/* read quoted token */
tmp = strchr(this->pos + 1, *this->pos);
if (tmp)
{
*token = this->pos + 1;
*tmp = '\0';
this->pos = tmp + 1;
return TRUE;
}
/* unterminated string, FALL-THROUGH */
}
default:
{
/* find nearest separator */
sep = this->sep; sep = this->sep;
while (*sep) while (*sep)
{ {
@@ -237,6 +256,9 @@ static bool enumerate_token_enum(token_enum_t *this, char **token)
last = TRUE; last = TRUE;
pos = this->pos = strchr(this->pos, '\0'); pos = this->pos = strchr(this->pos, '\0');
} }
break;
}
}
/* trim trailing characters/separators */ /* trim trailing characters/separators */
pos--; pos--;