mirror of
https://github.com/samsonjs/lake.git
synced 2026-03-25 08:55:49 +00:00
- add booleans, dotted lists, functions - proper lexical scope - special forms: define, set!, and, or, quote, lambda - added some basic list manipulations - print functions and dotted lists - removed nil - more robust in general
78 lines
1.1 KiB
C
78 lines
1.1 KiB
C
/**
|
|
* string.c
|
|
* Lake Scheme
|
|
*
|
|
* Copyright 2011 Sami Samhuri
|
|
* MIT License
|
|
*
|
|
*/
|
|
|
|
#include <glib.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include "int.h"
|
|
#include "lake.h"
|
|
#include "string.h"
|
|
|
|
static LakeStr *str_alloc(void)
|
|
{
|
|
LakeStr *str = g_malloc(sizeof(LakeStr));
|
|
VAL(str)->type = TYPE_STR;
|
|
VAL(str)->size = sizeof(LakeStr);
|
|
return str;
|
|
}
|
|
|
|
void str_free(LakeStr *str)
|
|
{
|
|
g_free(str->s);
|
|
g_free(str);
|
|
}
|
|
|
|
LakeVal *str_set(LakeStr *str, char *s)
|
|
{
|
|
str->n = strlen(s);
|
|
str->s = g_strdup(s);
|
|
return NULL;
|
|
}
|
|
|
|
LakeStr *str_from_c(char *s)
|
|
{
|
|
LakeStr *str = str_alloc();
|
|
str_set(str, s);
|
|
return str;
|
|
}
|
|
|
|
LakeStr *str_make(void)
|
|
{
|
|
return str_from_c("");
|
|
}
|
|
|
|
LakeInt *str_len(LakeStr *str)
|
|
{
|
|
return int_from_c(str->n);
|
|
}
|
|
|
|
LakeStr *str_copy(LakeStr *str)
|
|
{
|
|
return str_from_c(str->s);
|
|
}
|
|
|
|
char *str_val(LakeStr *str)
|
|
{
|
|
return g_strdup(str->s);
|
|
}
|
|
|
|
LakeInt *str_cmp(LakeStr *a, LakeStr *b)
|
|
{
|
|
return int_from_c(g_strcmp0(a->s, b->s));
|
|
}
|
|
|
|
LakeBool *str_eq(LakeStr *a, LakeStr *b)
|
|
{
|
|
return bool_from_int(g_strcmp0(a->s, b->s) == 0);
|
|
}
|
|
|
|
LakeStr *str_to_str(LakeStr *str)
|
|
{
|
|
return str_copy(str);
|
|
}
|