*/
size_t mutt_str_startswith(const char *str, const char *prefix, enum CaseSensitivity cs)
{
- if (!str || (str[0] == '\0') || !prefix || !prefix[0])
+ if (!str || (str[0] == '\0') || !prefix || (prefix[0] == '\0'))
{
return 0;
}
const char *saved_prefix = prefix;
- for (char_cmp f = get_char_cmp(cs); *str && *prefix; str++, prefix++)
+ for (char_cmp fn = get_char_cmp(cs); *str && *prefix; str++, prefix++)
{
- if (!f(*str, *prefix))
+ if (!fn(*str, *prefix))
{
return 0;
}
{
// size_t mutt_str_startswith(const char *str, const char *prefix, enum CaseSensitivity cs);
- {
- TEST_CHECK(mutt_str_startswith(NULL, "apple", CASE_MATCH) == 0);
- }
+ TEST_CHECK(mutt_str_startswith(NULL, "apple", CASE_MATCH) == 0);
+ TEST_CHECK(mutt_str_startswith("apple", NULL, CASE_MATCH) == 0);
- {
- TEST_CHECK(mutt_str_startswith("apple", NULL, CASE_MATCH) == 0);
- }
+ TEST_CHECK(mutt_str_startswith("", "apple", CASE_MATCH) == 0);
+ TEST_CHECK(mutt_str_startswith("apple", "", CASE_MATCH) == 0);
+
+ TEST_CHECK(mutt_str_startswith("applebanana", "apple", CASE_MATCH) == 5);
+ TEST_CHECK(mutt_str_startswith("APPLEbanana", "apple", CASE_MATCH) == 0);
+
+ TEST_CHECK(mutt_str_startswith("APPLEbanana", "apple", CASE_IGNORE) == 5);
+ TEST_CHECK(mutt_str_startswith("GUAVAbanana", "apple", CASE_IGNORE) == 0);
}