diff --git a/include/picrin.h b/include/picrin.h index 27c1e210..1da8a491 100644 --- a/include/picrin.h +++ b/include/picrin.h @@ -164,8 +164,9 @@ bool pic_interned_p(pic_state *, pic_sym); char *pic_strdup(pic_state *, const char *); char *pic_strndup(pic_state *, const char *, size_t); -struct pic_string *pic_str_new(pic_state *, const char *, size_t); /* the 2nd arg may be NULL for empty string */ -struct pic_string *pic_str_new_cstr(pic_state *, const char *); +pic_str *pic_str_new(pic_state *, const char * /* nullable */, size_t); +pic_str *pic_str_new_cstr(pic_state *, const char *); + pic_value pic_format(pic_state *, const char *, ...); pic_value pic_vformat(pic_state *, const char *, va_list); pic_value pic_vfformat(pic_state *, XFILE *, const char *, va_list); diff --git a/src/string.c b/src/string.c index 67b98692..f7437c37 100644 --- a/src/string.c +++ b/src/string.c @@ -8,10 +8,10 @@ #include "picrin/pair.h" #include "picrin/port.h" -struct pic_string * +pic_str * pic_str_new(pic_state *pic, const char *cstr, size_t len) { - struct pic_string *str; + pic_str *str; char *copy; if (cstr) { @@ -20,12 +20,18 @@ pic_str_new(pic_state *pic, const char *cstr, size_t len) copy = (char *)pic_alloc(pic, len); } - str = (struct pic_string *)pic_obj_alloc(pic, sizeof(struct pic_string), PIC_TT_STRING); + str = (pic_str *)pic_obj_alloc(pic, sizeof(pic_str), PIC_TT_STRING); str->len = len; str->str = copy; return str; } +pic_str * +pic_str_new_cstr(pic_state *pic, const char *cstr) +{ + return pic_str_new(pic, cstr, strlen(cstr)); +} + pic_value pic_vfformat(pic_state *pic, XFILE *file, const char *fmt, va_list ap) { @@ -119,15 +125,6 @@ pic_format(pic_state *pic, const char *fmt, ...) return objs; } -struct pic_string * -pic_str_new_cstr(pic_state *pic, const char *cstr) -{ - size_t len; - - len = strlen(cstr); - return pic_str_new(pic, cstr, len); -} - static pic_value pic_str_string_p(pic_state *pic) { @@ -230,7 +227,7 @@ pic_str_string_copy(pic_state *pic) size_t len, start, end, i; char *str; int n; - struct pic_string *copy; + pic_str *copy; n = pic_get_args(pic, "s|ii", &str, &len, &start, &end);