Annotation of libaitcfg/src/tools.c, revision 1.2
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 $
! 6: * $Id: tools.c,v 1.1.1.1.2.1 2008/09/30 20:00:26 misho Exp $
! 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: {
33: int i, pos = 0;
34:
35: if (!psLine)
36: return 0;
37: for (i = strlen((char*) psLine); i; i--) {
38: switch (psLine[i - 1]) {
39: case ' ':
40: case '\t':
41: case '\r':
42: case '\n':
43: psLine[i - 1] = 0;
44: pos++;
45: continue;
46: }
47: break;
48: }
49:
50: return pos;
51: }
52:
53: #pragma GCC visibility pop
54:
55: // trim() Triming all whitespaces both left/right
56: inline int trim(u_char *psLine)
57: {
58: int ret = 0;
59:
60: ret = ltrim(psLine);
61: ret += rtrim(psLine);
62:
63: return ret;
64: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>