2 0f3e84f4 2003-01-13 alex * ngIRCd -- The Next Generation IRC Daemon
3 39f1ddd9 2005-01-25 alex * Copyright (c)2001-2005 Alexander Barton (alex@barton.de)
5 0f3e84f4 2003-01-13 alex * This program is free software; you can redistribute it and/or modify
6 0f3e84f4 2003-01-13 alex * it under the terms of the GNU General Public License as published by
7 0f3e84f4 2003-01-13 alex * the Free Software Foundation; either version 2 of the License, or
8 0f3e84f4 2003-01-13 alex * (at your option) any later version.
9 0f3e84f4 2003-01-13 alex * Please read the file COPYING, README and AUTHORS for more information.
11 0f3e84f4 2003-01-13 alex * Tool functions
15 0f3e84f4 2003-01-13 alex #include "portab.h"
17 097c7bd7 2006-04-09 alex static char UNUSED id[] = "$Id: tool.c,v 1.6 2006/04/09 12:53:07 alex Exp $";
19 0f3e84f4 2003-01-13 alex #include "imp.h"
20 0f3e84f4 2003-01-13 alex #include <assert.h>
21 0f3e84f4 2003-01-13 alex #include <ctype.h>
22 0f3e84f4 2003-01-13 alex #include <stdio.h>
23 0f3e84f4 2003-01-13 alex #include <string.h>
25 0f3e84f4 2003-01-13 alex #include "exp.h"
26 0f3e84f4 2003-01-13 alex #include "tool.h"
30 cba92708 2006-03-22 alex * Removes all leading and trailing whitespaces of a string.
31 cba92708 2006-03-22 alex * @param String The string to remove whitespaces from.
34 cba92708 2006-03-22 alex ngt_TrimStr(char *String)
36 cba92708 2006-03-22 alex char *start, *end;
38 cba92708 2006-03-22 alex assert(String != NULL);
40 0f3e84f4 2003-01-13 alex start = String;
42 cba92708 2006-03-22 alex /* Remove whitespaces at the beginning of the string ... */
43 097c7bd7 2006-04-09 alex while (*start == ' ' || *start == '\t' ||
44 097c7bd7 2006-04-09 alex *start == '\n' || *start == '\r')
47 bebfbedf 2006-03-24 fw if (!*start) {
48 097c7bd7 2006-04-09 alex *String = '\0';
52 cba92708 2006-03-22 alex /* ... and at the end: */
53 cba92708 2006-03-22 alex end = strchr(start, '\0');
55 cba92708 2006-03-22 alex while ((*end == ' ' || *end == '\t' || *end == '\n' || *end == '\r')
56 097c7bd7 2006-04-09 alex && end >= start)
59 cba92708 2006-03-22 alex /* New trailing NULL byte */
60 cba92708 2006-03-22 alex *(++end) = '\0';
62 bebfbedf 2006-03-24 fw memmove(String, start, (size_t)(end - start)+1);
63 0f3e84f4 2003-01-13 alex } /* ngt_TrimStr */
67 8adff592 2005-03-19 fw ngt_LowerStr( char *String )
69 0f3e84f4 2003-01-13 alex /* String in Kleinbuchstaben konvertieren. Der uebergebene
70 0f3e84f4 2003-01-13 alex * Speicherbereich wird durch das Ergebnis ersetzt, zusaetzlich
71 0f3e84f4 2003-01-13 alex * wird dieser auch als Pointer geliefert. */
75 0f3e84f4 2003-01-13 alex assert( String != NULL );
77 0f3e84f4 2003-01-13 alex /* Zeichen konvertieren */
78 0f3e84f4 2003-01-13 alex ptr = String;
79 0f3e84f4 2003-01-13 alex while( *ptr )
81 0f3e84f4 2003-01-13 alex *ptr = tolower( *ptr );
85 0f3e84f4 2003-01-13 alex return String;
86 0f3e84f4 2003-01-13 alex } /* ngt_LowerStr */
90 8adff592 2005-03-19 fw ngt_TrimLastChr( char *String, const char Chr)
92 39f1ddd9 2005-01-25 alex /* If last character in the string matches Chr, remove it.
93 39f1ddd9 2005-01-25 alex * Empty strings are handled correctly. */
95 8adff592 2005-03-19 fw unsigned int len;
97 39f1ddd9 2005-01-25 alex assert( String != NULL );
99 39f1ddd9 2005-01-25 alex len = strlen( String );
100 39f1ddd9 2005-01-25 alex if( len == 0 ) return;
104 39f1ddd9 2005-01-25 alex if( String[len] == Chr ) String[len] = '\0';
105 39f1ddd9 2005-01-25 alex } /* ngt_TrimLastChr */
108 0f3e84f4 2003-01-13 alex /* -eof- */