tokenizer.c: Support ellipsis tokens.

This commit is contained in:
Reece H. Dunn
2017-05-02 07:28:29 +01:00
parent 706e780ff4
commit 55bfbb4754
3 changed files with 62 additions and 2 deletions
+20 -1
View File
@@ -98,9 +98,10 @@ typedef enum {
ESPEAKNG_CTYPE_COMMA,
ESPEAKNG_CTYPE_COLON,
ESPEAKNG_CTYPE_SEMICOLON,
ESPEAKNG_CTYPE_ELLIPSIS,
} espeakng_CTYPE;
#define ESPEAKNG_CTYPE_PROPERTY_MASK 0xFC0000000000C001ull
#define ESPEAKNG_CTYPE_PROPERTY_MASK 0xFE0000000000C001ull
// Reference: http://www.unicode.org/reports/tr14/tr14-32.html -- Unicode Line Breaking Algorithm
static espeakng_CTYPE codepoint_type(uint32_t c)
@@ -151,6 +152,8 @@ static espeakng_CTYPE codepoint_type(uint32_t c)
return ESPEAKNG_CTYPE_COLON;
case ESPEAKNG_PROPERTY_SEMI_COLON:
return ESPEAKNG_CTYPE_SEMICOLON;
case ESPEAKNG_PROPERTY_ELLIPSIS:
return ESPEAKNG_CTYPE_ELLIPSIS;
}
// 4. Classify the remaining codepoints.
@@ -284,6 +287,18 @@ tokenizer_state_default(espeak_ng_TOKENIZER *tokenizer)
return tokenizer_read_word_token(tokenizer, current, ESPEAKNG_TOKEN_WORD_UPPERCASE);
case ESPEAKNG_CTYPE_FULL_STOP:
current += utf8_out(c, current);
if (c == '.' && text_decoder_peekc(tokenizer->decoder) == '.') {
c = text_decoder_getc(tokenizer->decoder);
if (text_decoder_peekc(tokenizer->decoder) == '.') {
c = text_decoder_getc(tokenizer->decoder);
current += utf8_out('.', current);
current += utf8_out('.', current);
*current = '\0';
return ESPEAKNG_TOKEN_ELLIPSIS;
} else {
tokenizer->keepc = c;
}
}
*current = '\0';
return ESPEAKNG_TOKEN_FULL_STOP;
case ESPEAKNG_CTYPE_QUESTION_MARK:
@@ -306,6 +321,10 @@ tokenizer_state_default(espeak_ng_TOKENIZER *tokenizer)
current += utf8_out(c, current);
*current = '\0';
return ESPEAKNG_TOKEN_SEMICOLON;
case ESPEAKNG_CTYPE_ELLIPSIS:
current += utf8_out(c, current);
*current = '\0';
return ESPEAKNG_TOKEN_ELLIPSIS;
default:
current += utf8_out(c, current);
*current = '\0';
+1
View File
@@ -57,6 +57,7 @@ typedef enum
ESPEAKNG_TOKEN_COMMA,
ESPEAKNG_TOKEN_COLON,
ESPEAKNG_TOKEN_SEMICOLON,
ESPEAKNG_TOKEN_ELLIPSIS,
} espeak_ng_TOKEN_TYPE;
espeak_ng_TOKEN_TYPE