Browse Source

cleanup: refactor checking for _^_ to function SwitchLanguage()

master
Juho Hiltunen 2 years ago
parent
commit
139eef57d2
1 changed files with 28 additions and 20 deletions
  1. 28
    20
      src/libespeak-ng/translate.c

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

#include "translateword.h" #include "translateword.h"


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);


Translator *translator = NULL; // the main translator Translator *translator = NULL; // the main translator
Translator *translator2 = NULL; // secondary translator for certain words Translator *translator2 = NULL; // secondary translator for certain words
p = (unsigned char *)word_phonemes; p = (unsigned char *)word_phonemes;
if (word_flags & FLAG_PHONEMES) { if (word_flags & FLAG_PHONEMES) {
// The input is in phoneme mnemonics, not language text // The input is in phoneme mnemonics, not language text
int c1;
char lang_name[12];


if (memcmp(word, "_^_", 3) == 0) { if (memcmp(word, "_^_", 3) == 0) {
// switch languages
word += 3;
for (ix = 0;;) {
c1 = *word++;
if ((c1 == ' ') || (c1 == 0))
break;
lang_name[ix++] = tolower(c1);
}
lang_name[ix] = 0;

if ((ix = LookupPhonemeTable(lang_name)) > 0) {
SelectPhonemeTable(ix);
word_phonemes[0] = phonSWITCH;
word_phonemes[1] = ix;
word_phonemes[2] = 0;
}
} else
SwitchLanguage(word, word_phonemes);
} else {
EncodePhonemes(word, word_phonemes, &bad_phoneme); EncodePhonemes(word, word_phonemes, &bad_phoneme);
}

flags = FLAG_FOUND; flags = FLAG_FOUND;
} else { } else {
int c2; int c2;
} }
} }



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


} }
} }


static void SwitchLanguage(char *word, char *word_phonemes) {
char lang_name[12];
int ix;
int c1;

word += 3;

for (ix = 0;;) {
c1 = *word++;
if ((c1 == ' ') || (c1 == 0))
break;
lang_name[ix++] = tolower(c1);
}
lang_name[ix] = 0;

if ((ix = LookupPhonemeTable(lang_name)) > 0) {
SelectPhonemeTable(ix);
word_phonemes[0] = phonSWITCH;
word_phonemes[1] = ix;
word_phonemes[2] = 0;
}
}

void InitText(int control) void InitText(int control)
{ {
count_sentences = 0; count_sentences = 0;

Loading…
Cancel
Save