Re: [Libclc-developers] Some of the string functions
Status: Planning
Brought to you by:
augestad
|
From: <bo...@me...> - 2003-03-24 21:29:49
|
Hallvard B Furuseth wrote:
> Here are the string functions I have added. See the previously posted
> doc for detailed descriptions.
>
> /* Copyright(c) 2003, Hallvard B. Furuseth. (h.b...@us...) */
> char *clc_stpcpy(char *CLC_RESTRICT s1, const char *CLC_RESTRICT s2)
> {
> clc_assert_not_null(clc_stpcpy, s1);
> clc_assert_not_null(clc_stpcpy, s2);
A general question: Given the fact that the asserts are for the libclc
*user* only, how about an assert like this one?
clc_assert_arg(clc_stpcpy, s1 != s2);
I just use you code as an example here.
>
> char *
> clc_strendcpy(char *dst, const char *CLC_RESTRICT src, const char *end)
> {
> clc_assert_arg(clc_strendcpy, dst != NULL && src != NULL && end != NULL);
If I was the user of libclc, I'd prefer to get the exact name of the
invalid argument. This kind of assert forces me to check up to three
variables. The line is also longer than 72 characters.
> if (dst < end) {
> end--; /* room for terminating NUL */
> while (dst < end && *src)
> *dst++ = *src++;
> *dst = '\0';
> if (*src)
> dst++; /* return end parameter if truncation */
> }
> return dst;
> }
>
> char *clc_stralloc(const char *arg1, ...)
> {
> size_t len;
> const char *arg;
> char *ret, *end;
> va_list ap;
> int bad;
>
> bad = 0;
> len = 1;
How about "int bad = 0;" on one line instead?
>
> int
> clc_strcasecmp(const char *s1, const char *s2)
> {
Asserts?
>
> int
> clc_strncasecmp(const char *s1, const char *s2, size_t n)
> {
Asserts?
> char *
> clc_strsep(char **CLC_RESTRICT stringp, const char *CLC_RESTRICT delim)
> {
> char *str, *end;
> clc_assert_arg(clc_strsep, delim != NULL);
clc_assert_not_null()?
>
> char *
> clc_strtok_r(char *str, const char *CLC_RESTRICT delim, char **tracker)
> {
> clc_assert_arg(clc_strtok_r, delim != NULL);
> clc_assert_arg(clc_strtok_r, tracker != NULL);
clc_assert_not_null()?
Looks very good! Just a few asserts away from beeing production ready. ;-)
--
boa
libclc home: http://libclc.sourceforge.net
|