encode_utf7(s)
public
Encode a string from UTF-8 format to modified UTF-7.
Show source
def self.encode_utf7(s)
return s.gsub(/(&)|([^\x20-\x7e]+)/) {
if $1
"&-"
else
base64 = [$&.unpack("U*").pack("n*")].pack("m")
"&" + base64.delete("=\n").tr("/", ",") + "-"
end
}.force_encoding("ASCII-8BIT")
end