signed_length function, generalizing the usual string length function