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"
|
|
|
|
|
|
|
|
void trim(char *s)
|
|
|
|
{
|
2005-09-01 15:53:57 +05:30
|
|
|
size_t len = strlen(s);
|
|
|
|
size_t lws;
|
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) {
|
2005-09-01 15:53:57 +05:30
|
|
|
lws = strspn(s, " \n\r\t\v");
|
2007-10-30 00:52:13 +05:30
|
|
|
if (lws) {
|
|
|
|
len -= lws;
|
|
|
|
memmove(s, s + lws, len);
|
|
|
|
}
|
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
|
|
|
}
|