str: New function ds_put_substring_multiple().
authorBen Pfaff <blp@cs.stanford.edu>
Mon, 1 Aug 2022 04:18:21 +0000 (21:18 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Sun, 7 Aug 2022 16:53:13 +0000 (09:53 -0700)
src/libpspp/str.c
src/libpspp/str.h

index 3046daee6d1bc4390b7793bacd2ada894ef83bb7..811674225c23c9f0f8f757bab266ccae662b7c38 100644 (file)
@@ -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
index 9c20cfba6553551572487ec151cfb026f329eaca..91de05f395264f2d3231ef9d23c82eda9788602f 100644 (file)
@@ -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)