On Fri, Oct 31, 2014 at 11:56:08AM +0100, Emeric Brun wrote:
> In your case, you don't need to modify data so i think the most
> elegant(zerocopy) way to do this converter is to not use smp_dup:
>
> You only need to do a manual parsing to reach your token based on string
> length and not char '0'. You only need to make smp->data.str.str point
> on the start of the wanted field, and to set smp->data.str.len to the
> appropriate value.
Absolutely. The following simple code works fine and does not touch the
input contents, feel free to adapt it to work with args and chunks :
void field(const char *str, int f, const char *sep, const char **beg, int *len)
{
const char *s;
const char *end;
while (*str) {
/* look for first character not a delimiter */
for (s = sep; *s; s++) {
if (*str == *s)
goto next_delim;
}
/* look for first delimiter */
for (end = str + 1; *end; end++) {
for (s = sep; *s; s++) {
if (*end == *s)
goto first_delim;
}
}
first_delim:
/* we have the word between <str> and <end> */
if (--f <= 0) {
*beg = str;
*len = (end - str);
return;
}
str = end;
next_delim:
str++;
}
*beg = NULL;
*len = 0;
}
Regards,
Willy