MCPcopy Create free account
hub / github.com/alliedmodders/sourcemod / MatchRegex

Function MatchRegex

extensions/regex/extension.cpp:109–162  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

107
108
109static cell_t MatchRegex(IPluginContext *pCtx, const cell_t *params)
110{
111 Handle_t hndl = static_cast<Handle_t>(params[1]);
112 HandleError err;
113 HandleSecurity sec;
114 sec.pOwner = NULL;
115 sec.pIdentity = myself->GetIdentity();
116
117 RegEx *x;
118 if ((err=g_pHandleSys->ReadHandle(hndl, g_RegexHandle, &sec, (void **)&x)) != HandleError_None)
119 {
120 return pCtx->ThrowNativeError("Invalid regex handle %x (error %d)", hndl, err);
121 }
122 if (!x)
123 {
124 pCtx->ThrowNativeError("Regex data not found\n");
125 return 0;
126 }
127
128 size_t offset = 0;
129 if (params[0] >= 4)
130 {
131 offset = static_cast<size_t>(params[4]);
132 }
133
134 char *str;
135 pCtx->LocalToString(params[2], &str);
136
137 int e = x->Match(str, offset);
138 if (e == -1)
139 {
140 /* there was a match error. move on. */
141 cell_t *res;
142 pCtx->LocalToPhysAddr(params[3], &res);
143 *res = x->mErrorCode;
144 /* only clear the match results, since the regex object
145 may still be referenced later */
146 x->ClearMatch();
147
148 return -1;
149 }
150 else if (e == 0)
151 {
152 /* only clear the match results, since the regex object
153 may still be referenced later */
154 x->ClearMatch();
155
156 return 0;
157 }
158 else
159 {
160 return x->mMatches[0].mSubStringCount;
161 }
162}
163
164static cell_t MatchRegexAll(IPluginContext *pCtx, const cell_t *params)
165{

Callers

nothing calls this directly

Calls 4

MatchMethod · 0.80
ClearMatchMethod · 0.80
GetIdentityMethod · 0.45
ReadHandleMethod · 0.45

Tested by

no test coverage detected