2 * valerie_util.c -- General Purpose Client Utilities
3 * Copyright (C) 2002-2003 Ushodaya Enterprises Limited
4 * Author: Charles Yates <charles.yates@pandora.be>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 /* System header files */
25 /* Application header files */
26 #include "valerie_util.h"
28 /** Remove LF or CR/LF terminations from the input string.
31 char *valerie_util_chomp( char *input )
35 int length = strlen( input );
36 if ( length && input[ length - 1 ] == '\n' )
37 input[ length - 1 ] = '\0';
38 if ( length > 1 && input[ length - 2 ] == '\r' )
39 input[ length - 2 ] = '\0';
44 /** Remove leading and trailing spaces from the input string.
47 char *valerie_util_trim( char *input )
51 int length = strlen( input );
53 while( first < length && isspace( input[ first ] ) )
55 memmove( input, input + first, length - first + 1 );
56 length = length - first;
57 while ( length > 0 && isspace( input[ length - 1 ] ) )
58 input[ -- length ] = '\0';
63 /** Strip the specified string of leading and trailing 'value' (ie: ").
66 char *valerie_util_strip( char *input, char value )
70 char *ptr = strrchr( input, value );
73 if ( input[ 0 ] == value )
74 strcpy( input, input + 1 );