lkml.org 
[lkml]   [2006]   [Apr]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH/RFC] s390: Hypervisor File System
From
Date
Hi Ingo,

Ingo Oeser <ioe-lkml@rameria.de> 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 majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2006-04-24 19:19    [W:0.065 / U:0.216 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site