strip.c 902 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*!
  2. \file lib/db/dbmi_base/strip.c
  3. \brief DBMI Library (base) - strip strings
  4. (C) 1999-2009, 2011 by the GRASS Development Team
  5. This program is free software under the GNU General Public License
  6. (>=v2). Read the file COPYING that comes with GRASS for details.
  7. \author Joel Jones (CERL/UIUC), Radim Blazek
  8. \author Doxygenized by Martin Landa <landa.martin gmail.com> (2011)
  9. */
  10. #include <grass/dbmi.h>
  11. /*!
  12. \brief Strip given string
  13. 'buf' is rewritten in place with leading and trailing white
  14. space removed.
  15. \param buf string buffer
  16. */
  17. void db_strip(char *buf)
  18. {
  19. char *a, *b;
  20. /* remove leading white space */
  21. for (a = b = buf; *a == ' ' || *a == '\t'; a++) ;
  22. if (a != b)
  23. while ((*b++ = *a++)) ;
  24. /* remove trailing white space */
  25. for (a = buf; *a; a++) ;
  26. if (a != buf) {
  27. for (a--; *a == ' ' || *a == '\t'; a--) ;
  28. a++;
  29. *a = 0;
  30. }
  31. }