
It’s wrappers all the way down - chmaynard
https://oleb.net/2018/lastindex-reversed/
======
tropo
Dear my... this is way leaner in C.

    
    
        return strrchr(str,',')+1;
    

There are just a handful of branches unless your library goes nuts with
vectorization.

If you want to handle three forms of broken input:

    
    
        if(!str)
            return NULL;
        str = strrchr(str,',');
        if(!str)
            return NULL;
        if(!*++str)
            return NULL;
        return str;

~~~
db48x
It's only leaner in C if you know that the caller doesn't need a freshly-
allocated string, and isn't going to free the pointer that you return.

~~~
tropo
add a strdup()

That is still far fewer layers of gunk, not even counting whatever may
underlie the non-C strings.

~~~
db48x
Surely you mean strndup, since you're keeping careful track of the correct
length of your strings to prevent buffer overflows.

