1.1 --- a/core/smn_string.cpp Tue May 22 15:42:18 2007 +0000
1.2 +++ b/core/smn_string.cpp Tue May 22 20:50:48 2007 +0000
1.3 @@ -407,6 +407,43 @@
1.4 return islower(chr);
1.5 }
1.6
1.7 +static cell_t ReplaceString(IPluginContext *pContext, const cell_t *params)
1.8 +{
1.9 + char *text, *search, *replace;
1.10 + size_t maxlength;
1.11 +
1.12 + pContext->LocalToString(params[1], &text);
1.13 + pContext->LocalToString(params[3], &search);
1.14 + pContext->LocalToString(params[4], &replace);
1.15 + maxlength = (size_t)params[2];
1.16 +
1.17 +
1.18 + return UTIL_ReplaceAll(text, maxlength, search, replace);
1.19 +}
1.20 +
1.21 +static cell_t ReplaceStringEx(IPluginContext *pContext, const cell_t *params)
1.22 +{
1.23 + char *text, *search, *replace;
1.24 + size_t maxlength;
1.25 +
1.26 + pContext->LocalToString(params[1], &text);
1.27 + pContext->LocalToString(params[3], &search);
1.28 + pContext->LocalToString(params[4], &replace);
1.29 + maxlength = (size_t)params[2];
1.30 +
1.31 + size_t searchLen = (params[5] == -1) ? strlen(search) : (size_t)params[5];
1.32 + size_t replaceLen = (params[6] == -1) ? strlen(replace) : (size_t)params[6];
1.33 +
1.34 + char *ptr = UTIL_ReplaceEx(text, maxlength, search, searchLen, replace, replaceLen);
1.35 +
1.36 + if (ptr == NULL)
1.37 + {
1.38 + return -1;
1.39 + }
1.40 +
1.41 + return ptr - text;
1.42 +}
1.43 +
1.44 static cell_t TrimString(IPluginContext *pContext, const cell_t *params)
1.45 {
1.46 char *str;
1.47 @@ -444,6 +481,10 @@
1.48
1.49 REGISTER_NATIVES(basicStrings)
1.50 {
1.51 + {"BreakString", BreakString},
1.52 + {"FloatToString", sm_floattostr},
1.53 + {"Format", sm_format},
1.54 + {"FormatEx", sm_formatex},
1.55 {"GetCharBytes", GetCharBytes},
1.56 {"IntToString", sm_numtostr},
1.57 {"IsCharAlpha", IsCharAlpha},
1.58 @@ -452,9 +493,10 @@
1.59 {"IsCharNumeric", IsCharNumeric},
1.60 {"IsCharSpace", IsCharSpace},
1.61 {"IsCharUpper", IsCharUpper},
1.62 + {"ReplaceString", ReplaceString},
1.63 + {"ReplaceStringEx", ReplaceStringEx},
1.64 {"strlen", sm_strlen},
1.65 {"StrBreak", BreakString}, /* Backwards compat shim */
1.66 - {"BreakString", BreakString},
1.67 {"StrContains", sm_contain},
1.68 {"strcmp", sm_strcmp},
1.69 {"StrCompare", sm_strcmp}, /* Backwards compat shim */
1.70 @@ -463,10 +505,7 @@
1.71 {"StrCopy", sm_strcopy}, /* Backwards compat shim */
1.72 {"StringToInt", sm_strconvint},
1.73 {"StringToFloat", sm_strtofloat},
1.74 - {"FloatToString", sm_floattostr},
1.75 - {"Format", sm_format},
1.76 - {"FormatEx", sm_formatex},
1.77 + {"TrimString", TrimString},
1.78 {"VFormat", sm_vformat},
1.79 - {"TrimString", TrimString},
1.80 {NULL, NULL},
1.81 };