Skip to content

Instantly share code, notes, and snippets.

@sw
Created December 23, 2011 15:03
Show Gist options
  • Save sw/1514422 to your computer and use it in GitHub Desktop.
Save sw/1514422 to your computer and use it in GitHub Desktop.
SLRE: is_any_of() with escape character support
static int
is_any_of(const unsigned char *p, int len, const char *s, int *ofs)
{
int i, ch;
ch = s[*ofs];
for (i = 0; i < len; i++)
if (p[i] == ch) {
(*ofs)++;
return (1);
}
else if (p[i] == 0)
{
if ( ((p[i + 1] == SPACE) && isspace(ch) )
|| ((p[i + 1] == NONSPACE) && !isspace(ch) )
|| ((p[i + 1] == DIGIT) && isdigit(ch) )
|| ((p[i + 1] == '\0') && (ch == '\0') )
{
(*ofs)++;
return (1);
}
i++;
}
}
return (0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment