xkcd-substitutions icon indicating copy to clipboard operation
xkcd-substitutions copied to clipboard

Improve the algorithm to match case when replacing.

Open piquan opened this issue 8 years ago • 1 comments

Fix for #31. This improves the algorithm we use to match case, rather than doing a character-by-character check of case.

This computes the Hamming distance (number of characters changed) between the original and its lower case, upper case, and title case equivalents. Whichever is the closest match to the original, we do the same to the replacement. The lower case path also has a special check for whether the initial letter is capitalized, so that sentence starts are correctly handled.

piquan avatar May 28 '16 02:05 piquan

This is based on b471210, which is currently the Posnet:master top-of-tree. This patch doesn't integrate quite precisely after #48, so let me know if you need me to rebase this or other pull requests to make them easier to apply.

piquan avatar May 28 '16 21:05 piquan