Re: [Libclc-developers] new string functions: clc_str{n}{case}comm()
Status: Planning
Brought to you by:
augestad
|
From: Hallvard B F. <h.b...@us...> - 2003-03-23 15:47:54
|
Bj=F8rn Augestad writes: > 1. Why do you return -1 if s1 is shorter than s2? I don't. the *s1 =3D=3D '\0' test only hits if *s1 =3D=3D *s2. > 2. The implementation crashes if s2 is shorter than s1 and shorter than=20 > len, doesn't it? Then the tolower test will stop the loop. Well, unless *s2 =3D=3D '\0' and tolower(*s2) !=3D '\0', but if anyone has broken tolower that badly I don't care if they lose. > 3. Why have a len at all? If you just want to see if the first n=20 > characters are common, can't memcmp, strncasecmp or others be used instea= d? One could test with strncasecmp first and then call strcasecomm() if the strings are not equal, but that's more work and more code. > 4. Given 1) and 3), why not return size_t? What can go wrong? The problem is what to return if the strings are equal and shorter than the length parameter. strlen(s1)? Then the caller must test if either of s1[return value] or s2[return value] is non-'\0' if he wants to know if the strings are equal. strlen(s1)+1? Then we can't inspect s1[return value], which might be out of bounds, and we must test if the return value is nonzero before inspecting s1[return value-1]. So I gave up and returned -1 instead. --=20 Hallvard |