Hi Ingo,
Ingo Oeser <[email protected]> wrote on 04/22/2006 12:30:28 AM:
>
> Nearly.
>
> - Just return the *ptr and let the caller modify the string.
> - Take a string with characters to reject
>
> Reasons:
> - string might be read only
> - caller wants to copy it anyway
> - string might be a substring or sth. we like to parse further
> - Symmetry with strchr()
>
> Otherwise it is a very good idea implemented in a patch similiar to this
> untested one below against Linus' current tree.
>
> use case would be:
> char *s = strltrim(string, " \t");
> char *e = strrtrim(s, " \t\n\r");
> *e = '\0';
I agree that it is a good idea to specify the characters to
reject, but I would like to use the function without having an
additional local pointer variable. In my opinion this
functionality is enough for most cases.
What about something like that:
/**
* strrtrim - Remove trailing characters specified in @reject
* @s: The string to be searched
* @reject: The string of letters to avoid
*/
static inline void strrtrim(char *s, const char *reject)
{
char *p;
const char *r;
for (p = s + strlen(s) - 1; s <= p; p--) {
for (r = reject; (*r != '\0') && (*p != *r); r++)
/* nothing */;
if (*r == '\0')
break;
}
*(p + 1) = '\0';
}
Regards
Michael
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[Index of Archives]
[Kernel Newbies]
[Netfilter]
[Bugtraq]
[Photo]
[Stuff]
[Gimp]
[Yosemite News]
[MIPS Linux]
[ARM Linux]
[Linux Security]
[Linux RAID]
[Video 4 Linux]
[Linux for the blind]
[Linux Resources]