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.9 2008/02/26 22:04:18 fw Exp $";
25 #include <netinet/in.h>
32 * Removes all leading and trailing whitespaces of a string.
33 * @param String The string to remove whitespaces from.
36 ngt_TrimStr(char *String)
40 assert(String != NULL);
44 /* Remove whitespaces at the beginning of the string ... */
45 while (*start == ' ' || *start == '\t' ||
46 *start == '\n' || *start == '\r')
54 /* ... and at the end: */
55 end = strchr(start, '\0');
57 while ((*end == ' ' || *end == '\t' || *end == '\n' || *end == '\r')
61 /* New trailing NULL byte */
64 memmove(String, start, (size_t)(end - start)+1);
69 ngt_LowerStr( char *String )
71 /* String in Kleinbuchstaben konvertieren. Der uebergebene
72 * Speicherbereich wird durch das Ergebnis ersetzt, zusaetzlich
73 * wird dieser auch als Pointer geliefert. */
77 assert( String != NULL );
79 /* Zeichen konvertieren */
83 *ptr = tolower( *ptr );
92 ngt_TrimLastChr( char *String, const char Chr)
94 /* If last character in the string matches Chr, remove it.
95 * Empty strings are handled correctly. */
99 assert( String != NULL );
101 len = strlen( String );
102 if( len == 0 ) return;
106 if( String[len] == Chr ) String[len] = '\0';
107 } /* ngt_TrimLastChr */