* Replace all occurrences of a string in a StringInfo with a different string. */
| 362 | * Replace all occurrences of a string in a StringInfo with a different string. |
| 363 | */ |
| 364 | void |
| 365 | replaceStringInfoString(StringInfo str, char *replace, char *replacement) |
| 366 | { |
| 367 | char *ptr; |
| 368 | |
| 369 | while ((ptr = strstr(str->data, replace)) != NULL) |
| 370 | { |
| 371 | char *dup = pstrdup(str->data); |
| 372 | |
| 373 | resetStringInfo(str); |
| 374 | appendBinaryStringInfo(str, dup, ptr - str->data); |
| 375 | appendStringInfoString(str, replacement); |
| 376 | appendStringInfoString(str, dup + (ptr - str->data) + strlen(replace)); |
| 377 | pfree(dup); |
| 378 | } |
| 379 | } |
no test coverage detected