Code: Select all
put the number of items of "1,2,3,4" -- returns 4
put the number of items of "1,2,3,4," -- returns 4 with final comma
put the number of items of "1,2,3,4, " -- returns 5 with trailing space
Code: Select all
static int4 countitems(MCExecPoint &ep, const char *sptr, const char *eptr)
{
int4 items = 1;
if (sptr < eptr)
do
{
if (*sptr == ep.getitemdel() && sptr + 1 < eptr)
items++;
}
while (++sptr < eptr);
return items;
}
Code: Select all
if (*sptr == ep.getitemdel())
So... given that the function correctly does what's expected, I have two questions:
1. Why is the extra test in the conditional in the first place? It produces confusing, and IMO wrong, results and seems to provide no other purpose.
2. What would be the repercussions of making the change? Are there code scenarios that explicitly rely on the existing behavior? I can't come up with any off the top of my head, and in fact the only things that come to mind are scripts that might try to account for the current behavior by doing a secondary check and correcting for it. Database queries perhaps?