cstring · Section 3
cstring_replace
NAME
cstring_replace - replace every non-overlapping occurrence of needle
LIBRARY
C Collections (libccollections, -lccollections)
SYNOPSIS
#include <ccollections/cstring.h>
ccol_retval cstring_replace(cstr s, const char *needle,
const char *replacement);
DESCRIPTION
This function replaces every non-overlapping occurrence of needle in s with replacement. It builds the result in a fresh buffer and swaps that buffer in, so replacement may contain needle without any risk of an endless loop. When needle is not found the call succeeds and s does not change.
PARAMETERS
s String to change needle Substring to search for (must not be NULL or empty) replacement Substitute string (must not be NULL)
RETURN VALUE
ccol_success - The replace succeeded, also when needle was
not found
ccol_invalid_args - needle is NULL or empty, or replacement is NULL
ccol_container_full - The result would overflow a size_t
ccol_not_enough_memory - The buffer allocation failed
NOTES
Matches never overlap, and the search goes from left to right Asserts if s is NULL