mirror of
https://github.com/sfall-team/sfall.git
synced 2026-07-27 16:52:34 -07:00
string_pos: use negative pos value how it works in substr
This commit is contained in:
@@ -1095,12 +1095,12 @@
|
||||
doc: "Takes a string and a seperator, searches the string for all instances of the seperator, and returns a temp array filled with the pieces of the string split at each instance. If you give an empty string as the seperator, the string is split into individual characters. You can use this to search for a substring in a string like this: `strlen(get_array(string_split(haystack, needle), 0))`"
|
||||
opcode: 0x8235
|
||||
- name: substr
|
||||
detail: string substr(string text, start, length)
|
||||
detail: string substr(string text, int start, int length)
|
||||
doc: |
|
||||
Cuts a substring from a string starting at "start" up to "length" characters. The first character position is 0 (zero).
|
||||
- If start is negative - it indicates starting position from the end of the string (for example `substr("test", -2, 2)` will return last 2 charactes: "st").
|
||||
- If length is negative - it means so many characters will be omitted from the end of string (example: `substr("test", 0, -2)` will return string without last 2 characters: "te").
|
||||
- If length is zero - it will return a string from the starting position to the end of the string **New behavior** for sfall 4.2.2/3.8.22
|
||||
- If length is zero - it will return a string from the starting position to the end of the string. **New behavior** for sfall 4.2.2/3.8.22
|
||||
opcode: 0x824e
|
||||
- name: strlen
|
||||
detail: int strlen(string text)
|
||||
@@ -1122,7 +1122,9 @@
|
||||
macro: sfall.h
|
||||
- name: string_pos_from
|
||||
detail: string string_pos_from(string haystack, string needle, int pos)
|
||||
doc: Returns position of a first occurance of a needle string in a haystack string (starting from a given 0-based position), or -1 if not found.
|
||||
doc: |
|
||||
Returns position of a first occurance of a needle string in a haystack string (starting from a given 0-based position), or -1 if not found.
|
||||
- If pos is negative - it indicates starting position from the end of the string, similar to substr().
|
||||
macro: sfall.h
|
||||
- name: string_format
|
||||
detail: string string_format(string format, any val1, any val2, ...)
|
||||
|
||||
@@ -282,6 +282,8 @@
|
||||
|
||||
/* SFALL_FUNCX MACROS */
|
||||
|
||||
#define FUNC_SELECTOR_7(_1,_2,_3,_4,_5,_6,_7,FUNC,...) FUNC
|
||||
|
||||
#define add_extra_msg_file(name) sfall_func1("add_extra_msg_file", name)
|
||||
#define add_global_timer_event(time, fixedParam) sfall_func2("add_g_timer_event", time, fixedParam)
|
||||
#define add_iface_tag sfall_func0("add_iface_tag")
|
||||
@@ -400,8 +402,7 @@
|
||||
#define string_format5(format, a1, a2, a3, a4, a5) sfall_func6("string_format", format, a1, a2, a3, a4, a5)
|
||||
#define string_format6(format, a1, a2, a3, a4, a5, a6) sfall_func7("string_format", format, a1, a2, a3, a4, a5, a6)
|
||||
#define string_format7(format, a1, a2, a3, a4, a5, a6, a7) sfall_func8("string_format", format, a1, a2, a3, a4, a5, a6, a7)
|
||||
#define string_format_MACRO(_0,_1,_2,_3,_4,_5,_6,FUNC,...) FUNC
|
||||
#define string_format(...) string_format_MACRO(__VA_ARGS__, string_format6, string_format5, string_format4, string_format3, string_format2, string_format1)(__VA_ARGS__)
|
||||
#define string_format(format, ...) FUNC_SELECTOR_7(__VA_ARGS__,string_format7,string_format6,string_format5,string_format4,string_format3,string_format2,string_format1)(format, __VA_ARGS__)
|
||||
#define string_tolower(text) sfall_func2("string_to_case", text, 0)
|
||||
#define string_toupper(text) sfall_func2("string_to_case", text, 1)
|
||||
#define tile_by_position(x, y) sfall_func2("tile_by_position", x, y)
|
||||
@@ -432,4 +433,6 @@
|
||||
#define get_current_quick_save_slot metarule3(213, 0, 0, 0)
|
||||
#define set_current_quick_save_slot(page, slot, check) metarule3(214, page, slot, check) // check: 1 - don't check slot when saving
|
||||
|
||||
#undef FUNC_SELECTOR_7
|
||||
|
||||
#endif
|
||||
|
||||
@@ -208,6 +208,9 @@ void mf_string_pos(OpcodeContext& ctx) {
|
||||
ctx.setReturn(-1);
|
||||
return;
|
||||
}
|
||||
else if (pos < 0) {
|
||||
pos = len + pos;
|
||||
}
|
||||
}
|
||||
else {
|
||||
pos = 0;
|
||||
|
||||
Reference in New Issue
Block a user