string: new string library
Strings are simply byte vectors. We want a separate type so when tagging/untagging we can have some level of type separation.
This commit is contained in:
4
Makefile
4
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
|
||||
|
||||
35
include/alisp/string.h
Normal file
35
include/alisp/string.h
Normal file
@@ -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 <alisp/sv.h>
|
||||
#include <alisp/vec.h>
|
||||
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
44
src/string.c
Normal file
44
src/string.c
Normal file
@@ -0,0 +1,44 @@
|
||||
/* string.c: String library implementation
|
||||
* Created: 2026-03-05
|
||||
* Author: Aryadev Chavali
|
||||
* License: See end of file
|
||||
* Commentary:
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <alisp/string.h>
|
||||
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
Reference in New Issue
Block a user