BTW, was there a reason for not noticing the case of exact match in the search loop, and falling out early? As it stands the code will reliably choose the leftmost match if there are multiple equal items in the search array, but do we care about such cases?
I am not sure if we care, probably not.
Anyway I attached patch that I am happy with. I am not yet sure what to do with naming.