MCPcopy Create free account
hub / github.com/alibaba/zvec / zvec_string_array_add

Function zvec_string_array_add

src/binding/c/c_api.cc:994–1005  ·  view source on GitHub ↗

* @brief Add a string to string array at specified index * @param array String array to add to * @param idx Index to add at * @param str String to add */

Source from the content-addressed store, hash-verified

992 * @param str String to add
993 */
994void zvec_string_array_add(zvec_string_array_t *array, size_t idx,
995 const char *str) {
996 if (!array || !str) return;
997 if (idx >= array->count) return;
998 size_t len = strlen(str);
999 char *buf = (char *)malloc(len + 1);
1000 if (!buf) return;
1001 memcpy(buf, str, len + 1);
1002 array->strings[idx].data = buf;
1003 array->strings[idx].length = len;
1004 array->strings[idx].capacity = len + 1;
1005}
1006
1007/**
1008 * @brief Destroy a string array and free all memory

Calls

no outgoing calls

Tested by 2