2001-03-17 04:17:14 +05:30
|
|
|
/* vi: set sw=4 ts=4: */
|
|
|
|
/*
|
|
|
|
* Utility routines.
|
|
|
|
*
|
2004-03-15 13:59:22 +05:30
|
|
|
* Copyright (C) many different people.
|
2003-07-15 02:51:08 +05:30
|
|
|
* If you wrote this, please acknowledge your work.
|
2001-03-17 04:17:14 +05:30
|
|
|
*
|
2006-05-20 00:59:19 +05:30
|
|
|
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
2001-03-17 04:17:14 +05:30
|
|
|
*/
|
|
|
|
|
|
|
|
#include "libbb.h"
|
|
|
|
|
2008-06-27 08:22:20 +05:30
|
|
|
void FAST_FUNC trim(char *s)
|
2001-03-17 04:17:14 +05:30
|
|
|
{
|
2005-09-01 15:53:57 +05:30
|
|
|
size_t len = strlen(s);
|
2001-04-23 22:34:41 +05:30
|
|
|
|
2001-03-17 04:17:14 +05:30
|
|
|
/* trim trailing whitespace */
|
2007-10-30 00:52:13 +05:30
|
|
|
while (len && isspace(s[len-1]))
|
|
|
|
--len;
|
2001-03-17 04:17:14 +05:30
|
|
|
|
|
|
|
/* trim leading whitespace */
|
2007-04-12 06:02:05 +05:30
|
|
|
if (len) {
|
2009-10-23 01:58:08 +05:30
|
|
|
char *nws = skip_whitespace(s);
|
|
|
|
if ((nws - s) != 0) {
|
|
|
|
len -= (nws - s);
|
|
|
|
memmove(s, nws, len);
|
2007-10-30 00:52:13 +05:30
|
|
|
}
|
2005-09-01 15:53:57 +05:30
|
|
|
}
|
2007-04-12 06:02:05 +05:30
|
|
|
s[len] = '\0';
|
2001-03-17 04:17:14 +05:30
|
|
|
}
|