mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-12-07 13:45:03 -05:00
talk: Rework utf8-awareness in talk_spell()
* Eliminates warning on 16-bit unicode devices * More efficient * Still correct Change-Id: I8d29f5560bc6f34b935e867d184a62a280b33596
This commit is contained in:
parent
ebaa78542d
commit
eeb8a893f1
1 changed files with 3 additions and 12 deletions
15
apps/talk.c
15
apps/talk.c
|
|
@ -764,24 +764,15 @@ static int _talk_spell(const char* spell, size_t len, bool enqueue)
|
|||
|
||||
do_enqueue(enqueue); /* cut off all the pending stuff */
|
||||
|
||||
const char *last = spell;
|
||||
size_t len0 = len - 1;
|
||||
|
||||
/* Tokenize into UTF8 codepoints */
|
||||
while ((spell = utf8decode(spell, &c)), c != '\0')
|
||||
{
|
||||
int count;
|
||||
if (c <= 0x7f)
|
||||
count = 1;
|
||||
else if (c <= 0x7ff)
|
||||
count = 2;
|
||||
else if (c <= 0xffff)
|
||||
count = 3;
|
||||
else
|
||||
count = 4;
|
||||
|
||||
len0 -= count;
|
||||
len0 -= (spell - last);
|
||||
if (len0 >= len) /* ie we underflow and wrap */
|
||||
break;
|
||||
last = spell;
|
||||
|
||||
/* NOTE: This is COMPLETLY BROKEN for NON-ENGLISH */
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue