remove pic_make_str_fill

This commit is contained in:
Yuichi Nishiwaki 2015-07-13 09:03:32 +09:00
parent cbe5e81b28
commit 5635661b3c
3 changed files with 14 additions and 22 deletions

View File

@ -4,13 +4,16 @@ void
pic_str_set(pic_state *pic, pic_str *str, size_t i, char c) pic_str_set(pic_state *pic, pic_str *str, size_t i, char c)
{ {
pic_str *x, *y, *z, *tmp; pic_str *x, *y, *z, *tmp;
char buf[1];
if (pic_str_len(str) <= i) { if (pic_str_len(str) <= i) {
pic_errorf(pic, "index out of range %d", i); pic_errorf(pic, "index out of range %d", i);
} }
buf[0] = c;
x = pic_str_sub(pic, str, 0, i); x = pic_str_sub(pic, str, 0, i);
y = pic_make_str_fill(pic, 1, c); y = pic_make_str(pic, buf, 1);
z = pic_str_sub(pic, str, i + 1, pic_str_len(str)); z = pic_str_sub(pic, str, i + 1, pic_str_len(str));
tmp = pic_str_cat(pic, x, pic_str_cat(pic, y, z)); tmp = pic_str_cat(pic, x, pic_str_cat(pic, y, z));

View File

@ -22,7 +22,6 @@ void pic_rope_decref(pic_state *, struct pic_rope *);
pic_str *pic_make_str(pic_state *, const char * /* nullable */, size_t); pic_str *pic_make_str(pic_state *, const char * /* nullable */, size_t);
pic_str *pic_make_str_cstr(pic_state *, const char *); pic_str *pic_make_str_cstr(pic_state *, const char *);
pic_str *pic_make_str_fill(pic_state *, size_t, char);
char pic_str_ref(pic_state *, pic_str *, size_t); char pic_str_ref(pic_state *, pic_str *, size_t);
size_t pic_str_len(pic_str *); size_t pic_str_len(pic_str *);

View File

@ -240,25 +240,6 @@ pic_make_str_cstr(pic_state *pic, const char *cstr)
return pic_make_str(pic, cstr, strlen(cstr)); return pic_make_str(pic, cstr, strlen(cstr));
} }
pic_str *
pic_make_str_fill(pic_state *pic, size_t len, char fill)
{
size_t i;
char *buf = pic_malloc(pic, len);
pic_str *str;
for (i = 0; i < len; ++i) {
buf[i] = fill;
}
buf[i] = '\0';
str = pic_make_str(pic, buf, len);
pic_free(pic, buf);
return str;
}
size_t size_t
pic_str_len(pic_str *str) pic_str_len(pic_str *str)
{ {
@ -474,7 +455,16 @@ pic_str_make_string(pic_state *pic)
pic_get_args(pic, "k|c", &len, &c); pic_get_args(pic, "k|c", &len, &c);
return pic_obj_value(pic_make_str_fill(pic, len, c)); {
size_t i;
char buf[len];
for (i = 0; i < len; ++i) {
buf[i] = c;
}
return pic_obj_value(pic_make_str(pic, buf, len));
}
} }
static pic_value static pic_value