picrin/src/string.c

40 lines
679 B
C
Raw Normal View History

2013-10-20 19:48:55 -04:00
#include <string.h>
#include "picrin.h"
struct pic_string *
pic_str_new(pic_state *pic, const char *cstr, size_t len)
2013-10-20 19:48:55 -04:00
{
struct pic_string *str;
str = (struct pic_string *)pic_obj_alloc(pic, sizeof(struct pic_string), PIC_TT_STRING);
str->len = len;
2013-11-15 03:08:18 -05:00
str->str = strdup(cstr);
return str;
2013-10-20 19:48:55 -04:00
}
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);
}
2013-11-17 03:42:52 -05:00
static pic_value
pic_str_string_p(pic_state *pic)
{
pic_value v;
pic_get_args(pic, "o", &v);
return pic_bool_value(pic_str_p(v));
}
void
pic_init_str(pic_state *pic)
{
pic_defun(pic, "string?", pic_str_string_p);
}