src/common/string.c
/**
 * Extract a portion of a string into a destination buffer using the supplied
 * start and end indices.
 *
 * If something is found, space is allocated for the resulting string and a null
 * terminator is added. The caller must free the result.
 *
 * If nothing is found or there was an error then the result will != NO_ERROR
 */
Extract a portion of a string into a destination buffer using the supplied
start and end indices.

If something is found, space is allocated for the resulting string and a null
terminator is added. The caller must free the result.

If nothing is found or there was an error then the result will != NO_ERROR
Extract a portion of a string into a destination buffer using the supplied start and end indices . If something is found space is allocated for the resulting string and a null terminator is added . The caller must free the result . If nothing is found or there was an error then the result will ! = NO_ERROR
enum natwm_error string_splice(const char *string, size_t start, size_t end, char **destination,
                               size_t *size)
{
        if (string == NULL || end < start || end > strlen(string)) {
                return INVALID_INPUT_ERROR;
        }
        size_t result_size = end - start;
        *destination = malloc(result_size + 1);
        if (*destination == NULL) {
                return MEMORY_ALLOCATION_ERROR;
        }
        memcpy(*destination, string + start, result_size);
        (*destination)[result_size] = '\0';
        SET_IF_NON_NULL(size, result_size);
        return NO_ERROR;
}
enum natwm_error string_splice ( const char * string , size_t start , size_t end , char * * destination , size_t * size ) { if ( string == NULL || end < start || end > strlen ( string ) ) { return INVALID_INPUT_ERROR ; } size_t result_size = end - start ; * destination = malloc ( result_size + 1 ) ; if ( * destination == NULL ) { return MEMORY_ALLOCATION_ERROR ; } memcpy ( * destination , string + start , result_size ) ; ( * destination ) [ result_size ] = ' \0 ' ; SET_IF_NON_NULL ( size , result_size ) ; return NO_ERROR ; }
Extract a portion of a string into a destination buffer using the supplied
 start and end indices.
Extract a portion of a string into a destination buffer using the supplied start and end indices .