diff --git a/artifacts/scripting/functions.yml b/artifacts/scripting/functions.yml index 99e296bb..c90da555 100644 --- a/artifacts/scripting/functions.yml +++ b/artifacts/scripting/functions.yml @@ -1118,14 +1118,14 @@ (DEPRECATED) Returns a pointer to a string variable or to a text - __NOTE:__ this function is intended for use only in `HOOK_DESCRIPTIONOBJ`. Starting from sfall 4.4/3.8.40, you can return normal strings directly in the hook without calling the function macro: sfall.h - - name: string_pos - detail: int string_pos(string haystack, string needle) + - name: string_find + detail: int string_find(string haystack, string needle) doc: Returns the position of the first occurrence of a `needle` string in a `haystack` string, or -1 if not found. The first character position is 0 (zero). macro: sfall.h - - name: string_pos_from - detail: int string_pos_from(string haystack, string needle, int pos) + - name: string_find_from + detail: int string_find_from(string haystack, string needle, int pos) doc: | - Works the same as `string_pos`, except you can specify the position to start the search. + Works the same as `string_find`, except you can specify the position to start the search. - If `pos` is negative - it indicates a position starting from the end of the string, similar to `substr()`. macro: sfall.h - name: string_format diff --git a/artifacts/scripting/headers/lib.strings.h b/artifacts/scripting/headers/lib.strings.h index 9a798e81..a1f6ce20 100644 --- a/artifacts/scripting/headers/lib.strings.h +++ b/artifacts/scripting/headers/lib.strings.h @@ -11,7 +11,7 @@ #include "sfall.h" -#define is_in_string(str, sub) (string_pos(str, sub) != -1) +#define string_contains(str, sub) (string_find(str, sub) != -1) #define string_starts_with(str, sub) (substr(str, 0, strlen(sub)) == sub) #define string_format_array(fmt, arr) sprintf_array(fmt, arr) // Replaces all occurances of substring in a string with another substring diff --git a/artifacts/scripting/headers/sfall.h b/artifacts/scripting/headers/sfall.h index c70ed6ab..2167b639 100644 --- a/artifacts/scripting/headers/sfall.h +++ b/artifacts/scripting/headers/sfall.h @@ -393,8 +393,8 @@ #define spatial_radius(obj) sfall_func1("spatial_radius", obj) #define string_compare(str1, str2) sfall_func2("string_compare", str1, str2) #define string_compare_locale(str1, str2, codePage) sfall_func3("string_compare", str1, str2, codePage) -#define string_pos(haystack, needle) sfall_func2("string_pos", haystack, needle) -#define string_pos_from(haystack, needle, pos) sfall_func3("string_pos", haystack, needle, pos) +#define string_find(haystack, needle) sfall_func2("string_find", haystack, needle) +#define string_find_from(haystack, needle, pos) sfall_func3("string_find", haystack, needle, pos) #define string_format1(format, a1) sfall_func2("string_format", format, a1) #define string_format2(format, a1, a2) sfall_func3("string_format", format, a1, a2) #define string_format3(format, a1, a2, a3) sfall_func4("string_format", format, a1, a2, a3) diff --git a/artifacts/scripting/sfall function notes.md b/artifacts/scripting/sfall function notes.md index 65356db0..513e8811 100644 --- a/artifacts/scripting/sfall function notes.md +++ b/artifacts/scripting/sfall function notes.md @@ -1118,9 +1118,9 @@ sfall_funcX metarule functions - Subsequent calls for the same file will return the same array, unless it was disposed using `free_array` ---- -#### string_pos -`int sfall_func2("string_pos", string haystack, string needle)` -`int sfall_func3("string_pos", string haystack, string needle, int pos)` +#### string_find +`int sfall_func2("string_find", string haystack, string needle)` +`int sfall_func3("string_find", string haystack, string needle, int pos)` - Returns the position of the first occurrence of a `needle` string in a `haystack` string, or -1 if not found. The first character position is 0 (zero) diff --git a/sfall/Modules/Scripting/Handlers/Metarule.cpp b/sfall/Modules/Scripting/Handlers/Metarule.cpp index 71a9fd37..f1000b1a 100644 --- a/sfall/Modules/Scripting/Handlers/Metarule.cpp +++ b/sfall/Modules/Scripting/Handlers/Metarule.cpp @@ -160,7 +160,7 @@ static const SfallMetarule metarules[] = { {"show_window", mf_show_window, 0, 1, -1, {ARG_STRING}}, {"spatial_radius", mf_spatial_radius, 1, 1, 0, {ARG_OBJECT}}, {"string_compare", mf_string_compare, 2, 3, 0, {ARG_STRING, ARG_STRING, ARG_INT}}, - {"string_pos", mf_string_pos, 2, 3, -1, {ARG_STRING, ARG_STRING, ARG_INT}}, + {"string_find", mf_string_find, 2, 3, -1, {ARG_STRING, ARG_STRING, ARG_INT}}, {"string_format", mf_string_format, 2, 8, 0, {ARG_STRING, ARG_ANY, ARG_ANY, ARG_ANY, ARG_ANY, ARG_ANY, ARG_ANY, ARG_ANY}}, {"string_to_case", mf_string_to_case, 2, 2, -1, {ARG_STRING, ARG_INT}}, {"tile_by_position", mf_tile_by_position, 2, 2, -1, {ARG_INT, ARG_INT}}, diff --git a/sfall/Modules/Scripting/Handlers/Utils.cpp b/sfall/Modules/Scripting/Handlers/Utils.cpp index 3cf816db..e4424af8 100644 --- a/sfall/Modules/Scripting/Handlers/Utils.cpp +++ b/sfall/Modules/Scripting/Handlers/Utils.cpp @@ -198,7 +198,7 @@ void mf_string_compare(OpcodeContext& ctx) { } } -void mf_string_pos(OpcodeContext& ctx) { +void mf_string_find(OpcodeContext& ctx) { const char* const haystack = ctx.arg(0).strValue(); int pos = 0; if (ctx.numArgs() > 2) { diff --git a/sfall/Modules/Scripting/Handlers/Utils.h b/sfall/Modules/Scripting/Handlers/Utils.h index f78ba2db..6c96d413 100644 --- a/sfall/Modules/Scripting/Handlers/Utils.h +++ b/sfall/Modules/Scripting/Handlers/Utils.h @@ -37,7 +37,7 @@ void op_strlen(OpcodeContext&); void mf_string_compare(OpcodeContext&); -void mf_string_pos(OpcodeContext&); +void mf_string_find(OpcodeContext&); void op_sprintf(OpcodeContext&);