]> arthur.barton.de Git - ngircd-alex.git/blob - src/ngircd/tool.c
440fcb4b235a0a315bd44dea1ee28e40cf242b74
[ngircd-alex.git] / src / ngircd / tool.c
1 /*
2  * ngIRCd -- The Next Generation IRC Daemon
3  * Copyright (c)2001,2002 by 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  */
13
14
15 #include "portab.h"
16
17 static char UNUSED id[] = "$Id: tool.c,v 1.10 2002/12/12 12:24:18 alex Exp $";
18
19 #include "imp.h"
20 #include <assert.h>
21 #include <ctype.h>
22 #include <stdio.h>
23 #include <string.h>
24
25 #include "exp.h"
26 #include "tool.h"
27
28
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. */
35         
36         CHAR *start, *ptr;
37
38         assert( String != NULL );
39
40         start = String;
41         
42         /* Zeichen am Anfang pruefen ... */
43         while(( *start == ' ' ) || ( *start == 9 )) start++;
44         
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';
49
50         memmove( String, start, strlen( start ) + 1 );
51 } /* ngt_TrimStr */
52
53
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. */
60
61         CHAR *ptr;
62
63         assert( String != NULL );
64
65         /* Zeichen konvertieren */
66         ptr = String;
67         while( *ptr )
68         {
69                 *ptr = tolower( *ptr );
70                 ptr++;
71         }
72         
73         return String;
74 } /* ngt_LowerStr */
75
76
77 /* -eof- */