Skip to content

Instantly share code, notes, and snippets.

Created January 11, 2013 08:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/4509088 to your computer and use it in GitHub Desktop.
Save anonymous/4509088 to your computer and use it in GitHub Desktop.
template <size_t N>
const char* find_param(request* r, const char (&psz)[N]) {
char name[N + 2] = "&";
memcpy(name + 1, psz, N - 1);
name[N] = '=';
if (strncmp(r->query, name + 1, N)) {
return strstr(r->query, name);
} else {
return args;
}
}
// ...
const char* textStart = find_param(r, "text");
// ... check for NULL, find first '&' after textStart and do something useful
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment