On Saturday 05 July 2014 11:42:29 Darshit Shah wrote:
> It's all fine. I think the function names are okay, they're a bit
> long, but we can work with that.
>
> Just change the return values. 0 for true and 1 for false. Since that
> is what we're all used to in C.
Hi Darshit,
my last answer was a bit short. I was standing in a crowded, hot train being
shaken while typing on this mini touch keyboard of my mobile phone :-(
There is a 'is' class of functions that do not return errors but just 0 for
'No/False' and 1 for 'Yes/True'. Example: isatty(), isdigit(), ...
These functions simply ask a question that has to be answered with Yes or No.
You normally use it like
if (isupper(c)) ...
and NOT like
if (isupper(c)==1) ...
Your idea now is to change these functions and turn around the logic. Ok, BUT
one should also rename these function at the same time to e.g. isnotupper() to
use it like
if (isnotupper(c)==0)
which you ask for.
Right now you use the 'is' PSL functions like
if (psl_is_public_suffix(psl, domain)) ...
If you insist on checking for 0 (or a define) as success, than we should
rename these functions to e.g.
if ((rc=psl_test_public_suffix(psl, domain))==PSL_SUCCESS) print 'suffix'
else print error code 'rc'.
My design goal was to provide as-easy-as-possible functions.
But you might be right and we should return an error code... but that might
not be enough. A programmer might also be interested in why the param is a
public suffix (Unknown TLD / prvailing * match, Domain might be an exception,
domain has too many labels to be a PS, ...).
For this case we could define some codes and extend the function like
if (psl_is_public_suffix(psl, domain, &why)) {
print The <domain> is a public suffix because <why>
} else {
print The <domain> is *NOT* a public suffix because <why>
}
What do you think ?
And strictly spoken, library functions should also not return char *, like
psl_unregistrable_domain()... it should return an error code and take a third
argument char **ret to return the allocated string.
It is simply a design decision. And so far I decided for simple functions
which drop some details. If you really need more how would you like it ?
We could also have a set of 'simple' function (that we already have) plus
'detailed' functions (see above) ... everything is possible.
Tim