- int gnum = 0;
- bool esc = false;
- for (int i = 0; i < str.size(); ++i)
- {
- if (!esc && str[i] == '\\')
- {
- esc = true;
- continue;
- }
- if (!esc && str[i] == '(') //group starts
- {
- gnum++;
- if (i+1 < str.size() && str[i+1] == '?') //group with attrs
- {
- i++;
- if (i+1 < str.size() && str[i+1] == ':') //non-capturing
- {
- if (gnum > 0) gnum--;
- i++;
- continue;
- }
- if (i+1 < str.size() && str[i+1] == 'P') //optional, python
- i++;
- if (i+1 < str.size() && str[i+1] == '<') //named
- {
- i++;
- std::string gname;
- bool term = false;
- while (++i < str.size())
- {
- if (str[i] == '>') { term = true; break; }
- if (!isalnum(str[i]))
- throw mp::filter::FilterException
- ("Only alphanumeric chars allowed, found "
- " in '"
- + str
- + "' at "
- + boost::lexical_cast<std::string>(i));
- gname += str[i];
- }
- if (!term)
- throw mp::filter::FilterException
- ("Unterminated group name '" + gname
- + " in '" + str +"'");
- groups_bynum[gnum] = gname;
- groups_byname[gname] = gnum;
- std::cout << "Found named group '" << gname
- << "' at $" << gnum << std::endl;
- }
- }
- }
- esc = false;
- }
+ for (int h = 0; h < uri_pats.size(); h++)
+ {
+ int gnum = 0;
+ bool esc = false;
+ //regex is first, subpat is second
+ std::string str = uri_pats[h].first;
+ //for each pair we have an indexing map
+ std::map<int, std::string> groups_bynum;
+ for (int i = 0; i < str.size(); ++i)
+ {
+ if (!esc && str[i] == '\\')
+ {
+ esc = true;
+ continue;
+ }
+ if (!esc && str[i] == '(') //group starts
+ {
+ gnum++;
+ if (i+1 < str.size() && str[i+1] == '?') //group with attrs
+ {
+ i++;
+ if (i+1 < str.size() && str[i+1] == ':') //non-capturing
+ {
+ if (gnum > 0) gnum--;
+ i++;
+ continue;
+ }
+ if (i+1 < str.size() && str[i+1] == 'P') //optional, python
+ i++;
+ if (i+1 < str.size() && str[i+1] == '<') //named
+ {
+ i++;
+ std::string gname;
+ bool term = false;
+ while (++i < str.size())
+ {
+ if (str[i] == '>') { term = true; break; }
+ if (!isalnum(str[i]))
+ throw mp::filter::FilterException
+ ("Only alphanumeric chars allowed, found "
+ " in '"
+ + str
+ + "' at "
+ + boost::lexical_cast<std::string>(i));
+ gname += str[i];
+ }
+ if (!term)
+ throw mp::filter::FilterException
+ ("Unterminated group name '" + gname
+ + " in '" + str +"'");
+ groups_bynum[gnum] = gname;
+ std::cout << "Found named group '" << gname
+ << "' at $" << gnum << std::endl;
+ }
+ }
+ }
+ esc = false;
+ }
+ groups_bynum_vec.push_back(groups_bynum);
+ }