mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-13 18:17:39 -04:00
misc.c split_string replace with strtok_r
there isn't much difference from this function to strtok_r now places a NULL in the last vector space permitting as well Change-Id: Ibaaa1ad01b5054c41a6410788a2333b8d11a7cf7
This commit is contained in:
parent
3ad8c0ad7b
commit
28af87526d
1 changed files with 6 additions and 10 deletions
16
apps/misc.c
16
apps/misc.c
|
@ -1384,20 +1384,16 @@ void format_time(char* buf, int buf_size, long t)
|
|||
int split_string(char *str, const char split_char, char *vector[], const int vector_length)
|
||||
{
|
||||
int i;
|
||||
char *p = str;
|
||||
|
||||
/* skip leading splitters */
|
||||
while(*p == split_char) p++;
|
||||
char sep[2] = {split_char, '\0'};
|
||||
char *e, *p = strtok_r(str, sep, &e);
|
||||
|
||||
/* *p in the condition takes care of trailing splitters */
|
||||
for(i = 0; p && *p && i < vector_length; i++)
|
||||
for(i = 0; i < vector_length; i++)
|
||||
{
|
||||
vector[i] = p;
|
||||
if ((p = strchr(p, split_char)))
|
||||
{
|
||||
*p++ = '\0';
|
||||
while(*p == split_char) p++; /* skip successive splitters */
|
||||
}
|
||||
if (!p)
|
||||
break;
|
||||
p = strtok_r(NULL, sep, &e);
|
||||
}
|
||||
|
||||
return i;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue