2 * ngIRCd -- The Next Generation IRC Daemon
3 * Copyright (c)2001-2008 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.
23 #include <netinet/in.h>
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' ||
44 *start == '\n' || *start == '\r')
52 /* ... and at the end: */
53 end = strchr(start, '\0');
55 while ((*end == ' ' || *end == '\t' || *end == '\n' || *end == '\r')
59 /* New trailing NULL byte */
62 memmove(String, start, (size_t)(end - start)+1);
67 * Convert a string to uppercase letters.
70 ngt_UpperStr(char *String)
74 assert(String != NULL);
86 * Convert a string to lowercase letters.
89 ngt_LowerStr(char *String)
93 assert(String != NULL);
105 ngt_TrimLastChr( char *String, const char Chr)
107 /* If last character in the string matches Chr, remove it.
108 * Empty strings are handled correctly. */
112 assert( String != NULL );
114 len = strlen( String );
115 if( len == 0 ) return;
119 if( String[len] == Chr ) String[len] = '\0';
120 } /* ngt_TrimLastChr */