Annotation of libaitio/src/tools.c, revision 1.1.2.1
1.1.2.1 ! 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.4 2010/03/22 15:15:48 misho Exp $
! 7: *
! 8: *************************************************************************/
! 9: #include "global.h"
! 10: #include "aitio.h"
! 11:
! 12:
! 13: /*
! 14: * io_LTrimStr() Remove left whitespaces from text string
! 15: * @psLine = Text string
! 16: * return: 0 nothing to do; !=0 Removed bytes
! 17: */
! 18: inline int io_LTrimStr(u_char *psLine)
! 19: {
! 20: int pos = 0;
! 21: u_char *s;
! 22:
! 23: if (!psLine || !*psLine)
! 24: return 0;
! 25:
! 26: for (s = psLine; isspace(*s); s++);
! 27: pos = s - psLine;
! 28:
! 29: memmove(psLine, s, (strlen((char*) psLine) - pos) + 1);
! 30: return pos;
! 31: }
! 32:
! 33: /*
! 34: * io_RTrimStr() Remove right whitespaces from text string
! 35: * @psLine = Text string
! 36: * return: 0 nothing to do; !=0 Removed bytes
! 37: */
! 38: inline int io_RTrimStr(u_char *psLine)
! 39: {
! 40: u_char *t, *pos;
! 41:
! 42: if (!psLine || !*psLine)
! 43: return 0;
! 44:
! 45: pos = psLine + strlen((char*) psLine);
! 46: for (t = pos - 1; t > psLine && isspace(*t); t--);
! 47: *++t = 0;
! 48:
! 49: return pos - t;
! 50: }
! 51:
! 52: /*
! 53: * io_TrimStr() Remove left and right whitespaces from text string
! 54: * @psLine = Text string
! 55: * return: 0 nothing to do; !=0 Removed bytes
! 56: */
! 57: inline int io_TrimStr(u_char *psLine)
! 58: {
! 59: int ret = 0;
! 60:
! 61: ret = io_LTrimStr(psLine);
! 62: ret += io_RTrimStr(psLine);
! 63:
! 64: return ret;
! 65: }
! 66:
! 67: /*
! 68: * io_UnquotStr() Remove quots from input text string
! 69: * @psLine = Text string
! 70: * return: 0 nothing to do; 1 successful unquoted string
! 71: */
! 72: inline int io_UnquotStr(u_char *psLine)
! 73: {
! 74: char *pos, *str = NULL;
! 75: int flg;
! 76:
! 77: if (!psLine)
! 78: return 0;
! 79:
! 80: switch (*psLine) {
! 81: case '`':
! 82: case '"':
! 83: case '\'':
! 84: str = strdup((char*) psLine + 1);
! 85: for (pos = str, flg = 0; *pos; flg = ('\\' == *pos), pos++) {
! 86: if (!flg && *pos == *psLine) {
! 87: *pos = 0;
! 88: strlcpy((char*) psLine, str, strlen((char*) psLine) + 1);
! 89: break;
! 90: }
! 91: }
! 92: free(str);
! 93: return 1;
! 94: }
! 95:
! 96: return 0;
! 97: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>