Browse Source

Simplify printing the replace message.

master
Reece H. Dunn 6 years ago
parent
commit
252f5772ae
1 changed files with 16 additions and 18 deletions
  1. 16
    18
      src/libespeak-ng/translate.c

+ 16
- 18
src/libespeak-ng/translate.c View File

return 1; return 1;
} }


static const char *
FindReplacementChars(Translator *tr, unsigned int c, unsigned int nextc, bool *ignore_next) {
static const char * FindReplacementChars(
Translator *tr,
const char **pfrom,
unsigned int c,
unsigned int nextc,
bool *ignore_next
) {
unsigned int uc = 0; unsigned int uc = 0;
const char *from = (const char *)tr->langopts.replace_chars;
const char *from = *pfrom;
while (*(unsigned int *)from != 0) { while (*(unsigned int *)from != 0) {
*pfrom = from;

from += utf8_in((int *)&uc, from); from += utf8_in((int *)&uc, from);
if (c == uc) { if (c == uc) {
if (*from == 0) return from + 1; if (*from == 0) return from + 1;
} }
if (c == 0) return 0; if (c == 0) return 0;


if (tr->langopts.replace_chars == NULL)
const char *from = (const char *)tr->langopts.replace_chars;
if (from == NULL)
return c; return c;


// there is a list of character codes to be substituted with alternative codes // there is a list of character codes to be substituted with alternative codes
upper_case = 1; upper_case = 1;
} }


const char *to = FindReplacementChars(tr, c_lower, next_in, &ignore_next);
const char *to = FindReplacementChars(tr, &from, c_lower, next_in, &ignore_next);
if (to == NULL) if (to == NULL)
return c; // no substitution return c; // no substitution


if (option_phonemes & espeakPHONEMES_TRACE)
fprintf(f_trans, "Replace: %s > %s\n", from, to);

to += utf8_in((int *)&new_c, to); to += utf8_in((int *)&new_c, to);
if (*to != 0) { if (*to != 0) {
// there is a second character to be inserted // there is a second character to be inserted
new_c = ucd_toupper(new_c); new_c = ucd_toupper(new_c);


*wordflags |= FLAG_CHAR_REPLACED; *wordflags |= FLAG_CHAR_REPLACED;
if (option_phonemes & espeakPHONEMES_TRACE) {
char msg[21] = {'R','e','p','l','a','c','e',':',' '};
char *index = msg;
index += 9;
index += utf8_out(c, index);
*index++ = ' ';
*index++ = '>';
*index++ = ' ';
index += utf8_out(new_c, index);
index += utf8_out(c2, index);
*index = 0;
fprintf(f_trans, "%s\n", msg);
}
return new_c; return new_c;
} }



Loading…
Cancel
Save