3
0

trim.c 517 B

123456789101112131415161718192021222324252627
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Utility routines.
  4. *
  5. * Copyright (C) many different people.
  6. * If you wrote this, please acknowledge your work.
  7. *
  8. * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
  9. */
  10. #include "libbb.h"
  11. void trim(char *s)
  12. {
  13. size_t len = strlen(s);
  14. size_t lws;
  15. /* trim trailing whitespace */
  16. while (len && isspace(s[len-1])) --len;
  17. /* trim leading whitespace */
  18. if (len) {
  19. lws = strspn(s, " \n\r\t\v");
  20. memmove(s, s + lws, len -= lws);
  21. }
  22. s[len] = '\0';
  23. }