~donmcc/astr

ref: da1e8f414d3ebbcc625064018e67e92082c78723 astr/astr.c -rw-r--r-- 2.1 KiB
Remove `const` from `va_list` parameters.

For FreeBSD compatibility, remove the `const` qualifier from various
`va_list` parameters.
Make `va_list` parameters `const`.

The functions `astr_formatted_length_from_va_list()`,
`astr_realloc_append_formatted_from_va_list()` and
`astr_alloc_formatted_from_va_list()` are already defensively copying
their `va_list` parameters, so make these parameters `const` to
communicate this.
Made `astr_alloc_formatted_from_va_list()` inline.

Moved definition into the header and added `extern` declaration to the
`.c` file.
Reimplement `astr_alloc_formatted_from_va_list()`.

Drop the need to call `vasprintf()` and change the implementation of
`astr_alloc_formatted_from_va_list()` to call
`astr_realloc_append_formatted_from_va_list()` with a `NULL` string
pointer.

Update the readme and man page and remove the check for `vasprintf()`
from the configure script.
Add test for reallocating a `NULL` string.

Validate that `astr_realloc_append_formatted()` and
`astr_realloc_append_formatted_from_va_list()` correctly handles a
pointer to `NULL` as the string argument `s` by adding a unit test to
cover this case.

Fix `astr_realloc_append_formatted_from_va_list()` so that it only calls
`strlen()` on non-`NULL` string pointers.

Rename various unit tests to change `_for_NULL` to `_for_invalid` to
distinguish between valid `NULL` cases and invalid ones.
Added the `astr_cmp()` function for comparing strings.

The `astr_cmp()` function is an inline wrapper around `strcmp()` that
included `NULL` handling.

Reimplemented `astr_eq()` in terms of `astr_cmp()`.
Added the `astr_empty()` inline function.

The `astr_empty()` function tests a given string to see if it is `NULL`
or points to an empty string.
Added functions to append formatted characters.

Added functions

    astr_realloc_append_formatted()
    astr_realloc_append_formatted_from_va_list()

along with tests, man page and readme documentation.
Change _args suffix to _with_va_list.

Rename `_args` functions to `_with_va_list`:

    astr_alloc_formatted_with_va_list()
    astr_formatted_length_with_va_list()

Also updated the man page to reflect these changes and name changes from
the previous commit.
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.
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.
Move inline declarations to the end of the header.

Place inline declarations at the end of the `astr.h` file, so that they
can be alphabetized as a group and can use previously declared
functions.

Place the extern declarations of inline functions at the end of the
`astr.c` file to mirror the order in the header.
Replace ternary expression with if statement.

Made the implementation of `astr_len_format_args()` more closely mirror
`astr_alloc_format_args()` by using a similar `if` statement for
error checking.
Added `astr_len_format()` and `astr_len_format_args()`.

These two functions use `vsnprintf()` to calculate the number of bytes
needed to hold the formatted string that would result from the
equivalent call to `astr_alloc_format()`.

Added tests and updated the readme and man page for these functions.

Removed tests for the `astr_alloc_format_args()` function, since the
tests for `astr_alloc_format()` cover this function as well.
Change "formatted" to "format".

Rename `astr_alloc_formatted()` and `astr_alloc_formatted_args()`
functions to `astr_alloc_format()` and `astr_alloc_format_args()`
respectively.

Also rename related tests and update the readme and man page.
Added `astr_alloc_formatted_args()` function.

Extracted this function from `astr_alloc_formatted()` to separate the
`va_list` processing (which stays in `astr_alloc_formatted()`) from the
string formatting logic, which moved into `astr_alloc_formatted_args()`.

Added tests and updated the readme and man page.
Added the `astr_eq_bytes()` inline function.

Also added tests for `astr_eq_bytes()` and added documentation for it to
the readme and the man page.
Added `astr_alloc_formatted()` function.

Also added tests for the function and documentation to the man page and
the readme file.
Added initial source, build system and tests.

Created library source files `astr.h` and `astr.c`, adding the initial
library function `astr_alloc_empty()`.

Created test source file `astr_tests.c` with a test for
`astr_alloc_emtpy()`.

Ran `autoscan` to create initial `configure.ac` file and added
additional checks.  Also added `Makefile.am` with targets to create both
`libastr` and `astr_tests`.

Updated `.gitignore` with Autotools generated files and directories.
Updated the readme with instructions to run `autoreconf` to regenerate
the build system.