]> arthur.barton.de Git - ngircd-alex.git/blob - src/tool/tool.c
Remove INT, LONG, BOOLEAN, STATIC, CONST, CHAR datatypes.
[ngircd-alex.git] / src / tool / tool.c
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  */
13
14
15 #include "portab.h"
16
17 static char UNUSED id[] = "$Id: tool.c,v 1.3 2005/03/19 18:43:52 fw 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 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. */
82
83         unsigned int len;
84
85         assert( String != NULL );
86
87         len = strlen( String );
88         if( len == 0 ) return;
89
90         len--;
91
92         if( String[len] == Chr ) String[len] = '\0';
93 } /* ngt_TrimLastChr */
94
95
96 /* -eof- */