Thank you for the feedback, everyone. Attached is version 4 of the patch,featuring a few tests and minor rewordings.
Cheers,Greg