Skip to content

Commit

Permalink
MBS-11854: Recognize unicode hyphen in guess case (#2199)
Browse files Browse the repository at this point in the history
Words with a unicode hyphen were not being recognized
as split words: the hyphen was just being considered one more character.
This changes that, and then ensures that guess case recognizes
the hyphen as such and does the same as with a hyphen-minus.

Sadly, part of my fix for MBS-10156 (for re‐mode with unicode hyphen)
will no longer work now since it is no longer considered
one single word, but I think this makes a lot more sense for now.
The current code already didn't do anything with re-mode with a
hyphen-minus, so this actually adds consistency.
  • Loading branch information
reosarevok committed Aug 12, 2021
1 parent 6e3e634 commit 61ee8af
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
4 changes: 2 additions & 2 deletions root/static/scripts/guess-case/MB/GuessCase/Handler/Base.js
Expand Up @@ -117,7 +117,7 @@ MB.GuessCase.Handler.Base = function (gc) {
*/
var handled = false;
if (!gc.regexes.SPECIALCASES) {
gc.regexes.SPECIALCASES = /(&|¿|¡|\?|\!|;|:|'|‘|’|‹|›|"|“|”|„|“|«|»|\-|\+|,|\*|\.|#|%|\/|\(|\)|\{|\}|\[|\])/;
gc.regexes.SPECIALCASES = /(&|¿|¡|\?|\!|;|:|'|‘|’|‹|›|"|“|”|„|“|«|»|\-|‐|\+|,|\*|\.|#|%|\/|\(|\)|\{|\}|\[|\])/;
}
if (input.matchCurrentWord(gc.regexes.SPECIALCASES)) {
handled = !!(
Expand Down Expand Up @@ -332,7 +332,7 @@ MB.GuessCase.Handler.Base = function (gc) {
*/
self.doHyphen = function () {
if (!gc.regexes.HYPHEN) {
gc.regexes.HYPHEN = '-';
gc.regexes.HYPHEN = /^[\-‐]$/;
}
if (input.matchCurrentWord(gc.regexes.HYPHEN)) {
output.appendWordPreserveWhiteSpace(true);
Expand Down
2 changes: 1 addition & 1 deletion root/static/scripts/guess-case/MB/GuessCase/Input.js
Expand Up @@ -182,7 +182,7 @@ class GuessCaseInput {
const splitwords = [];
let word = [];
if (!gc.regexes.SPLITWORDSANDPUNCTUATION) {
gc.regexes.SPLITWORDSANDPUNCTUATION = /[^!¿¡\"%&'´`‘’‹›“”„“«»()\[\]\{\}\*\+,-\.\/:;<=>\?\s#]/;
gc.regexes.SPLITWORDSANDPUNCTUATION = /[^!¿¡\"%&'´`‘’‹›“”„“«»()\[\]\{\}\*\+‐\-,\.\/:;<=>\?\s#]/;
}
for (let i = 0; i < chars.length; i++) {
if (chars[i].match(gc.regexes.SPLITWORDSANDPUNCTUATION)) {
Expand Down
1 change: 0 additions & 1 deletion root/static/scripts/guess-case/utils.js
Expand Up @@ -61,7 +61,6 @@ const preBracketSingleWordsList = [
'rehearsal',
'remixed',
'remode',
're‐mode',
'rework',
'reworked',
'session',
Expand Down
14 changes: 11 additions & 3 deletions root/static/scripts/tests/GuessCase.js
Expand Up @@ -175,7 +175,7 @@ test('Recording', function (t) {
});

test('Work', function (t) {
t.plan(23);
t.plan(24);

const tests = [
{
Expand Down Expand Up @@ -344,6 +344,14 @@ test('Work', function (t) {
roman: false,
keepuppercase: false,
},
{
input: 'hyphen-minus? hyphen‐maximus!',
expected: 'Hyphen-Minus? Hyphen‐Maximus!',
bug: 'MBS-11854',
mode: 'English',
roman: false,
keepuppercase: false,
},
];

for (const test of tests) {
Expand Down Expand Up @@ -457,8 +465,8 @@ test('BugFixes', function (t) {
mode: 'French',
},
{
input: 'We Love Techno (Re‐Mode)',
expected: 'We Love Techno (re‐mode)',
input: 'We Love Techno (Remode)',
expected: 'We Love Techno (remode)',
bug: 'MBS-10156',
mode: 'English',
},
Expand Down

0 comments on commit 61ee8af

Please sign in to comment.