From 5bc7e4d6ebdbd0c8bb30763b38cd48b6d79fffe1 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 21 Apr 2013 01:03:46 +0200 Subject: bstr: add bstrspn() --- core/bstr.c | 9 +++++++++ core/bstr.h | 1 + 2 files changed, 10 insertions(+) (limited to 'core') diff --git a/core/bstr.c b/core/bstr.c index a472fbfb02..16da0993ea 100644 --- a/core/bstr.c +++ b/core/bstr.c @@ -82,6 +82,15 @@ int bstrcspn(struct bstr str, const char *reject) return i; } +int bstrspn(struct bstr str, const char *accept) +{ + int i; + for (i = 0; i < str.len; i++) + if (!strchr(accept, str.start[i])) + break; + return i; +} + int bstr_find(struct bstr haystack, struct bstr needle) { for (int i = 0; i < haystack.len; i++) diff --git a/core/bstr.h b/core/bstr.h index bcac6cdba3..7dd318002a 100644 --- a/core/bstr.h +++ b/core/bstr.h @@ -58,6 +58,7 @@ int bstrcmp(struct bstr str1, struct bstr str2); int bstrcasecmp(struct bstr str1, struct bstr str2); int bstrchr(struct bstr str, int c); int bstrrchr(struct bstr str, int c); +int bstrspn(struct bstr str, const char *accept); int bstrcspn(struct bstr str, const char *reject); int bstr_find(struct bstr haystack, struct bstr needle); -- cgit v1.2.3