+/* Initializes DST with the CNT characters from SRC starting at
+ position IDX. */
+void
+ds_init_substring (struct string *dst,
+ const struct string *src, size_t idx, size_t cnt)
+{
+ assert (dst != src);
+ ds_init (dst);
+ ds_assign_substring (dst, src, idx, cnt);
+}
+
+/* Copies SRC into DST.
+ DST and SRC may be the same string. */
+void
+ds_assign_string (struct string *dst, const struct string *src)
+{
+ ds_assign_buffer (dst, ds_data (src), ds_length (src));
+}
+
+/* Replaces DST by CNT characters from SRC starting at position
+ IDX.
+ DST and SRC may be the same string. */
+void
+ds_assign_substring (struct string *dst,
+ const struct string *src, size_t idx, size_t cnt)
+{
+ if (idx < src->length)
+ ds_assign_buffer (dst, src->string + idx, MIN (cnt, src->length - idx));
+ else
+ ds_clear (dst);
+}
+
+/* Replaces DST by the LENGTH characters in SRC.
+ SRC may be a substring within DST. */
+void
+ds_assign_buffer (struct string *dst, const char *src, size_t length)
+{
+ dst->length = length;
+ ds_extend (dst, length);
+ memmove (dst->string, src, length);
+}
+
+/* Replaces DST by null-terminated string SRC. SRC may overlap
+ with DST. */
+void
+ds_assign_c_str (struct string *dst, const char *src)
+{
+ ds_assign_buffer (dst, src, strlen (src));
+}
+