melder_sprint.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #ifndef _melder_sprint_h_
  2. #define _melder_sprint_h_
  3. /* melder_sprint.h
  4. *
  5. * Copyright (C) 1992-2018 Paul Boersma
  6. *
  7. * This code is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * This code is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. * See the GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this work. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. inline static void _recursiveTemplate_Melder_sprint (char32 **inout_pointer, const MelderArg& arg) {
  21. if (arg._arg) {
  22. char32 *newEndOfStringLocation = stp32cpy (*inout_pointer, arg._arg);
  23. *inout_pointer = newEndOfStringLocation;
  24. }
  25. }
  26. template <typename... Args>
  27. void _recursiveTemplate_Melder_sprint (char32 **inout_pointer, const MelderArg& first, Args... rest) {
  28. _recursiveTemplate_Melder_sprint (inout_pointer, first);
  29. _recursiveTemplate_Melder_sprint (inout_pointer, rest...);
  30. }
  31. template <typename... Args>
  32. void Melder_sprint (mutablestring32 buffer, int64 bufferSize, const MelderArg& first, Args... rest) {
  33. integer length = MelderArg__length (first, rest...);
  34. if (length >= bufferSize) {
  35. for (int64 i = 0; i < bufferSize; i ++)
  36. buffer [i] = U'?';
  37. if (bufferSize > 0)
  38. buffer [bufferSize - 1] = U'\0';
  39. return;
  40. }
  41. char32 *p = & buffer [0];
  42. _recursiveTemplate_Melder_sprint (& p, first, rest...);
  43. }
  44. /* End of file melder_sprint.h */
  45. #endif