MCPcopy Create free account
hub / github.com/KaisenAmin/c_std / string_reverse

Function string_reverse

string/std_string.c:815–836  ·  view source on GitHub ↗

* @brief Reverses the characters in the String object. * * This function reverses the order of characters in the String object. * It allocates memory for the reversed string, replaces the original string with the reversed one, and frees the temporary memory. * * @param str The String object to reverse. Must not be NULL. */

Source from the content-addressed store, hash-verified

813 STRING_LOG("[string_insert]: Error - invalid arguments.\n");
814 return;
815 }
816 size_t n = strlen(strItem);
817 if (n == 0) {
818 return;
819 }
820 /* strItem may point into this String: work from its offset, which stays
821 valid when the buffer moves */
822 size_t off = sstr_alias_offset(str, strItem);
823 if (n >= str->capacitySize - str->size && !stringbuf_grow_for(str, n)) {
824 STRING_LOG("[string_insert]: Error - Memory allocation failed.\n");
825 return;
826 }
827 char* base = str->dataStr;
828 memmove(base + pos + n, base + pos, str->size - pos + 1); /* tail + terminator */
829 if (off == SIZE_MAX) {
830 memcpy(base + pos, strItem, n);
831 }
832 else if (off + n <= pos) {
833 memcpy(base + pos, base + off, n); /* source before the gap: unmoved */
834 }
835 else if (off >= pos) {
836 memcpy(base + pos, base + off + n, n); /* source moved right by n */
837 }
838 else {
839 /* source straddles pos: its head stayed, its tail moved by n */

Callers

nothing calls this directly

Calls 2

string_replaceFunction · 0.85
string_c_strFunction · 0.85

Tested by

no test coverage detected