Browse Source

cleanup: remove duplicate StringToWord()

Found with pmd-cpd static analysis
master
Juho Hiltunen 2 years ago
parent
commit
d47d2d0a40

+ 19
- 0
src/libespeak-ng/common.c View File

@@ -298,6 +298,25 @@ int Read4Bytes(FILE *f)
return acc;
}

unsigned int StringToWord(const char *string)
{
// Pack 4 characters into a word
int ix;
unsigned char c;
unsigned int word;

if (string == NULL)
return 0;

word = 0;
for (ix = 0; ix < 4; ix++) {
if (string[ix] == 0) break;
c = string[ix];
word |= (c << (ix*8));
}
return word;
}

int towlower2(unsigned int c, Translator *translator)
{
// check for non-standard upper to lower case conversions

+ 1
- 0
src/libespeak-ng/common.h View File

@@ -34,6 +34,7 @@ int IsSpace(unsigned int c);
int isspace2(unsigned int c);
int is_str_totally_null(const char* str, int size); // Tests if all bytes of str up to size are null
int Read4Bytes(FILE *f);
unsigned int StringToWord(const char *string);
int towlower2(unsigned int c, Translator *translator); // Supports Turkish I

ESPEAK_NG_API int utf8_in(int *c, const char *buf);

+ 1
- 20
src/libespeak-ng/compiledata.c View File

@@ -35,7 +35,7 @@
#include <espeak-ng/speak_lib.h>
#include <espeak-ng/encoding.h>

#include "common.h" // for GetFileLength, strncpy0, ...
#include "common.h" // for GetFileLength, strncpy0, ...c
#include "error.h" // for create_file_error_context
#include "mnemonics.h" // for LookupMnemName, MNEM_TAB
#include "phoneme.h" // for PHONEME_TAB, PHONEME_TAB_LIST
@@ -502,25 +502,6 @@ static void error_from_status(espeak_ng_STATUS status, const char *context)
error("%s.", message);
}

static unsigned int StringToWord(const char *string)
{
// Pack 4 characters into a word
int ix;
unsigned char c;
unsigned int word;

if (string == NULL)
return 0;

word = 0;
for (ix = 0; ix < 4; ix++) {
if (string[ix] == 0) break;
c = string[ix];
word |= (c << (ix*8));
}
return word;
}

static const MNEM_TAB reserved_phonemes[] = {
{ "_\001", phonCONTROL }, // NOT USED
{ "%", phonSTRESS_U },

+ 1
- 19
src/libespeak-ng/compilembrola.c View File

@@ -31,6 +31,7 @@
#include "mbrola.h"

#include "error.h" // for create_file_error_context
#include "common.h" // for StringToWord
#include "mbrola.h" // for MBROLA_TAB
#include "phoneme.h" // for N_PHONEME_TAB
#include "speech.h" // for path_home
@@ -44,25 +45,6 @@ static const char *basename(const char *filename)
return current == filename ? current : current + 1;
}

static unsigned int StringToWord(const char *string)
{
// Pack 4 characters into a word
int ix;
unsigned char c;
unsigned int word;

if (string == NULL)
return 0;

word = 0;
for (ix = 0; ix < 4; ix++) {
if (string[ix] == 0) break;
c = string[ix];
word |= (c << (ix*8));
}
return word;
}

#pragma GCC visibility push(default)
espeak_ng_STATUS espeak_ng_CompileMbrolaVoice(const char *filepath, FILE *log, espeak_ng_ERROR_CONTEXT *context)
{

Loading…
Cancel
Save