The encoder has messy newline detection

The newline replacement can be compressed to a one-liner for each value and on top of that, the `input_str` value isn't being changed after the replacement is done.