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, 8 months ago) by misho
Branches: MAIN
CVS tags: cfg3_2, cfg3_1, HEAD, CFG3_1, CFG3_0
prepare ver

/*************************************************************************
* (C) 2008 AITNET ltd - Sofia/Bulgaria - <misho@aitbg.com>
*  by Michael Pounov <misho@openbsd-bg.org>
*
* $Author: misho $
* $Id: tools.c,v 1.2 2009/09/09 09:07:31 misho Exp $
*
*************************************************************************/
#include "global.h"
#include "aitcfg.h"
#include "tools.h"

#pragma GCC visibility push(hidden)

// ltrim() Left trim whitespaces
inline int ltrim(u_char *psLine)
{
	int pos = 0;

	if (!psLine)
		return 0;
	pos = strspn((char*) psLine, " \t\r\n");
	if (!pos)
		return 0;

	memmove(psLine, psLine + pos, strlen((char*) psLine));
	return pos;
}

// rtrim() Right trim whitespaces
inline int rtrim(u_char *psLine)
{
	int i, pos = 0;

	if (!psLine)
		return 0;
	for (i = strlen((char*) psLine); i; i--) {
		switch (psLine[i - 1]) {
			case ' ':
			case '\t':
			case '\r':
			case '\n':
				psLine[i - 1] = 0;
				pos++;
				continue;
		}
		break;
	}

	return pos;
}

#pragma GCC visibility pop

// trim() Triming all whitespaces both left/right
inline int trim(u_char *psLine)
{
	int ret = 0;

	ret = ltrim(psLine);
	ret += rtrim(psLine);

	return ret;
}

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>