From 14fc5cdb632c0ee31fbaaf9a32a6ad877ac70015 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Mon, 7 Nov 2022 23:18:43 +0100 Subject: [PATCH 1/2] dictionary: Fix failure to look back Firstly, a ~ match is supposed to match even if there's nothing left. Also, when p doesn't match, we should not return immediately, but skip to the next group. Fixes #1507 --- src/libespeak-ng/dictionary.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/libespeak-ng/dictionary.c b/src/libespeak-ng/dictionary.c index 56471e89..17c3580e 100644 --- a/src/libespeak-ng/dictionary.c +++ b/src/libespeak-ng/dictionary.c @@ -695,6 +695,10 @@ static int IsLetterGroup(Translator *tr, char *word, int group, int pre) return -1; while (*p != RULE_GROUP_END) { + // If '~' (no character) is allowed in group, return 0. + if (*p == '~') + return 0; + if (pre) { len = strlen(p); w = word; @@ -702,16 +706,12 @@ static int IsLetterGroup(Translator *tr, char *word, int group, int pre) { w--; if (*w == 0) - // Not found - return -1; + // Not found, skip the rest of this group. + goto skip; } } else w = word; - // If '~' (no character) is allowed in group, return 0. - if (*p == '~') - return 0; - // Check current group while ((*p == *w) && (*w != 0)) { w++; @@ -724,6 +724,7 @@ static int IsLetterGroup(Translator *tr, char *word, int group, int pre) } // No match, so skip the rest of this group. +skip: while (*p++ != 0) ; } From 52e4811ab9d828dac1120d58a13ba272d94d66af Mon Sep 17 00:00:00 2001 From: Juho Hiltunen Date: Mon, 7 Nov 2022 23:18:30 +0100 Subject: [PATCH 2/2] test for #1507 --- tests/translate.test | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/translate.test b/tests/translate.test index 99520642..0a5155fd 100755 --- a/tests/translate.test +++ b/tests/translate.test @@ -105,3 +105,11 @@ test_phon cmn "ni35X'Au35_| m'A21_| (en)h@44loU11_| De@11(cmn)_|" "你好馬 hel test_phon cmn-latn-pinyin "ni35X'Au35_| m'A35_| n'i35_| X'Au35_| m'A214_|" "你好馬 ni3 hao3 ma3" test_phon cmn "thiE55nt'i51_|" "天地" + +# https://github.com/espeak-ng/espeak-ng/issues/1507 +test_phon ml "k'a +t'a +p'a +k'e:r@l.@m +t'a:m@ra +p'o:le" "ക: ത: പ: കേരളം: താമര: പോലെ:"