Properly handle non-Unix newlines and '\r' escape sequences.