Blob


1 /*
2 * ngIRCd -- The Next Generation IRC Daemon
3 * Copyright (c)2001-2005 Alexander Barton (alex@barton.de)
4 *
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.
10 *
11 * Tool functions
12 */
15 #include "portab.h"
17 static char UNUSED id[] = "$Id: tool.c,v 1.3 2005/03/19 18:43:52 fw Exp $";
19 #include "imp.h"
20 #include <assert.h>
21 #include <ctype.h>
22 #include <stdio.h>
23 #include <string.h>
25 #include "exp.h"
26 #include "tool.h"
29 GLOBAL void
30 ngt_TrimStr( char *String )
31 {
32 /* Mit ngt_TrimStr() werden fuehrende und folgende Leerzeichen,
33 * Tabulatoren und Zeilenumbrueche (ASCII 10 und ASCII 13) aus
34 * dem String entfernt. */
36 char *start, *ptr;
38 assert( String != NULL );
40 start = String;
42 /* Zeichen am Anfang pruefen ... */
43 while(( *start == ' ' ) || ( *start == 9 )) start++;
45 /* Zeichen am Ende pruefen ... */
46 ptr = strchr( start, '\0' ) - 1;
47 while((( *ptr == ' ' ) || ( *ptr == 9 ) || ( *ptr == 10 ) || ( *ptr == 13 )) && ptr >= start ) ptr--;
48 *(++ptr) = '\0';
50 memmove( String, start, strlen( start ) + 1 );
51 } /* ngt_TrimStr */
54 GLOBAL char *
55 ngt_LowerStr( char *String )
56 {
57 /* String in Kleinbuchstaben konvertieren. Der uebergebene
58 * Speicherbereich wird durch das Ergebnis ersetzt, zusaetzlich
59 * wird dieser auch als Pointer geliefert. */
61 char *ptr;
63 assert( String != NULL );
65 /* Zeichen konvertieren */
66 ptr = String;
67 while( *ptr )
68 {
69 *ptr = tolower( *ptr );
70 ptr++;
71 }
73 return String;
74 } /* ngt_LowerStr */
77 GLOBAL void
78 ngt_TrimLastChr( char *String, const char Chr)
79 {
80 /* If last character in the string matches Chr, remove it.
81 * Empty strings are handled correctly. */
83 unsigned int len;
85 assert( String != NULL );
87 len = strlen( String );
88 if( len == 0 ) return;
90 len--;
92 if( String[len] == Chr ) String[len] = '\0';
93 } /* ngt_TrimLastChr */
96 /* -eof- */