Dave Burt
3/15/2005 4:45:00 AM
>> What builtin quoted printable facilities?
>
> Look up the "M" format for Array.pack.
So here's the cheat solution:
class String
def to_quoted_printable(*args)
[self].pack("M").gsub(/\n/, "\r\n")
end
def from_quoted_printable
self.gsub(/\r\n/, "\n").unpack("M").first
end
end
(Just add my original if __FILE__ block to make it almost quiz-compatible)
And here's how it fares against my test suite:
Loaded suite TC_QuotedPrintable
Started
.............FF.FFFFFFF..
Finished in 0.39 seconds.
So it's 10 times the speed of my original one (against random binary data), but
chops lines too early, ends up with 73- instead of 76-character lines. Of
course, this one won't do XML.
Interestingly, if I use a gsub! instead of a loop with sub!s in my soft_break!
method, I get a 5x speedup... and fail the same tests.
Cheers,
Dave