Add string_pbrk

This commit is contained in:
Patrick Pelissier committed 2017-08-02 22:24:12 +02:00
1 parent 7165740af3
commit a780a7d144
2 files changed
+14

No files matched your search

+9
View File
@@ -436,6 +436,15 @@ string_cspn(const string_t v1, const char accept[])
return strcspn(string_get_cstr(v1), accept);
}
static inline size_t
string_pbrk(const string_t v1, const char first_of[])
{
STRING_CONTRACT (v1);
M_ASSUME (first_of != NULL);
const char *p = M_ASSIGN_CAST(const char*, strpbrk(string_get_cstr(v1), first_of));
return p == NULL ? STRING_FAILURE : (size_t) (p-string_get_cstr(v1));
}
static inline void
string_left(string_t v, size_t index)
{
+5
View File
@@ -318,6 +318,11 @@ int main(void)
string_replace_at(s1, 6, 3, "World");
assert(string_equal_str_p(s1, "HELLO World!"));
h = string_pbrk(s1, "AB");
assert(h==STRING_FAILURE);
h = string_pbrk(s1, "oO");
assert(h==4);
string_clear (s1);
string_clear (s2);