From: Ben Pfaff Date: Mon, 1 Aug 2022 04:18:21 +0000 (-0700) Subject: str: New function ds_put_substring_multiple(). X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?p=pspp;a=commitdiff_plain;h=32538f9f35aee7145a49971f9dae1394a1a201b5 str: New function ds_put_substring_multiple(). --- diff --git a/src/libpspp/str.c b/src/libpspp/str.c index 3046daee6d..811674225c 100644 --- a/src/libpspp/str.c +++ b/src/libpspp/str.c @@ -1677,6 +1677,18 @@ ds_put_unichar (struct string *st, ucs4_t uc) st->ss.length += u8_uctomb (CHAR_CAST (uint8_t *, ds_end (st)), uc, 6); } +/* Appends N copies of S to ST. */ +void +ds_put_substring_multiple (struct string *dst, struct substring src, size_t n) +{ + char *p = ds_put_uninit (dst, n * src.length); + for (size_t i = 0; i < n; i++) + { + memcpy (p, src.string, src.length); + p += src.length; + } +} + /* If relocation has been enabled, replace ST, with its relocated version */ void diff --git a/src/libpspp/str.h b/src/libpspp/str.h index 9c20cfba65..91de05f395 100644 --- a/src/libpspp/str.h +++ b/src/libpspp/str.h @@ -240,6 +240,7 @@ void ds_put_byte_multiple (struct string *, int ch, size_t); void ds_put_unichar (struct string *, ucs4_t uc); void ds_put_cstr (struct string *, const char *); void ds_put_substring (struct string *, struct substring); +void ds_put_substring_multiple (struct string *, struct substring, size_t n); void ds_put_vformat (struct string *st, const char *, va_list) PRINTF_FORMAT (2, 0); void ds_put_c_vformat (struct string *st, const char *, va_list)