From 5be2871481af5607d0886a35d2608aabf2de83bc Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Sat, 23 Sep 2006 19:17:50 +0000 Subject: r18850: add strspn() function i ejs (This used to be commit e8f892bedc65042565442ac802df6eda96388f14) --- source4/scripting/ejs/smbcalls_string.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'source4/scripting') diff --git a/source4/scripting/ejs/smbcalls_string.c b/source4/scripting/ejs/smbcalls_string.c index d5884cb00f..403de7ba35 100644 --- a/source4/scripting/ejs/smbcalls_string.c +++ b/source4/scripting/ejs/smbcalls_string.c @@ -89,6 +89,22 @@ static int ejs_strstr(MprVarHandle eid, int argc, char **argv) return 0; } +/* + usage: + var s = strspn(string, legal_chars_string); +*/ +static int ejs_strspn(MprVarHandle eid, int argc, char **argv) +{ + int len; + if (argc != 2) { + ejsSetErrorMsg(eid, "strspn invalid arguments"); + return -1; + } + len = strspn(argv[0], argv[1]); + mpr_Return(eid, mprCreateIntegerVar(len)); + return 0; +} + /* usage: list = split(".", "a.foo.bar"); @@ -493,6 +509,7 @@ static int ejs_string_init(MprVarHandle eid, int argc, struct MprVar **argv) mprSetStringCFunction(obj, "strlower", ejs_strlower); mprSetStringCFunction(obj, "strupper", ejs_strupper); mprSetStringCFunction(obj, "strstr", ejs_strstr); + mprSetStringCFunction(obj, "strspn", ejs_strspn); mprSetCFunction(obj, "split", ejs_split); mprSetCFunction(obj, "join", ejs_join); mprSetCFunction(obj, "sprintf", ejs_sprintf); -- cgit