encoding.c: Support using wchar_t strings with the text decoder API.

This commit is contained in:
Reece H. Dunn
2017-03-30 22:52:38 +01:00
parent 2de0368d39
commit 6a0b5e4ae1
3 changed files with 48 additions and 0 deletions
+20
View File
@@ -581,6 +581,14 @@ string_decoder_getc_iso_10646_ucs_2(espeak_ng_TEXT_DECODER *decoder)
return c1 + (c2 << 8);
}
static uint32_t
string_decoder_getc_wchar(espeak_ng_TEXT_DECODER *decoder)
{
wchar_t c = *(const wchar_t *)decoder->current;
decoder->current += sizeof(wchar_t);
return c;
}
typedef struct
{
uint32_t (*get)(espeak_ng_TEXT_DECODER *decoder);
@@ -651,6 +659,18 @@ text_decoder_decode_string(espeak_ng_TEXT_DECODER *decoder,
return ENS_OK;
}
espeak_ng_STATUS
text_decoder_decode_wstring(espeak_ng_TEXT_DECODER *decoder,
const wchar_t *string,
int length)
{
decoder->get = string_decoder_getc_wchar;
decoder->codepage = NULL;
decoder->current = (const uint8_t *)string;
decoder->end = (const uint8_t *)(string + length);
return ENS_OK;
}
int
text_decoder_eof(espeak_ng_TEXT_DECODER *decoder)
{
+5
View File
@@ -36,6 +36,11 @@ text_decoder_decode_string(espeak_ng_TEXT_DECODER *decoder,
int length,
espeak_ng_ENCODING encoding);
espeak_ng_STATUS
text_decoder_decode_wstring(espeak_ng_TEXT_DECODER *decoder,
const wchar_t *string,
int length);
int
text_decoder_eof(espeak_ng_TEXT_DECODER *decoder);