From 74924757286a627e85fdbb494db58c9bbbb62365 Mon Sep 17 00:00:00 2001 From: Juho Hiltunen Date: Sun, 28 Aug 2022 17:46:59 +0300 Subject: [PATCH] code cleanup: make a function for checking tr->chars_ignore ReadClause() is very long and should be shortened for code readability --- src/libespeak-ng/readclause.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/libespeak-ng/readclause.c b/src/libespeak-ng/readclause.c index 86755097..6fce5fdc 100644 --- a/src/libespeak-ng/readclause.c +++ b/src/libespeak-ng/readclause.c @@ -478,6 +478,17 @@ static int lookupwchar2(const unsigned short *list, int c) return 0; } +static bool IgnoreOrReplaceChar(Translator *tr, int *c1) { + int i; + if ((i = lookupwchar2(tr->chars_ignore, *c1)) != 0) { + if (i == 1) { + // ignore this character + return true; + } + *c1 = i; // replace current character with the result + } + return false; +} int ReadClause(Translator *tr, char *buf, short *charix, int *charix_top, int n_buf, int *tone_type, char *voice_change) { @@ -703,13 +714,9 @@ int ReadClause(Translator *tr, char *buf, short *charix, int *charix_top, int n_ linelength++; - if ((j = lookupwchar2(tr->chars_ignore, c1)) != 0) { - if (j == 1) { - // ignore this character (eg. zero-width-non-joiner U+200C) - continue; - } - c1 = j; // replace the character - } + if (IgnoreOrReplaceChar(tr, &c1) == true) + continue; + if (iswalnum(c1)) any_alnum = true;