fix xr_put
This commit is contained in:
parent
4501b9bd93
commit
3ee807a347
13
src/string.c
13
src/string.c
|
@ -74,28 +74,29 @@ pic_str_ref(pic_state *pic, pic_str *str, size_t i)
|
||||||
static xrope *
|
static xrope *
|
||||||
xr_put(xrope *rope, size_t i, char c)
|
xr_put(xrope *rope, size_t i, char c)
|
||||||
{
|
{
|
||||||
xrope *x, *y;
|
xrope *x, *y, *z;
|
||||||
char buf[1];
|
char buf[2];
|
||||||
|
|
||||||
if (xr_len(rope) <= i) {
|
if (xr_len(rope) <= i) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
buf[0] = c;
|
buf[0] = c;
|
||||||
|
buf[1] = '\0';
|
||||||
|
|
||||||
x = xr_sub(rope, 0, i);
|
x = xr_sub(rope, 0, i);
|
||||||
y = xr_new_copy(buf, 1);
|
y = xr_new_copy(buf, 1);
|
||||||
rope = xr_cat(x, y);
|
z = xr_cat(x, y);
|
||||||
XROPE_DECREF(x);
|
XROPE_DECREF(x);
|
||||||
XROPE_DECREF(y);
|
XROPE_DECREF(y);
|
||||||
|
|
||||||
x = rope;
|
x = z;
|
||||||
y = xr_sub(rope, i + 1, xr_len(rope));
|
y = xr_sub(rope, i + 1, xr_len(rope));
|
||||||
rope = xr_cat(x, y);
|
z = xr_cat(z, y);
|
||||||
XROPE_DECREF(x);
|
XROPE_DECREF(x);
|
||||||
XROPE_DECREF(y);
|
XROPE_DECREF(y);
|
||||||
|
|
||||||
return rope;
|
return z;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
Loading…
Reference in New Issue