--------------020108040905050308080407
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Dave Burt wrote:

> Tabs and spaces that are followed by something printable on the same line 
> should not be escaped; see the following:

Oh, I misread the quiz -- I thought I would have to escape multiple 
whitespace characters as well which seemed to also make sense. (XML can 
sometimes collapse multiple whitespace characters into one.)

This in fact simplifies my algorithm. Note that the new code will also 
escape at the file end in case there is no new line character there. I 
think that that is actually a good thing.

>>>- allows too-long lines (my tests saw up to 104 characters on a line)
>>
>>Any hints on when this is happening? I can't see why and when this would 
>>happen.
> 
> test_encode_12 also demonstrates this. I fixed it by changing 
> /[\t ](?:[\v\t ]|$)../ to /[\t ]$../.
> This (obviously) fixes the mid-line whitespace as well.

Still not sure why this was happening. Line breaks should be applied 
after the escaping has already happened. But I guess it's fixed now anyway.

> Also, this, on line 10: "char[0 ... -1] + ...", seems redundant - with char 
> as a one-character match, it's an empty string.

It wasn't when I was escaping all repeated whitespace. It now is.

>>I'll repost the full source when I've sorted out that other problem as 
>>well.

Which is now. See attachment.

I've also decided to do proper escaping of the "[" and "]" characters in 
the also_encode argument. Note that it's still possible to cause an 
invalid Regexp by supplying b-a which I think is okay.

--------------020108040905050308080407
Content-Type: application/x-ruby;
 nameuoted_printable.rb"
Content-Transfer-Encoding: base64
Content-Disposition: inline;
 filenameuoted_printable.rb"

bW9kdWxlIFF1b3RlZFByaW50YWJsZQ0KICBleHRlbmQgc2VsZg0KDQogICMgRW5jb2RlcyB0
ZXh0IGFzIHF1b3RlZCBwcmludGFibGUuIFRoZSBzZWNvbmQgYXJndW1lbnQgc3BlY2lmaWVz
IGNoYXJhY3RlcnMgdGhhdA0KICAjIHNob3VsZCBiZSBlbmNvZGVkIGluIGFkZGl0aW9uIHRv
IHRoZSBvbmVzIHRoYXQgYXJlIGF1dG9tYXRpY2FsbHkgcXVvdGVkIG9uZXMuDQogICMgSXQg
aXMgYSBzdHJpbmcgdGhhdCBzcGVjaWZpZXMgY2hhcmFjdGVycy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