STRVEC.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #pragma once
  2. /* STRVEC.h
  3. *
  4. * Copyright (C) 1992-2018 Paul Boersma
  5. *
  6. * This code is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * This code is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. * See the GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this work. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. inline STRVEC STRVECfromTo (STRVEC strvec, integer fromIndex, integer toIndex) {
  20. integer offsetIndex = fromIndex - 1;
  21. Melder_assert (offsetIndex >= 0);
  22. Melder_assert (toIndex <= strvec.size);
  23. integer rangeSize = toIndex - offsetIndex;
  24. if (rangeSize <= 0) return STRVEC();
  25. return STRVEC (& strvec [offsetIndex], toIndex - offsetIndex);
  26. }
  27. inline constSTRVEC STRVECfromTo (constSTRVEC strvec, integer fromIndex, integer toIndex) {
  28. integer offsetIndex = fromIndex - 1;
  29. Melder_assert (offsetIndex >= 0);
  30. Melder_assert (toIndex <= strvec.size);
  31. integer rangeSize = toIndex - offsetIndex;
  32. if (rangeSize <= 0) return constSTRVEC();
  33. return constSTRVEC (& strvec [offsetIndex], rangeSize);
  34. }
  35. /*
  36. Regard a string as a sequence of tokens,
  37. separated (and perhaps preceded and followed) by white space.
  38. The tokens cannot contain spaces themselves (there are no escapes).
  39. */
  40. autostring32vector STRVECtokenize (conststring32 string);
  41. /* End of file STRVEC.h */