Convert some uses of strlen() into tests for the null character

Using strlen() in O(n) instead of testing for '\0' in O(1) is
inefficient, especially as the terminating condition of a loop that
exits when it reaches the end of the string, when then becomes O(n^2)
if strlen() is used.