Support for String#encode with :universal_newline.

This has been implemented directly in String#encode similar to the :xml option.
I'm not sure if this is the best place to put it in but I can't find a better
alternative.

This fixes #2944.
Specs for String#encode with :universal_newline.