misc: Add a function to encode newlines
Given a string, the added function encodes existing newline characters
('\n') as the string "\\n" and puts into a given output buffer.
The output buffer must have at least 2 times the length of the input
string plus 1 for the terminating '\0'. In the worst case, each
character can be replaced by 2 characters.
Signed-off-by: Anderson Toshiyuki Sasaki <firstname.lastname@example.org>
Reviewed-by: Andreas Schneider <email@example.com>
Reviewed-by: Jakub Jelen <firstname.lastname@example.org>
(cherry picked from commit c9ce8fa40b45af7fca2c75fe5f0614d881e35a84)