blob: 9afcfd507bb973138228418d93133cc93fe16cea (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
/*
* Portable string trimming routines.
* $Id$
* Copyright (c) 1997 by Tycho Softworks.
* For conditions of distribution and reuse see product license.
*/
#include <other/string.h>
char *strtrim(char *str, const char *trim)
{
return strltrim(strrtrim(str, trim), trim);
}
char *strrtrim(char *str, const char *trim)
{
char *end;
if(!str)
return NULL;
end = str + strlen(str);
while(end-- > str)
{
if(!strchr(trim, *end))
return str;
*end = 0;
}
return str;
}
char *strltrim(char *str, const char *trim)
{
if(!str)
return NULL;
while(*str)
{
if(!strchr(trim, *str))
return str;
++str;
}
return str;
}
|