encode carriage return (\r)

Hello.
Now that you have added the code to encode a carriage return, please be merged to master when it is good.