Changed single-line algorithm to check the last character that is not whitespace.