libc: minimal: add strspn and strcspn support

These functions are useful for determining prefixes, as with file system
paths.  They are required by littlefs.

Signed-off-by: Peter A. Bigot <pab@pabigot.com>
This commit is contained in:
Peter A. Bigot 2019-07-27 09:28:12 -05:00 committed by Andrew Boie
commit 8420f43b86
4 changed files with 61 additions and 0 deletions

View file

@ -249,6 +249,30 @@ void test_strchr(void)
}
/**
*
* @brief Test string prefix match functions
*
*/
void test_strxspn(void)
{
const char *empty = "";
const char *cset = "abc";
zassert_true(strspn("", empty) == 0U, "strspn empty empty");
zassert_true(strcspn("", empty) == 0U, "strcspn empty empty");
zassert_true(strspn("abde", cset) == 2U, "strspn match");
zassert_true(strcspn("abde", cset) == 0U, "strcspn nomatch");
zassert_true(strspn("da", cset) == 0U, "strspn nomatch");
zassert_true(strcspn("da", cset) == 1U, "strcspn match");
zassert_true(strspn("abac", cset) == 4U, "strspn all");
zassert_true(strcspn("defg", cset) == 4U, "strcspn all");
}
/**
*
* @brief Test memory comparison function
@ -310,6 +334,7 @@ void test_main(void)
ztest_unit_test(test_memset),
ztest_unit_test(test_strlen),
ztest_unit_test(test_strcmp),
ztest_unit_test(test_strxspn),
ztest_unit_test(test_bsearch)
);
ztest_run_test_suite(test_c_lib);