File:  [ELWIX - Embedded LightWeight unIX -] / libaitcfg / src / Attic / tools.c
Revision 1.2: download - view: text, annotated - select for diffs - revision graph
Wed Sep 9 09:07:31 2009 UTC (14 years, 9 months ago) by misho
Branches: MAIN
CVS tags: cfg3_2, cfg3_1, HEAD, CFG3_1, CFG3_0
prepare ver

    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.2 2009/09/09 09:07:31 misho Exp $
    7: *
    8: *************************************************************************/
    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>