encoding.c: Support determining the string length for length < 0.

This commit is contained in:
Reece H. Dunn
2017-04-01 13:23:09 +01:00
parent b5ed1f28a5
commit 9dabf64680
4 changed files with 53 additions and 25 deletions
+8
View File
@@ -17,8 +17,10 @@
#include "config.h"
#include <string.h>
#include <stdint.h>
#include <stdlib.h>
#include <wchar.h>
#include <espeak-ng/espeak_ng.h>
@@ -684,6 +686,8 @@ text_decoder_decode_string(espeak_ng_TEXT_DECODER *decoder,
if (enc->get == NULL)
return ENS_UNKNOWN_TEXT_ENCODING;
if (length < 0) length = string ? strlen(string) + 1 : 0;
decoder->get = string ? enc->get : null_decoder_getc;
decoder->codepage = enc->codepage;
decoder->current = (const uint8_t *)string;
@@ -704,6 +708,8 @@ text_decoder_decode_string_auto(espeak_ng_TEXT_DECODER *decoder,
if (enc->get == NULL)
return ENS_UNKNOWN_TEXT_ENCODING;
if (length < 0) length = string ? strlen(string) + 1 : 0;
decoder->get = string ? string_decoder_getc_auto : null_decoder_getc;
decoder->codepage = enc->codepage;
decoder->current = (const uint8_t *)string;
@@ -716,6 +722,8 @@ text_decoder_decode_wstring(espeak_ng_TEXT_DECODER *decoder,
const wchar_t *string,
int length)
{
if (length < 0) length = string ? wcslen(string) + 1 : 0;
decoder->get = string ? string_decoder_getc_wchar : null_decoder_getc;
decoder->codepage = NULL;
decoder->current = (const uint8_t *)string;
+1 -1
View File
@@ -1,7 +1,7 @@
/*
* Copyright (C) 2005 to 2015 by Jonathan Duddington
* email: jonsd@users.sourceforge.net
* Copyright (C) 2015-2016 Reece H. Dunn
* Copyright (C) 2015-2017 Reece H. Dunn
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
+6 -21
View File
@@ -1,7 +1,7 @@
/*
* Copyright (C) 2005 to 2014 by Jonathan Duddington
* email: jonsd@users.sourceforge.net
* Copyright (C) 2015-2016 Reece H. Dunn
* Copyright (C) 2015-2017 Reece H. Dunn
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -1916,21 +1916,6 @@ int UpperCaseInWord(Translator *tr, char *word, int c)
return 0;
}
static inline espeak_ng_STATUS init_wstring_decoder(const wchar_t *text)
{
return text_decoder_decode_wstring(p_decoder, text, wcslen(text) + 1);
}
static inline espeak_ng_STATUS init_string_decoder(const char *text, espeak_ng_ENCODING encoding)
{
return text_decoder_decode_string(p_decoder, text, strlen(text) + 1, encoding);
}
static inline espeak_ng_STATUS init_string_decoder_auto(const char *text, espeak_ng_ENCODING encoding)
{
return text_decoder_decode_string_auto(p_decoder, text, strlen(text) + 1, encoding);
}
const void *TranslateClause(Translator *tr, const void *vp_input, int *tone_out, char **voice_change)
{
int ix;
@@ -1988,19 +1973,19 @@ const void *TranslateClause(Translator *tr, const void *vp_input, int *tone_out,
switch (option_multibyte)
{
case espeakCHARS_WCHAR:
init_wstring_decoder((const wchar_t *)vp_input);
text_decoder_decode_wstring(p_decoder, (const wchar_t *)vp_input, -1);
break;
case espeakCHARS_AUTO:
init_string_decoder_auto((const char *)vp_input, tr->encoding);
text_decoder_decode_string_auto(p_decoder, (const char *)vp_input, -1, tr->encoding);
break;
case espeakCHARS_UTF8:
init_string_decoder((const char *)vp_input, ESPEAKNG_ENCODING_UTF_8);
text_decoder_decode_string(p_decoder, (const char *)vp_input, -1, ESPEAKNG_ENCODING_UTF_8);
break;
case espeakCHARS_8BIT:
init_string_decoder((const char *)vp_input, tr->encoding);
text_decoder_decode_string(p_decoder, (const char *)vp_input, -1, tr->encoding);
break;
case espeakCHARS_16BIT:
init_string_decoder((const char *)vp_input, ESPEAKNG_ENCODING_ISO_10646_UCS_2);
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