Debian Codegraph @

melder/melder_sprint.h

raw
1 #ifndef _melder_sprint_h_
2 #define _melder_sprint_h_
3 /* melder_sprint.h
4 *
5 * Copyright (C) 1992-2018,2020,2022,2025 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 3 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
21 template <typename... Arg>
22 void Melder_sprint (mutablestring32 buffer, int64 bufferSize, const Arg... arg) {
23 const integer length = MelderArg__length (arg...);
24 if (length >= bufferSize) {
25 for (int64 i = 0; i < bufferSize; i ++)
26 buffer [i] = U'?';
27 if (bufferSize > 0)
28 buffer [bufferSize - 1] = U'\0';
29 return;
30 }
31 char32 *p = & buffer [0];
32 auto addOneStringElement = [& p] (conststring32 string) {
33 if (string) {
34 char32 *newEndOfStringLocation = stp32cpy (p, string);
35 p = newEndOfStringLocation;
36 }
37 };
38 (// fold
39 addOneStringElement (MelderArg { arg }. _arg)
40 , ...
41 );
42 }
43
44 /* End of file melder_sprint.h */
45 #endif