From 14ede3e37268685fc40310ef63f323ed9947741b Mon Sep 17 00:00:00 2001 From: Juho Hiltunen Date: Sat, 17 Sep 2022 17:28:52 +0300 Subject: [PATCH] code cleanup: move is_str_totally_null() --- src/libespeak-ng/common.c | 11 +++++++++++ src/libespeak-ng/common.h | 1 + src/libespeak-ng/dictionary.c | 2 +- src/libespeak-ng/readclause.c | 8 -------- src/libespeak-ng/readclause.h | 3 --- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/libespeak-ng/common.c b/src/libespeak-ng/common.c index f810ebbe..e9d2decc 100644 --- a/src/libespeak-ng/common.c +++ b/src/libespeak-ng/common.c @@ -167,6 +167,15 @@ int utf8_in2(int *c, const char *buf, int backwards) return n_bytes+1; } + +int is_str_totally_null(const char* str, int size) { + // Tests if all bytes of str are null up to size + // This should never be reimplemented with integers, because + // this function has to work with unaligned char* + // (casting to int when unaligned may result in ungaranteed behaviors) + return (*str == 0 && memcmp(str, str+1, size-1) == 0); +} + int towlower2(unsigned int c, Translator *translator) { // check for non-standard upper to lower case conversions @@ -175,3 +184,5 @@ int towlower2(unsigned int c, Translator *translator) return ucd_tolower(c); } + + diff --git a/src/libespeak-ng/common.h b/src/libespeak-ng/common.h index bb33e183..2ad7007b 100644 --- a/src/libespeak-ng/common.h +++ b/src/libespeak-ng/common.h @@ -26,6 +26,7 @@ extern ESPEAK_NG_API int GetFileLength(const char *filename); extern ESPEAK_NG_API void strncpy0(char *to, const char *from, int size); +int is_str_totally_null(const char* str, int size); // Tests if all bytes of str up to size are null int towlower2(unsigned int c, Translator *translator); // Supports Turkish I ESPEAK_NG_API int utf8_in(int *c, const char *buf); diff --git a/src/libespeak-ng/dictionary.c b/src/libespeak-ng/dictionary.c index 98d2e0da..49a7549c 100644 --- a/src/libespeak-ng/dictionary.c +++ b/src/libespeak-ng/dictionary.c @@ -36,7 +36,7 @@ #include "dictionary.h" #include "numbers.h" // for LookupAccentedLetter, Look... #include "phoneme.h" // for PHONEME_TAB, phVOWEL, phon... -#include "readclause.h" // for WordToString2, is_str_tota... +#include "readclause.h" // for WordToString2 #include "speech.h" // for path_home #include "compiledict.h" // for DecodeRule #include "synthdata.h" // for PhonemeCode, InterpretPhoneme diff --git a/src/libespeak-ng/readclause.c b/src/libespeak-ng/readclause.c index 03ce76a7..a8529c24 100644 --- a/src/libespeak-ng/readclause.c +++ b/src/libespeak-ng/readclause.c @@ -131,14 +131,6 @@ int clause_type_from_codepoint(uint32_t c) return CLAUSE_NONE; } -int is_str_totally_null(const char* str, int size) { - // Tests if all bytes of str are null up to size - // This should never be reimplemented with integers, because - // this function has to work with unaligned char* - // (casting to int when unaligned may result in ungaranteed behaviors) - return (*str == 0 && memcmp(str, str+1, size-1) == 0); -} - static int IsRomanU(unsigned int c) { if ((c == 'I') || (c == 'V') || (c == 'X') || (c == 'L')) diff --git a/src/libespeak-ng/readclause.h b/src/libespeak-ng/readclause.h index c2d2ea3b..2692ddfd 100644 --- a/src/libespeak-ng/readclause.h +++ b/src/libespeak-ng/readclause.h @@ -34,9 +34,6 @@ typedef struct { extern PARAM_STACK param_stack[]; -// Tests if all bytes of str up to size are null -int is_str_totally_null(const char* str, int size); - int clause_type_from_codepoint(uint32_t c); int Eof(void); const char *WordToString2(unsigned int word);