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