STRVEC.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /* STRVEC.cpp
  2. *
  3. * Copyright (C) 2006,2007,2009,2011,2012,2015-2018 Paul Boersma
  4. *
  5. * This code 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 (at
  8. * your option) any later version.
  9. *
  10. * This code is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. * See the GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this work. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include "melder.h"
  19. autostring32vector STRVECtokenize (conststring32 string) {
  20. if (! string)
  21. return autostring32vector(); // accept null pointer input
  22. integer n = NUMnumberOfTokens (string);
  23. if (n == 0)
  24. return autostring32vector();
  25. autostring32vector result (n);
  26. integer itoken = 0;
  27. const char32 *p = & string [0];
  28. for (;;) {
  29. Melder_skipHorizontalOrVerticalSpace (& p);
  30. if (*p == U'\0')
  31. break;
  32. const char32 *beginOfInk = p;
  33. p ++; // step over first nonspace
  34. p = Melder_findEndOfInk (p);
  35. integer numberOfCharacters = p - beginOfInk;
  36. autostring32 token (numberOfCharacters);
  37. str32ncpy (token.get(), beginOfInk, numberOfCharacters);
  38. result [++ itoken] = token.move();
  39. }
  40. return result;
  41. }
  42. /* End of file STRVEC.cpp */