From c56cd245ac6aa35d11ec4a669b8a58c9c123a923 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Sat, 22 Jul 2017 10:54:32 +0300 Subject: [PATCH] Added IndexOf() and LastIndexOf() functions to ZScript string type https://forum.zdoom.org/viewtopic.php?t=57313 --- src/scripting/thingdef_data.cpp | 15 +++++++++++++++ wadsrc/static/zscript/base.txt | 2 ++ 2 files changed, 17 insertions(+) diff --git a/src/scripting/thingdef_data.cpp b/src/scripting/thingdef_data.cpp index 7cfa53504..f7b84f21b 100644 --- a/src/scripting/thingdef_data.cpp +++ b/src/scripting/thingdef_data.cpp @@ -1252,3 +1252,18 @@ DEFINE_ACTION_FUNCTION(FStringStruct, Filter) ACTION_RETURN_STRING(strbin1(*self)); } +DEFINE_ACTION_FUNCTION(FStringStruct, IndexOf) +{ + PARAM_SELF_STRUCT_PROLOGUE(FString); + PARAM_STRING(substr); + PARAM_INT_DEF(startIndex); + ACTION_RETURN_INT(self->IndexOf(substr, startIndex)); +} + +DEFINE_ACTION_FUNCTION(FStringStruct, LastIndexOf) +{ + PARAM_SELF_STRUCT_PROLOGUE(FString); + PARAM_STRING(substr); + ACTION_RETURN_INT(self->LastIndexOf(substr)); +} + diff --git a/wadsrc/static/zscript/base.txt b/wadsrc/static/zscript/base.txt index f35e39993..b2fd9c6c8 100644 --- a/wadsrc/static/zscript/base.txt +++ b/wadsrc/static/zscript/base.txt @@ -656,6 +656,8 @@ struct StringStruct native native String CharAt(int pos) const; native int CharCodeAt(int pos) const; native String Filter(); + native int IndexOf(String substr, int startIndex = 0) const; + native int LastIndexOf(String substr) const; } class SectorEffect : Thinker native