mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-14 17:45:04 +00:00
Backport from xs.
This commit is contained in:
parent
c8d535a154
commit
a1d083ff27
2 changed files with 7 additions and 5 deletions
10
xs.h
10
xs.h
|
@ -449,16 +449,18 @@ xs_str *xs_replace_in(xs_str *str, const char *sfrom, const char *sto, int times
|
|||
|
||||
int sfsz = strlen(sfrom);
|
||||
int stsz = strlen(sto);
|
||||
int diff = stsz - sfsz;
|
||||
char *ss;
|
||||
int offset = 0;
|
||||
|
||||
while (times > 0 && (ss = strstr(str + offset, sfrom)) != NULL) {
|
||||
int n_offset = ss - str;
|
||||
|
||||
if (sfsz != stsz) {
|
||||
str = xs_collapse(str, n_offset, sfsz);
|
||||
str = xs_expand(str, n_offset, stsz);
|
||||
}
|
||||
if (diff < 0)
|
||||
str = xs_collapse(str, n_offset, -diff);
|
||||
else
|
||||
if (diff > 0)
|
||||
str = xs_expand(str, n_offset, diff);
|
||||
|
||||
memcpy(str + n_offset, sto, stsz);
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
/* 0efaa0cfce82c0f8f7bde81359a2c55a41928af3 */
|
||||
/* 5b007ed034f8598be964d72f5becf24b379a7dd8 */
|
||||
|
|
Loading…
Reference in a new issue