summaryrefslogtreecommitdiff
path: root/lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib.c b/lib.c
index ba03c75..01f5110 100644
--- a/lib.c
+++ b/lib.c
@@ -123,6 +123,19 @@ static Val fn_spendsplat(State *S, int nargs, Val *args) {
ObjArr *a = AS_ARR(args[0]);
return fn_spend(S, a->len, a->d);
}
+static Val fn_ssub(State *S, int nargs, Val *args) {
+ CHECK(nargs == 2, "need exactly 2 args for ssub?");
+ CHECK(IS_STRING(args[0]) && IS_STRING(args[1]), "need 2 strings for ssub?");
+ ObjString *needle = AS_STRING(args[0]);
+ ObjString *haystack = AS_STRING(args[1]);
+ int maxoff = haystack->len - needle->len;
+ for (int i = 0; i <= maxoff; i++)
+ if (0 == memcmp(needle->d, haystack->d + i, needle->len))
+ return VAL_TRUE;
+ return VAL_FALSE;
+}
+
+
static Val fn_ssplit(State *S, int nargs, Val *args) {
CHECK(nargs==2,"need exactly 2 args for ssplit");
CHECK(IS_STRING(args[0]) && IS_STRING(args[1]), "need two strings for ssplit");
@@ -202,8 +215,10 @@ static BuiltinFunc builtin_funcs[] = {
{ "delete!", fn_delete },
{ "#", fn_len },
{ ",", fn_pend },
+
{ "s,", fn_spend },
{ "s,@", fn_spendsplat },
+ { "ssub?", fn_ssub },
{ "ssplit", fn_ssplit },
{ "schars-ascii", fn_schars_ascii },