From b3e0fbc8ed41ea24afe49d7617f5535638fdccf0 Mon Sep 17 00:00:00 2001 From: "Reece H. Dunn" Date: Sat, 1 Apr 2017 13:35:54 +0100 Subject: [PATCH] encoding.c: Create a text_decoder_decode_string_multibyte helper to work with the espeakCHARS_* flags. --- src/libespeak-ng/encoding.c | 23 +++++++++++++++++++++++ src/libespeak-ng/encoding.h | 6 ++++++ src/libespeak-ng/translate.c | 22 ++-------------------- 3 files changed, 31 insertions(+), 20 deletions(-) diff --git a/src/libespeak-ng/encoding.c b/src/libespeak-ng/encoding.c index 785e8483..b6bc2db2 100644 --- a/src/libespeak-ng/encoding.c +++ b/src/libespeak-ng/encoding.c @@ -731,6 +731,29 @@ text_decoder_decode_wstring(espeak_ng_TEXT_DECODER *decoder, return ENS_OK; } +espeak_ng_STATUS +text_decoder_decode_string_multibyte(espeak_ng_TEXT_DECODER *decoder, + const void *input, + espeak_ng_ENCODING encoding, + int flags) +{ + switch (flags & 7) + { + case espeakCHARS_WCHAR: + return text_decoder_decode_wstring(decoder, (const wchar_t *)input, -1); + case espeakCHARS_AUTO: + return text_decoder_decode_string_auto(decoder, (const char *)input, -1, encoding); + case espeakCHARS_UTF8: + return text_decoder_decode_string(decoder, (const char *)input, -1, ESPEAKNG_ENCODING_UTF_8); + case espeakCHARS_8BIT: + return text_decoder_decode_string(decoder, (const char *)input, -1, encoding); + case espeakCHARS_16BIT: + return text_decoder_decode_string(decoder, (const char *)input, -1, ESPEAKNG_ENCODING_ISO_10646_UCS_2); + default: + return ENS_UNKNOWN_TEXT_ENCODING; + } +} + int text_decoder_eof(espeak_ng_TEXT_DECODER *decoder) { diff --git a/src/libespeak-ng/encoding.h b/src/libespeak-ng/encoding.h index 00ce022b..01a2fdcd 100644 --- a/src/libespeak-ng/encoding.h +++ b/src/libespeak-ng/encoding.h @@ -47,6 +47,12 @@ text_decoder_decode_wstring(espeak_ng_TEXT_DECODER *decoder, const wchar_t *string, int length); +espeak_ng_STATUS +text_decoder_decode_string_multibyte(espeak_ng_TEXT_DECODER *decoder, + const void *input, + espeak_ng_ENCODING encoding, + int flags); + int text_decoder_eof(espeak_ng_TEXT_DECODER *decoder); diff --git a/src/libespeak-ng/translate.c b/src/libespeak-ng/translate.c index 009dabae..03e6dda1 100644 --- a/src/libespeak-ng/translate.c +++ b/src/libespeak-ng/translate.c @@ -1970,26 +1970,8 @@ const void *TranslateClause(Translator *tr, const void *vp_input, int *tone_out, if (p_decoder == NULL) p_decoder = create_text_decoder(); - switch (option_multibyte) - { - case espeakCHARS_WCHAR: - text_decoder_decode_wstring(p_decoder, (const wchar_t *)vp_input, -1); - break; - case espeakCHARS_AUTO: - text_decoder_decode_string_auto(p_decoder, (const char *)vp_input, -1, tr->encoding); - break; - case espeakCHARS_UTF8: - text_decoder_decode_string(p_decoder, (const char *)vp_input, -1, ESPEAKNG_ENCODING_UTF_8); - break; - case espeakCHARS_8BIT: - text_decoder_decode_string(p_decoder, (const char *)vp_input, -1, tr->encoding); - break; - case espeakCHARS_16BIT: - text_decoder_decode_string(p_decoder, (const char *)vp_input, -1, ESPEAKNG_ENCODING_ISO_10646_UCS_2); - break; - default: - return NULL; // unknown multibyte option value - } + if (text_decoder_decode_string_multibyte(p_decoder, vp_input, tr->encoding, option_multibyte) != ENS_OK) + return NULL; embedded_ix = 0; embedded_read = 0;