Skip to content

Commit

Permalink
[PATCH] strstrip() API
Browse files Browse the repository at this point in the history
Add a new strstrip() function to lib/string.c for removing leading and
trailing whitespace from a string.

Cc: Michael Holzheu <[email protected]>
Acked-by: Ingo Oeser <[email protected]>
Acked-by: Joern Engel <[email protected]>
Cc: Corey Minyard <[email protected]>
Signed-off-by: Pekka Enberg <[email protected]>
Acked-by: Michael Holzheu <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Pekka Enberg authored and Linus Torvalds committed Jun 23, 2006
1 parent 3fa2164 commit 481fad4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/linux/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ extern char * strnchr(const char *, size_t, int);
#ifndef __HAVE_ARCH_STRRCHR
extern char * strrchr(const char *,int);
#endif
extern char * strstrip(char *);
#ifndef __HAVE_ARCH_STRSTR
extern char * strstr(const char *,const char *);
#endif
Expand Down
30 changes: 30 additions & 0 deletions lib/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,36 @@ char *strnchr(const char *s, size_t count, int c)
EXPORT_SYMBOL(strnchr);
#endif

/**
* strstrip - Removes leading and trailing whitespace from @s.
* @s: The string to be stripped.
*
* Note that the first trailing whitespace is replaced with a %NUL-terminator
* in the given string @s. Returns a pointer to the first non-whitespace
* character in @s.
*/
char *strstrip(char *s)
{
size_t size;
char *end;

size = strlen(s);

if (!size)
return s;

end = s + size - 1;
while (end != s && isspace(*end))
end--;
*(end + 1) = '\0';

while (*s && isspace(*s))
s++;

return s;
}
EXPORT_SYMBOL(strstrip);

#ifndef __HAVE_ARCH_STRLEN
/**
* strlen - Find the length of a string
Expand Down

0 comments on commit 481fad4

Please sign in to comment.