Browse Source

cleanup: refactor duplicate loops to CalcWordLength().

Note: This code has no tests. Tests would pass even without a call to
this function.
master
Juho Hiltunen 2 years ago
parent
commit
319ce7b09f
1 changed files with 19 additions and 20 deletions
  1. 19
    20
      src/libespeak-ng/translate.c

+ 19
- 20
src/libespeak-ng/translate.c View File

#include "speech.h" // for MAKE_MEM_UNDEFINED #include "speech.h" // for MAKE_MEM_UNDEFINED
#include "translateword.h" #include "translateword.h"


static int CalcWordLength(int source_index, int charix_top, short int *charix, WORD_TAB *words, int word_count);
static void CombineFlag(Translator *tr, WORD_TAB *wtab, char *word, int *flags, unsigned char *p, char *word_phonemes); static void CombineFlag(Translator *tr, WORD_TAB *wtab, char *word, int *flags, unsigned char *p, char *word_phonemes);
static void SwitchLanguage(char *word, char *word_phonemes); static void SwitchLanguage(char *word, char *word_phonemes);


words[0].start = ix; words[0].start = ix;
words[0].flags = 0; words[0].flags = 0;


for (j = 0; charix[j] <= 0; j++) ;
words[0].sourceix = charix[j];
k = 0;
while (charix[j] != 0) {
// count the number of characters (excluding multibyte continuation bytes)
if (charix[j++] != -1)
k++;
}
words[0].length = k;
words[0].length = CalcWordLength(source_index, charix_top, charix, words, 0);


while (!finished && (ix < (int)sizeof(sbuf) - 1)) { while (!finished && (ix < (int)sizeof(sbuf) - 1)) {
prev_out2 = prev_out; prev_out2 = prev_out;
words[word_count].start = ix; words[word_count].start = ix;
words[word_count].flags = 0; words[word_count].flags = 0;


for (j = source_index; j < charix_top && charix[j] <= 0; j++) // skip blanks
;
words[word_count].sourceix = charix[j];
k = 0;
while (charix[j] != 0) {
// count the number of characters (excluding multibyte continuation bytes)
if (charix[j++] != -1)
k++;
}
words[word_count].length = k;
words[word_count].length = CalcWordLength(source_index, charix_top, charix, words, word_count);


word_flags = next_word_flags; word_flags = next_word_flags;
next_word_flags = 0; next_word_flags = 0;
} }
} }


static int CalcWordLength(int source_index, int charix_top, short int *charix, WORD_TAB *words, int word_count) {
int j;
int k;

for (j = source_index; j < charix_top && charix[j] <= 0; j++); // skip blanks
words[word_count].sourceix = charix[j];
k = 0;
while (charix[j] != 0) {
// count the number of characters (excluding multibyte continuation bytes)
if (charix[j++] != -1)
k++;
}
return k;
}

static void CombineFlag(Translator *tr, WORD_TAB *wtab, char *word, int *flags, unsigned char *p, char *word_phonemes) { static void CombineFlag(Translator *tr, WORD_TAB *wtab, char *word, int *flags, unsigned char *p, char *word_phonemes) {
// combine a preposition with the following word // combine a preposition with the following word




if ((control & espeakKEEP_NAMEDATA) == 0) if ((control & espeakKEEP_NAMEDATA) == 0)
InitNamedata(); InitNamedata();
}
}

Loading…
Cancel
Save