Review GetTextIcon() for #67

This commit is contained in:
Ray 2020-01-26 12:00:33 +01:00
parent e1e296583e
commit aa28f6c759

View File

@ -669,21 +669,23 @@ static const char *GetTextIcon(const char *text, int *iconId)
*iconId = -1; *iconId = -1;
if (text[0] == '#') // Maybe we have an icon! if (text[0] == '#') // Maybe we have an icon!
{ {
char iconValue[4] = { 0 }; char iconValue[4] = { 0 }; // Maximum length for icon value: 3 digits + '\0'
int i = 1; int pos = 1;
for (i = 1; i < 4; i++) while ((pos < 4) && (text[pos] >= '0') && (text[pos] <= '9'))
{ {
if ((text[i] != '#') && (text[i] != '\0')) iconValue[i - 1] = text[i]; iconValue[pos - 1] = text[pos];
else break; pos++;
} }
if (text[pos] == '#')
{
*iconId = TextToInteger(iconValue);
iconValue[3] = '\0'; // Move text pointer after icon
*iconId = TextToInteger(iconValue); // WARNING: If only icon provided, it could point to EOL character!
if (*iconId >= 0) text += (pos + 1);
// Move text pointer after icon }
// WARNING: If only icon provided, it could point to EOL character!
if (*iconId >= 0) text += (i + 1);
} }
#endif #endif