/g/ - Technology
install openbsd
[Make a Post]I'd use strpbrk with the complement of your set, saves you the strlen call.
>>1409
The complement of a typical set in my use case? That would have over 200 characters in it. I think the added overhead from looping through 200 chars (or however strpbrk() does it) would kill any performance gains.
Is writing a dedicated function here a good idea? Presumably the optimized libc functions would still be faster, even if not used optimally.
>>1410
If the performance of your program REALLY depends on this function, you can try with a lookup table.
>>1410
>That would have over 200 characters in it. I think the added overhead from looping through 200 chars (or however strpbrk() does it) would kill any performance gains.
m8, your set is probably compiled into a 256 cells lookup table, it doesn't change anything what size your set is.
>>1440
>nowhere in the documentation does it mention that there is a 256 char limit
Think for 3 seconds before posting
[Catalog][Overboard][Update]
[Reply]9 replies
Is this the best way of making sure that all characters in a string are members of a specified character set? Or is there an even simpler method?
#include <string.h>
int valid(const char *str, const char *set)
{
return (strspn(str, set) == strlen(str));
}