From da7eaa7b9ca4fc81d54be41cc7cc6670d9c084dc Mon Sep 17 00:00:00 2001 From: "Reece H. Dunn" Date: Mon, 27 Mar 2017 22:16:04 +0100 Subject: [PATCH] encoding.c: Create a text decoder API based on the usage in readclause.c. --- src/libespeak-ng/encoding.c | 35 ++++++++++++++++++++++++++++++ src/libespeak-ng/encoding.h | 43 +++++++++++++++++++++++++++++++++++++ tests/encoding.c | 17 +++++++++++++++ 3 files changed, 95 insertions(+) create mode 100644 src/libespeak-ng/encoding.h diff --git a/src/libespeak-ng/encoding.c b/src/libespeak-ng/encoding.c index 44b246b8..63673976 100644 --- a/src/libespeak-ng/encoding.c +++ b/src/libespeak-ng/encoding.c @@ -17,9 +17,13 @@ #include "config.h" +#include +#include + #include #include "speech.h" +#include "encoding.h" // http://www.iana.org/assignments/character-sets/character-sets.xhtml MNEM_TAB mnem_encoding[] = { @@ -45,3 +49,34 @@ espeak_ng_EncodingFromName(const char *encoding) } #pragma GCC visibility pop + +struct espeak_ng_TEXT_DECODER_ +{ +}; + +espeak_ng_TEXT_DECODER * +create_text_decoder(void) +{ + espeak_ng_TEXT_DECODER *decoder = malloc(sizeof(espeak_ng_TEXT_DECODER)); + if (!decoder) return NULL; + + return decoder; +} + +void +destroy_text_decoder(espeak_ng_TEXT_DECODER *decoder) +{ + if (decoder) free(decoder); +} + +int +text_decoder_eof(espeak_ng_TEXT_DECODER *decoder) +{ + return 1; +} + +uint32_t +text_decoder_getc(espeak_ng_TEXT_DECODER *decoder) +{ + return 0; +} diff --git a/src/libespeak-ng/encoding.h b/src/libespeak-ng/encoding.h new file mode 100644 index 00000000..de57ef59 --- /dev/null +++ b/src/libespeak-ng/encoding.h @@ -0,0 +1,43 @@ +/* + * Copyright (C) 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see: . + */ +#ifndef ESPEAK_NG_ENCODING_H +#define ESPEAK_NG_ENCODING_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +typedef struct espeak_ng_TEXT_DECODER_ espeak_ng_TEXT_DECODER; + +espeak_ng_TEXT_DECODER * +create_text_decoder(void); + +void +destroy_text_decoder(espeak_ng_TEXT_DECODER *decoder); + +int +text_decoder_eof(espeak_ng_TEXT_DECODER *decoder); + +uint32_t +text_decoder_getc(espeak_ng_TEXT_DECODER *decoder); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/tests/encoding.c b/tests/encoding.c index 7843cd2f..a47c26b7 100644 --- a/tests/encoding.c +++ b/tests/encoding.c @@ -19,10 +19,26 @@ #include "config.h" #include +#include #include #include #include +#include "encoding.h" + +void +test_unbound_text_decoder() +{ + printf("testing unbound text decoder\n"); + + espeak_ng_TEXT_DECODER *decoder = create_text_decoder(); + + assert(decoder != NULL); + assert(text_decoder_eof(decoder) == 1); + assert(text_decoder_getc(decoder) == 0); + + destroy_text_decoder(decoder); +} void test_unknown_encoding() @@ -55,6 +71,7 @@ test_us_ascii_encoding() int main(int argc, char **argv) { + test_unbound_text_decoder(); test_unknown_encoding(); test_us_ascii_encoding(); printf("done\n");