~donmcc/astr

6a7af5061199752b6dc6c374b8162d4eec212169 — Don McCaughey 1 year, 8 months ago deccae9
Renamed functions with "_format" in their names.

Changed `astr_alloc_format()` to `astr_alloc_formatted()` and
`astr_len_format()` to `astr_formatted_length()`.  Renamed the variable
argument versions of these to functions similarly.

Though this makes the names a little longer, I think it also makes them
read better.
4 files changed, 28 insertions(+), 28 deletions(-)

M README.md
M astr.c
M astr.h
M astr_tests.c
M README.md => README.md +4 -4
@@ 23,12 23,12 @@ Functions that end with the suffix `_args` take variable arguments as a
Allocate an empty string.

    char *
    astr_alloc_format(char const *format, ...);
    astr_alloc_formatted(char const *format, ...);

Allocate a formatted string.

    char *
    astr_alloc_format_args(char const *format, va_list arguments);
    astr_alloc_formatted_args(char const *format, va_list arguments);

Allocate a formatted string using a `va_list` object.



@@ 38,12 38,12 @@ Allocate a formatted string using a `va_list` object.
Compare the bytes of two strings for equality; `s1` and `s2` may be `NULL`.

    size_t
    astr_len_format(char const *format, ...);
    astr_formatted_length(char const *format, ...);

Calculate the length in bytes needed for the formatted string.

    size_t
    astr_len_format_args(char const *format, va_list arguments);
    astr_formatted_length_args(char const *format, va_list arguments);

Calculate the length in bytes needed for the formatted string using a `va_list`
object.

M astr.c => astr.c +6 -6
@@ 5,18 5,18 @@


char *
astr_alloc_format(char const *format, ...)
astr_alloc_formatted(char const *format, ...)
{
    va_list arguments;
    va_start(arguments, format);
    char *s = astr_alloc_format_args(format, arguments);
    char *s = astr_alloc_formatted_args(format, arguments);
    va_end(arguments);
    return s;
}


char *
astr_alloc_format_args(char const *format, va_list arguments)
astr_alloc_formatted_args(char const *format, va_list arguments)
{
    if (!format) {
        errno = EINVAL;


@@ 33,18 33,18 @@ astr_alloc_format_args(char const *format, va_list arguments)


size_t
astr_len_format(char const *format, ...)
astr_formatted_length(char const *format, ...)
{
    va_list arguments;
    va_start(arguments, format);
    size_t length = astr_len_format_args(format, arguments);
    size_t length = astr_formatted_length_args(format, arguments);
    va_end(arguments);
    return length;
}


size_t
astr_len_format_args(char const *format, va_list arguments)
astr_formatted_length_args(char const *format, va_list arguments)
{
    if (!format) {
        errno = EINVAL;

M astr.h => astr.h +4 -4
@@ 9,16 9,16 @@


char *
astr_alloc_format(char const *format, ...);
astr_alloc_formatted(char const *format, ...);

char *
astr_alloc_format_args(char const *format, va_list arguments);
astr_alloc_formatted_args(char const *format, va_list arguments);

size_t
astr_len_format(char const *format, ...);
astr_formatted_length(char const *format, ...);

size_t
astr_len_format_args(char const *format, va_list arguments);
astr_formatted_length_args(char const *format, va_list arguments);


inline char *

M astr_tests.c => astr_tests.c +14 -14
@@ 15,9 15,9 @@ test_astr_alloc_empty(void)


static void
test_astr_alloc_format(void)
test_astr_alloc_formatted(void)
{
    char *s = astr_alloc_format("answer: %i", 42);
    char *s = astr_alloc_formatted("answer: %i", 42);
    assert(s);
    assert(10 == strlen(s));
    assert(astr_eq("answer: 42", s));


@@ 26,10 26,10 @@ test_astr_alloc_format(void)


static void
test_astr_alloc_format_for_NULL_format(void)
test_astr_alloc_formatted_for_NULL_format(void)
{
    errno = 0;
    char *s = astr_alloc_format(NULL);
    char *s = astr_alloc_formatted(NULL);
    assert(!s);
    assert(EINVAL == errno);
    free(s);


@@ 39,7 39,7 @@ test_astr_alloc_format_for_NULL_format(void)
static void
test_astr_eq(void)
{
    char *s = astr_alloc_format("foo");
    char *s = astr_alloc_formatted("foo");

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


@@ 51,7 51,7 @@ test_astr_eq(void)
static void
test_astr_eq_for_NULL_string(void)
{
    char *s = astr_alloc_format("foo");
    char *s = astr_alloc_formatted("foo");

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


@@ 76,20 76,20 @@ test_astr_eq_for_empty_strings(void)


static void
test_astr_len_format(void)
test_astr_formatted_length(void)
{
    errno = 0;
    size_t length = astr_len_format("answer: %i", 42);
    size_t length = astr_formatted_length("answer: %i", 42);
    assert(10 == length);
    assert(0 == errno);
}


static void
test_astr_len_format_for_NULL_format(void)
test_astr_formatted_length_for_NULL_format(void)
{
    errno = 0;
    size_t length = astr_len_format(NULL);
    size_t length = astr_formatted_length(NULL);
    assert(0 == length);
    assert(EINVAL == errno);
}


@@ 99,13 99,13 @@ int
main(int argc, char *argv[])
{
    test_astr_alloc_empty();
    test_astr_alloc_format();
    test_astr_alloc_format_for_NULL_format();
    test_astr_alloc_formatted();
    test_astr_alloc_formatted_for_NULL_format();
    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();
    test_astr_formatted_length();
    test_astr_formatted_length_for_NULL_format();
    return EXIT_SUCCESS;
}