2 * ngIRCd -- The Next Generation IRC Daemon
3 * Copyright (c)2001-2005 Alexander Barton (alex@barton.de)
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * Please read the file COPYING, README and AUTHORS for more information.
17 static char UNUSED id[] = "$Id: tool.c,v 1.5 2006/03/24 23:25:39 fw Exp $";
30 * Removes all leading and trailing whitespaces of a string.
31 * @param String The string to remove whitespaces from.
34 ngt_TrimStr(char *String)
38 assert(String != NULL);
42 /* Remove whitespaces at the beginning of the string ... */
43 while (*start == ' ' || *start == '\t')
50 /* ... and at the end: */
51 end = strchr(start, '\0');
53 while ((*end == ' ' || *end == '\t' || *end == '\n' || *end == '\r')
57 /* New trailing NULL byte */
60 memmove(String, start, (size_t)(end - start)+1);
65 ngt_LowerStr( char *String )
67 /* String in Kleinbuchstaben konvertieren. Der uebergebene
68 * Speicherbereich wird durch das Ergebnis ersetzt, zusaetzlich
69 * wird dieser auch als Pointer geliefert. */
73 assert( String != NULL );
75 /* Zeichen konvertieren */
79 *ptr = tolower( *ptr );
88 ngt_TrimLastChr( char *String, const char Chr)
90 /* If last character in the string matches Chr, remove it.
91 * Empty strings are handled correctly. */
95 assert( String != NULL );
97 len = strlen( String );
98 if( len == 0 ) return;
102 if( String[len] == Chr ) String[len] = '\0';
103 } /* ngt_TrimLastChr */