~donmcc/astr

deccae99dacd10b65888f664ed7bcbd9c67c5a9a — Don McCaughey 3 years ago cc29e35
Rename astr_eq_bytes() to astr_eq().

On rethinking this name, the `_bytes` suffix isn't really necessary
since I believe it should be general knowledge that string comparisons
are byte-wise in C by default.
4 files changed, 16 insertions(+), 16 deletions(-)

M README.md
M astr.c
M astr.h
M astr_tests.c
M README.md => README.md +1 -1
@@ 33,7 33,7 @@ Allocate a formatted string.
Allocate a formatted string using a `va_list` object.

    bool
    astr_eq_bytes(char const *s1, char const *s2);
    astr_eq(char const *s1, char const *s2);

Compare the bytes of two strings for equality; `s1` and `s2` may be `NULL`.


M astr.c => astr.c +1 -1
@@ 63,5 63,5 @@ extern char *
astr_alloc_empty(void);

extern bool
astr_eq_bytes(char const *s1, char const *s2);
astr_eq(char const *s1, char const *s2);


M astr.h => astr.h +1 -1
@@ 28,7 28,7 @@ astr_alloc_empty(void)
}

inline bool
astr_eq_bytes(char const *s1, char const *s2)
astr_eq(char const *s1, char const *s2)
{
    if (s1 == s2) return true;
    if (NULL == s1 || NULL == s2) return false;

M astr_tests.c => astr_tests.c +13 -13
@@ 20,7 20,7 @@ test_astr_alloc_format(void)
    char *s = astr_alloc_format("answer: %i", 42);
    assert(s);
    assert(10 == strlen(s));
    assert(astr_eq_bytes("answer: 42", s));
    assert(astr_eq("answer: 42", s));
    free(s);
}



@@ 37,38 37,38 @@ test_astr_alloc_format_for_NULL_format(void)


static void
test_astr_eq_bytes(void)
test_astr_eq(void)
{
    char *s = astr_alloc_format("foo");

    assert(astr_eq_bytes("foo", s));
    assert(!astr_eq_bytes(s, "bar"));
    assert(astr_eq("foo", s));
    assert(!astr_eq(s, "bar"));

    free(s);
}


static void
test_astr_eq_bytes_for_NULL_string(void)
test_astr_eq_for_NULL_string(void)
{
    char *s = astr_alloc_format("foo");

    assert(!astr_eq_bytes(s, NULL));
    assert(!astr_eq_bytes(NULL, s));
    assert(astr_eq_bytes(NULL, NULL));
    assert(!astr_eq(s, NULL));
    assert(!astr_eq(NULL, s));
    assert(astr_eq(NULL, NULL));

    free(s);
}


static void
test_astr_eq_bytes_for_empty_strings(void)
test_astr_eq_for_empty_strings(void)
{
    char *s1 = astr_alloc_empty();
    char *s2 = astr_alloc_empty();

    assert(s1 != s2);
    assert(astr_eq_bytes(s1, s2));
    assert(astr_eq(s1, s2));

    free(s2);
    free(s1);


@@ 101,9 101,9 @@ main(int argc, char *argv[])
    test_astr_alloc_empty();
    test_astr_alloc_format();
    test_astr_alloc_format_for_NULL_format();
    test_astr_eq_bytes();
    test_astr_eq_bytes_for_NULL_string();
    test_astr_eq_bytes_for_empty_strings();
    test_astr_eq();
    test_astr_eq_for_NULL_string();
    test_astr_eq_for_empty_strings();
    test_astr_len_format();
    test_astr_len_format_for_NULL_format();
    return EXIT_SUCCESS;