Annotation of libaitcfg/src/tools.c, revision 1.2.4.1
1.2 misho 1: /*************************************************************************
2: * (C) 2008 AITNET ltd - Sofia/Bulgaria - <misho@aitbg.com>
3: * by Michael Pounov <misho@openbsd-bg.org>
4: *
5: * $Author: misho $
1.2.4.1 ! misho 6: * $Id: tools.c,v 1.2 2009/09/09 09:07:31 misho Exp $
1.2 misho 7: *
8: *************************************************************************/
1.1 misho 9: #include "global.h"
10: #include "aitcfg.h"
11: #include "tools.h"
12:
13: #pragma GCC visibility push(hidden)
14:
15: // ltrim() Left trim whitespaces
16: inline int ltrim(u_char *psLine)
17: {
18: int pos = 0;
19:
20: if (!psLine)
21: return 0;
22: pos = strspn((char*) psLine, " \t\r\n");
23: if (!pos)
24: return 0;
25:
26: memmove(psLine, psLine + pos, strlen((char*) psLine));
27: return pos;
28: }
29:
30: // rtrim() Right trim whitespaces
31: inline int rtrim(u_char *psLine)
32: {
1.2.4.1 ! misho 33: register int i;
! 34: int pos = 0;
1.1 misho 35:
36: if (!psLine)
37: return 0;
1.2.4.1 ! misho 38: for (i = strlen((char*) psLine) - 1; i; i--) {
! 39: switch (psLine[i]) {
1.1 misho 40: case ' ':
41: case '\t':
42: case '\r':
43: case '\n':
1.2.4.1 ! misho 44: psLine[i] = 0;
1.1 misho 45: pos++;
46: continue;
47: }
48: break;
49: }
50:
51: return pos;
52: }
53:
54: #pragma GCC visibility pop
55:
56: // trim() Triming all whitespaces both left/right
57: inline int trim(u_char *psLine)
58: {
59: int ret = 0;
60:
61: ret = ltrim(psLine);
62: ret += rtrim(psLine);
63:
64: return ret;
65: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>