diff --git a/Makefile b/Makefile index 097318d..cb2d18c 100644 --- a/Makefile +++ b/Makefile @@ -19,8 +19,8 @@ CFLAGS=$(GFLAGS) $(DFLAGS) -DVERBOSE_LOGS=2 -DTEST_VERBOSE=1 endif # Units to compile -UNITS=src/sv.c src/vec.c src/stream.c src/symtable.c src/lisp.c src/allocator.c \ - src/sys.c src/reader.c +UNITS=src/sv.c src/vec.c src/string.c src/stream.c src/symtable.c src/lisp.c \ + src/allocator.c src/sys.c src/reader.c OBJECTS:=$(patsubst src/%.c, $(DIST)/%.o, $(UNITS)) TEST_UNITS=test/main.c diff --git a/include/alisp/string.h b/include/alisp/string.h new file mode 100644 index 0000000..eac0a93 --- /dev/null +++ b/include/alisp/string.h @@ -0,0 +1,35 @@ +/* string.h: String library + * Created: 2026-03-05 + * Author: Aryadev Chavali + * License: See end of file + * Commentary: + */ + +#ifndef STRING_H +#define STRING_H + +#include +#include + +typedef struct +{ + vec_t data; +} str_t; + +str_t string_make(sv_t sv); +sv_t string_sv(str_t *); + +#endif + +/* Copyright (C) 2026 Aryadev Chavali + + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License Version 2 for + * details. + + * You may distribute and modify this code under the terms of the GNU General + * Public License Version 2, which you should have received a copy of along with + * this program. If not, please go to . + + */ diff --git a/src/string.c b/src/string.c new file mode 100644 index 0000000..37af4f6 --- /dev/null +++ b/src/string.c @@ -0,0 +1,44 @@ +/* string.c: String library implementation + * Created: 2026-03-05 + * Author: Aryadev Chavali + * License: See end of file + * Commentary: + */ + +#include + +#include + +str_t string_make(sv_t sv) +{ + str_t string = {0}; + if (sv.size) + { + vec_init(&string.data, sv.size); + if (sv.data) + { + memcpy(vec_data(&string.data), sv.data, sv.size); + } + } + return string; +} + +sv_t string_sv(str_t *str) +{ + if (!str) + return SV(NULL, 0); + return SV((char *)vec_data(&str->data), str->data.size); +} + +/* Copyright (C) 2026 Aryadev Chavali + + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License Version 2 for + * details. + + * You may distribute and modify this code under the terms of the GNU General + * Public License Version 2, which you should have received a copy of along with + * this program. If not, please go to . + + */