Bon, y'a quand même un moyen pas trop tordu ni compliqué pour sécuriser ça mais il faut y penser

/** CompareStrings
*
* Check if the string RefString terminated by a char of SeparatorTable is contained in the string table StringTable
* Return #item in the table, or -1 if the string isn't in the table. First item is #0
* Put in *NextChar a ptr to the next char after RefString if NextChar != NULL
**/
short CompareStrings(const char **NextChar, const char *RefString, const char *StringTable, const char *SeparatorTable)
{
// TODO
// This function could be optimized a lot, comparing char by char the two strings,
// and checking SeparatorTable if they match and *StringTable == 0.
// Here the StringTable is read twice, which is not optimal, but it's easier to write.
const char *EndChar;
const char *Separator;
short Item = 0;
unsigned long length;
while (*StringTable)
{
length = strlen(StringTable);
if (!strncmp(RefString, StringTable, length))
{
EndChar = RefString + length;
Separator = SeparatorTable;
do
{
if (*Separator == *EndChar)
{
if (NextChar != NULL)
*NextChar = EndChar;
return Item;
}
} while (*Separator++);
}
StringTable += length + 1;
Item++;
}
return -1;
}
Sasume (./371) :
(sinon pourquoi tu mixes lowerCamelCase et UpperCamelCase dans tes noms de variables ? Perso je préfère une convention différente pour les noms de variables et de fonctions, pour les différencier au premier coup d’œil)
Zerosquare (./375) :
Ouais enfin, on peut faire tst.l %a3 aussi. cmp.w, c'est naze pour le coup.
EDIT : cross
Lionel Debroux (./381) :
Le compilo d'Intel est meilleur que GCC pour les x86 Intel.
Lionel Debroux (./384) :
Je ne connaissais pas ce benchmark. En 32 bits, c'est amusant que LLVM, projet beaucoup plus récent (mais avec une architecture plus moderne...) que GCC, arrive à faire mieux que GCC. Il fait d'ailleurs également mieux que les ICC récents...
/** SkipSpaces
*
* Skip spaces and horizontal tabs. Return a pointer to the next non-space char, or to EOF
*/
const char *SkipSpaces(const char *Ptr)
{
while (*Ptr && (*Ptr != EOL) && ((*Ptr++ == SPACE) || (*Ptr == HTAB)));
return Ptr;
}
while ((*Ptr != EOL) && ((*Ptr++ == SPACE) || (*Ptr == HTAB)));