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

Function ReplaceStringEx

core/logic/smn_string.cpp:481–518  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

479}
480
481static cell_t ReplaceStringEx(IPluginContext *pContext, const cell_t *params)
482{
483 char *text, *search, *replace;
484 size_t maxlength;
485 bool caseSensitive;
486
487 pContext->LocalToString(params[1], &text);
488 pContext->LocalToString(params[3], &search);
489 pContext->LocalToString(params[4], &replace);
490 maxlength = (size_t)params[2];
491
492 size_t searchLen = (params[5] == -1) ? strlen(search) : (size_t)params[5];
493 size_t replaceLen = (params[6] == -1) ? strlen(replace) : (size_t)params[6];
494
495 /* Account for old binary plugins that won't pass the last parameter */
496 if (params[0] == 7)
497 {
498 caseSensitive = (bool)params[7];
499 }
500 else
501 {
502 caseSensitive = true;
503 }
504
505 if (searchLen == 0)
506 {
507 return pContext->ThrowNativeError("Cannot replace searches of empty strings");
508 }
509
510 char *ptr = UTIL_ReplaceEx(text, maxlength, search, searchLen, replace, replaceLen, caseSensitive);
511
512 if (ptr == NULL)
513 {
514 return -1;
515 }
516
517 return ptr - text;
518}
519
520static cell_t TrimString(IPluginContext *pContext, const cell_t *params)
521{

Callers

nothing calls this directly

Calls 1

UTIL_ReplaceExFunction · 0.85

Tested by

no test coverage detected