2013-10-20 19:48:55 -04:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "picrin.h"
|
|
|
|
|
|
|
|
pic_value
|
2013-10-20 22:12:34 -04:00
|
|
|
pic_str_new(pic_state *pic, const char *cstr, size_t len)
|
2013-10-20 19:48:55 -04:00
|
|
|
{
|
|
|
|
struct pic_string *str;
|
|
|
|
char *new_str;
|
|
|
|
|
|
|
|
new_str = (char *)pic_alloc(pic, len + 1);
|
2013-10-20 22:12:34 -04:00
|
|
|
strncpy(new_str, cstr, len);
|
|
|
|
new_str[len] = '\0';
|
2013-10-20 19:48:55 -04:00
|
|
|
|
|
|
|
str = (struct pic_string *)pic_obj_alloc(pic, sizeof(struct pic_string), PIC_TT_STRING);
|
|
|
|
str->len = len;
|
|
|
|
str->str = new_str;
|
|
|
|
|
|
|
|
return pic_obj_value(str);
|
|
|
|
}
|
2013-10-20 22:12:34 -04:00
|
|
|
|
|
|
|
pic_value
|
|
|
|
pic_str_new_cstr(pic_state *pic, const char *cstr)
|
|
|
|
{
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
len = strlen(cstr);
|
|
|
|
return pic_str_new(pic, cstr, len);
|
|
|
|
}
|