static cell_t MatchRegexAll(IPluginContext *pCtx, const cell_t *params) { Handle_t hndl = static_cast<Handle_t>(params[1]); HandleError err; HandleSecurity sec; sec.pOwner = NULL; sec.pIdentity = myself->GetIdentity(); RegEx *x; if ((err = g_pHandleSys->ReadHandle(hndl, g_RegexHandle, &sec, (void **)&x)) != HandleError_None) { return pCtx->ThrowNativeError("Invalid regex handle %x (error %d)", hndl, err); } if (!x) { pCtx->ThrowNativeError("Regex data not found\n"); return 0; } char *str; pCtx->LocalToString(params[2], &str); int e = x->MatchAll(str); if (e == -1) { /* there was a match error. move on. */ cell_t *res; pCtx->LocalToPhysAddr(params[3], &res); *res = x->mErrorCode; /* only clear the match results, since the regex object may still be referenced later */ x->ClearMatch(); return -1; } else if (e == 0) { /* only clear the match results, since the regex object may still be referenced later */ x->ClearMatch(); return 0; } else { return x->mMatchCount; } }
cell match_c(AMX *amx, cell *params, bool all) { int id = params[2] - 1; if (id >= (int)PEL.length() || id < 0 || PEL[id]->isFree()) { MF_LogError(amx, AMX_ERR_NATIVE, "Invalid regex handle %d", id); return 0; } int len; const char *str = MF_GetAmxString(amx, params[1], 0, &len); cell *errorCode = MF_GetAmxAddr(amx, params[3]); RegEx *x = PEL[id]; int e; if (all) e = x->MatchAll(str); else e = x->Match(str); if (e == -1) { /* there was a match error. move on. */ *errorCode = x->mErrorOffset; /* only clear the match results, since the regex object may still be referenced later */ x->ClearMatch(); return -2; } else if (e == 0) { *errorCode = 0; /* only clear the match results, since the regex object may still be referenced later */ x->ClearMatch(); return 0; } else { *errorCode = x->Count(); return x->Count(); } }
cell match(AMX *amx, cell *params, bool all) { int len; const char *str = MF_GetAmxString(amx, params[1], 0, &len); const char *regex = MF_GetAmxString(amx, params[2], 1, &len); int id = GetPEL(); RegEx *x = PEL[id]; char *flags = NULL; cell *errorCode; int result = 0; if (!all) { if (*params / sizeof(cell) >= 6) // compiled with 1.8's extra parameter { flags = MF_GetAmxString(amx, params[6], 2, &len); } result = x->Compile(regex, flags); errorCode = MF_GetAmxAddr(amx, params[3]); } else { result = x->Compile(regex, params[3]); errorCode = MF_GetAmxAddr(amx, params[6]); } if (!result) { const char *err = x->mError; *errorCode = x->mErrorOffset; MF_SetAmxString(amx, params[4], err ? err : "unknown", params[5]); return -1; } int e; if (all) e = x->MatchAll(str); else e = x->Match(str); if (e == -1) { /* there was a match error. destroy this and move on. */ *errorCode = x->mErrorOffset; x->Clear(); return -2; } else if (e == 0) { *errorCode = 0; x->Clear(); return 0; } else { *errorCode = x->Count(); if (all) return x->Count(); } return id + 1; }