- //Must be first so value will be empty if it's not specified
- if ((next = strchr(in, '&'))) {
- *next++ = 0;
- } else { //Don't return NULL as current pair needs to be returned
- next = "";
- }
- if ((split = strchr(in, '='))) {
- *split++ = 0;
- *value = split;
- return next;
+ //Find either = or &, whichever comes first
+ if ((ptr = strpbrk(in, "=&"))) {
+ if (*ptr == '&') { //No value specified
+ *value = ptr;
+ *ptr++ = 0;
+ } else {
+ //Stopped at an '=' sign
+ *ptr++ = 0;
+ *value = ptr;
+ if ((ptr = strchr(ptr,'&'))) {
+ *ptr++ = 0;
+ } else {
+ ptr = "";
+ }
+ }
+ } else { //No value specified and no other pair
+ ptr = "";
+ *value = ptr;