src/aws/flb_aws_util.c
static char* replace_uri_tokens(const char* original_string, const char* current_word,
                         const char* new_word)
{
    char *result;
    int i = 0;
    int count = 0;
    int new_word_len = strlen(new_word);
    int old_word_len = strlen(current_word);

    for (i = 0; original_string[i] != '\0'; i++) {
        if (strstr(&original_string[i], current_word) == &original_string[i]) {
            count++;
            i += old_word_len - 1;
        }
    }

    result = flb_sds_create_size(i + count * (new_word_len - old_word_len) + 1);
    if (!result) {
        flb_errno();
        return NULL;
    }

    i = 0;
    while (*original_string) {
        if (strstr(original_string, current_word) == original_string) {
            strcpy(&result[i], new_word);
            i += new_word_len;
            original_string += old_word_len;
        }
        else
            result[i++] = *original_string++;
    }

    result[i] = '\0';
    return result;
}
/* Generic replace function for strings. */
Generic replace function for strings.
Generic replace function for strings .
static char* replace_uri_tokens(const char* original_string, const char* current_word,
                         const char* new_word)
{
    char *result;
    int i = 0;
    int count = 0;
    int new_word_len = strlen(new_word);
    int old_word_len = strlen(current_word);
    for (i = 0; original_string[i] != '\0'; i++) {
        if (strstr(&original_string[i], current_word) == &original_string[i]) {
            count++;
            i += old_word_len - 1;
        }
    }
    result = flb_sds_create_size(i + count * (new_word_len - old_word_len) + 1);
    if (!result) {
        flb_errno();
        return NULL;
    }
    i = 0;
    while (*original_string) {
        if (strstr(original_string, current_word) == original_string) {
            strcpy(&result[i], new_word);
            i += new_word_len;
            original_string += old_word_len;
        }
        else
            result[i++] = *original_string++;
    }
    result[i] = '\0';
    return result;
}
static char * replace_uri_tokens ( const char * original_string , const char * current_word , const char * new_word ) { char * result ; int i = 0 ; int count = 0 ; int new_word_len = strlen ( new_word ) ; int old_word_len = strlen ( current_word ) ; for ( i = 0 ; original_string [ i ] != ' \0 ' ; i ++ ) { if ( strstr ( & original_string [ i ] , current_word ) == & original_string [ i ] ) { count ++ ; i += old_word_len - 1 ; } } result = flb_sds_create_size ( i + count * ( new_word_len - old_word_len ) + 1 ) ; if ( ! result ) { flb_errno ( ) ; return NULL ; } i = 0 ; while ( * original_string ) { if ( strstr ( original_string , current_word ) == original_string ) { strcpy ( & result [ i ] , new_word ) ; i += new_word_len ; original_string += old_word_len ; } else result [ i ++ ] = * original_string ++ ; } result [ i ] = ' \0 ' ; return result ; }
Generic replace function for strings.
Generic replace function for strings .