tool.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. #include "portab.h"
  14. static char UNUSED id[] = "$Id: tool.c,v 1.3 2005/03/19 18:43:52 fw Exp $";
  15. #include "imp.h"
  16. #include <assert.h>
  17. #include <ctype.h>
  18. #include <stdio.h>
  19. #include <string.h>
  20. #include "exp.h"
  21. #include "tool.h"
  22. GLOBAL void
  23. ngt_TrimStr( char *String )
  24. {
  25. /* Mit ngt_TrimStr() werden fuehrende und folgende Leerzeichen,
  26. * Tabulatoren und Zeilenumbrueche (ASCII 10 und ASCII 13) aus
  27. * dem String entfernt. */
  28. char *start, *ptr;
  29. assert( String != NULL );
  30. start = String;
  31. /* Zeichen am Anfang pruefen ... */
  32. while(( *start == ' ' ) || ( *start == 9 )) start++;
  33. /* Zeichen am Ende pruefen ... */
  34. ptr = strchr( start, '\0' ) - 1;
  35. while((( *ptr == ' ' ) || ( *ptr == 9 ) || ( *ptr == 10 ) || ( *ptr == 13 )) && ptr >= start ) ptr--;
  36. *(++ptr) = '\0';
  37. memmove( String, start, strlen( start ) + 1 );
  38. } /* ngt_TrimStr */
  39. GLOBAL char *
  40. ngt_LowerStr( char *String )
  41. {
  42. /* String in Kleinbuchstaben konvertieren. Der uebergebene
  43. * Speicherbereich wird durch das Ergebnis ersetzt, zusaetzlich
  44. * wird dieser auch als Pointer geliefert. */
  45. char *ptr;
  46. assert( String != NULL );
  47. /* Zeichen konvertieren */
  48. ptr = String;
  49. while( *ptr )
  50. {
  51. *ptr = tolower( *ptr );
  52. ptr++;
  53. }
  54. return String;
  55. } /* ngt_LowerStr */
  56. GLOBAL void
  57. ngt_TrimLastChr( char *String, const char Chr)
  58. {
  59. /* If last character in the string matches Chr, remove it.
  60. * Empty strings are handled correctly. */
  61. unsigned int len;
  62. assert( String != NULL );
  63. len = strlen( String );
  64. if( len == 0 ) return;
  65. len--;
  66. if( String[len] == Chr ) String[len] = '\0';
  67. } /* ngt_TrimLastChr */
  68. /* -eof- */