Revert to while loop for nextCharacter()

This commit is contained in:
Steve 2020-03-28 13:52:17 +00:00
parent f3bb77ca81
commit 7e14550cc1
1 changed files with 15 additions and 35 deletions

View File

@ -396,46 +396,26 @@ int getWrappedTextHeight(char *text, int size)
static char *nextCharacter(const char *str, int *i) static char *nextCharacter(const char *str, int *i)
{ {
unsigned char bit; unsigned char bit;
int numBits; int n;
memset(character, '\0', MAX_NAME_LENGTH); memset(character, '\0', MAX_NAME_LENGTH);
n = 0;
while (1)
{
bit = (unsigned char)str[*i]; bit = (unsigned char)str[*i];
numBits = 0; if ((bit >= ' ' && bit <= '~') || bit >= 0xC0 || bit == '\0')
if (bit == '\0')
{ {
return NULL; if (n > 0)
{
return character[0] != '\0' ? character : NULL;
} }
else if (bit <= 0x0000007F)
{
numBits = 1;
}
else if (bit <= 0x000007FF)
{
numBits = 2;
}
else if (bit <= 0x0000FFFF)
{
numBits = 3;
}
else if (bit <= 0x001FFFFF)
{
numBits = 4;
}
else if (bit <= 0x03FFFFFF)
{
numBits = 5;
}
else if (bit <= 0x7FFFFFFF)
{
numBits = 6;
} }
memcpy(character, &str[*i], numBits); character[n++] = str[*i];
(*i) += numBits; *i = *i + 1;
}
return character;
} }