]> git.ozlabs.org Git - ccan/blobdiff - ccan/bytestring/bytestring.c
bytestring: Implement bytestring_spn() and bytestring_cspn()
[ccan] / ccan / bytestring / bytestring.c
diff --git a/ccan/bytestring/bytestring.c b/ccan/bytestring/bytestring.c
new file mode 100644 (file)
index 0000000..69e2b32
--- /dev/null
@@ -0,0 +1,26 @@
+/* Licensed under LGPLv2+ - see LICENSE file for details */
+#include "config.h"
+
+#include <ccan/bytestring/bytestring.h>
+
+size_t bytestring_spn(struct bytestring s, struct bytestring accept)
+{
+       size_t i;
+
+       for (i = 0; i < s.len; i++)
+               if (bytestring_index(accept, s.ptr[i]) == NULL)
+                       return i;
+
+       return s.len;
+}
+
+size_t bytestring_cspn(struct bytestring s, struct bytestring reject)
+{
+       size_t i;
+
+       for (i = 0; i < s.len; i++)
+               if (bytestring_index(reject, s.ptr[i]) != NULL)
+                       return i;
+
+       return s.len;
+}