| 462 | } |
| 463 | |
| 464 | int CAction::executeRegExp(const char* P_string, VariableTable *P_callVarTable) |
| 465 | { |
| 466 | regmatch_t pmatch[10]; |
| 467 | int error; |
| 468 | int nbOfMatch = 0; |
| 469 | char* result = nullptr ; |
| 470 | |
| 471 | if (!M_regExpSet) { |
| 472 | ERROR("Trying to perform regular expression match on action that does not have one!"); |
| 473 | } |
| 474 | |
| 475 | if (getNbSubVarId() > 9) { |
| 476 | ERROR("You can only have nine sub expressions!"); |
| 477 | } |
| 478 | |
| 479 | memset((void*)pmatch, 0, sizeof(regmatch_t)*10); |
| 480 | |
| 481 | error = regexec(&M_internalRegExp, P_string, 10, pmatch, REGEXEC_PARAMS); |
| 482 | if (error == 0) { |
| 483 | CCallVariable* L_callVar = P_callVarTable->getVar(getVarId()); |
| 484 | |
| 485 | for (int i = 0; i <= getNbSubVarId(); i++) { |
| 486 | if (pmatch[i].rm_eo != -1) { |
| 487 | setSubString(&result, P_string, pmatch[i].rm_so, pmatch[i].rm_eo); |
| 488 | L_callVar->setMatchingValue(result); |
| 489 | nbOfMatch++; |
| 490 | } |
| 491 | if (i == getNbSubVarId()) { |
| 492 | break; |
| 493 | } |
| 494 | L_callVar = P_callVarTable->getVar(getSubVarId(i)); |
| 495 | } |
| 496 | } |
| 497 | return(nbOfMatch); |
| 498 | } |
| 499 | |
| 500 | void CAction::setSubString(char** P_target, const char* P_source, int P_start, int P_stop) |
| 501 | { |
no test coverage detected