From d263f7bcc8fefa5b5173b52109749fd0ddd006a3 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 25 Aug 2018 20:54:16 +0200 Subject: [PATCH] - removed most of the old LastIndexOf methods in FString, only leaving one for ZScript and clearly giving it a name that says it all. RIndexOf has been made the proper version of LastIndexOf internally now. --- src/scripting/thingdef_data.cpp | 4 ++-- src/zstring.cpp | 42 ++++++++++----------------------- src/zstring.h | 17 ++++++------- wadsrc/static/zscript/base.txt | 2 +- 4 files changed, 22 insertions(+), 43 deletions(-) diff --git a/src/scripting/thingdef_data.cpp b/src/scripting/thingdef_data.cpp index 35d2733f5c..a10d05710d 100644 --- a/src/scripting/thingdef_data.cpp +++ b/src/scripting/thingdef_data.cpp @@ -1270,7 +1270,7 @@ DEFINE_ACTION_FUNCTION(FStringStruct, LastIndexOf) PARAM_SELF_STRUCT_PROLOGUE(FString); PARAM_STRING(substr); PARAM_INT_DEF(endIndex); - ACTION_RETURN_INT(self->LastIndexOf(substr, endIndex)); + ACTION_RETURN_INT(self->LastIndexOfBroken(substr, endIndex)); } DEFINE_ACTION_FUNCTION(FStringStruct, RightIndexOf) @@ -1278,7 +1278,7 @@ DEFINE_ACTION_FUNCTION(FStringStruct, RightIndexOf) PARAM_SELF_STRUCT_PROLOGUE(FString); PARAM_STRING(substr); PARAM_INT_DEF(endIndex); - ACTION_RETURN_INT(self->RIndexOf(substr, endIndex)); + ACTION_RETURN_INT(self->LastIndexOf(substr, endIndex)); } DEFINE_ACTION_FUNCTION(FStringStruct, ToUpper) diff --git a/src/zstring.cpp b/src/zstring.cpp index e207cdb6b3..5e57df45bd 100644 --- a/src/zstring.cpp +++ b/src/zstring.cpp @@ -507,31 +507,11 @@ long FString::IndexOfAny (const char *charset, long startIndex) const return long(brk - Chars); } -long FString::LastIndexOf (const FString &substr) const -{ - return LastIndexOf (substr.Chars, long(Len()), substr.Len()); -} - -long FString::LastIndexOf (const char *substr) const -{ - return LastIndexOf (substr, long(Len()), strlen(substr)); -} - long FString::LastIndexOf (char subchar) const { return LastIndexOf (subchar, long(Len())); } -long FString::LastIndexOf (const FString &substr, long endIndex) const -{ - return LastIndexOf (substr.Chars, endIndex, substr.Len()); -} - -long FString::LastIndexOf (const char *substr, long endIndex) const -{ - return LastIndexOf (substr, endIndex, strlen(substr)); -} - long FString::LastIndexOf (char subchar, long endIndex) const { if ((size_t)endIndex > Len()) @@ -548,8 +528,10 @@ long FString::LastIndexOf (char subchar, long endIndex) const return -1; } -long FString::LastIndexOf (const char *substr, long endIndex, size_t substrlen) const +long FString::LastIndexOfBroken (const FString &_substr, long endIndex) const { + const char *substr = _substr.GetChars(); + size_t substrlen = _substr.Len(); if ((size_t)endIndex > Len()) { endIndex = long(Len()); @@ -596,27 +578,27 @@ long FString::LastIndexOfAny (const char *charset, long endIndex) const return -1; } -long FString::RIndexOf (const FString &substr) const +long FString::LastIndexOf (const FString &substr) const { - return RIndexOf(substr.Chars, Len() - substr.Len(), substr.Len()); + return LastIndexOf(substr.Chars, Len() - substr.Len(), substr.Len()); } -long FString::RIndexOf (const FString &substr, long endIndex) const +long FString::LastIndexOf (const FString &substr, long endIndex) const { - return RIndexOf(substr.Chars, endIndex, substr.Len()); + return LastIndexOf(substr.Chars, endIndex, substr.Len()); } -long FString::RIndexOf (const char *substr) const +long FString::LastIndexOf (const char *substr) const { - return RIndexOf(substr, Len() - strlen(substr), strlen(substr)); + return LastIndexOf(substr, Len() - strlen(substr), strlen(substr)); } -long FString::RIndexOf (const char *substr, long endIndex) const +long FString::LastIndexOf (const char *substr, long endIndex) const { - return RIndexOf(substr, endIndex, strlen(substr)); + return LastIndexOf(substr, endIndex, strlen(substr)); } -long FString::RIndexOf (const char *substr, long endIndex, size_t substrlen) const +long FString::LastIndexOf (const char *substr, long endIndex, size_t substrlen) const { if ((size_t)endIndex + substrlen > Len()) { diff --git a/src/zstring.h b/src/zstring.h index d61408dc77..67fef4a181 100644 --- a/src/zstring.h +++ b/src/zstring.h @@ -201,24 +201,21 @@ public: long IndexOfAny (const FString &charset, long startIndex=0) const; long IndexOfAny (const char *charset, long startIndex=0) const; - long LastIndexOf (const FString &substr) const; - long LastIndexOf (const char *substr) const; + // This is only kept for backwards compatibility with old ZScript versions that used this function and depend on its bug. long LastIndexOf (char subchar) const; - long LastIndexOf (const FString &substr, long endIndex) const; - long LastIndexOf (const char *substr, long endIndex) const; + long LastIndexOfBroken (const FString &substr, long endIndex) const; long LastIndexOf (char subchar, long endIndex) const; - long LastIndexOf (const char *substr, long endIndex, size_t substrlen) const; long LastIndexOfAny (const FString &charset) const; long LastIndexOfAny (const char *charset) const; long LastIndexOfAny (const FString &charset, long endIndex) const; long LastIndexOfAny (const char *charset, long endIndex) const; - long RIndexOf (const FString &substr) const; - long RIndexOf (const FString &substr, long endIndex) const; - long RIndexOf (const char *substr) const; - long RIndexOf (const char *substr, long endIndex) const; - long RIndexOf (const char *substr, long endIndex, size_t substrlen) const; + long LastIndexOf (const FString &substr) const; + long LastIndexOf (const FString &substr, long endIndex) const; + long LastIndexOf (const char *substr) const; + long LastIndexOf (const char *substr, long endIndex) const; + long LastIndexOf (const char *substr, long endIndex, size_t substrlen) const; void ToUpper (); void ToLower (); diff --git a/wadsrc/static/zscript/base.txt b/wadsrc/static/zscript/base.txt index 23ebafaf8c..f310e29007 100644 --- a/wadsrc/static/zscript/base.txt +++ b/wadsrc/static/zscript/base.txt @@ -815,7 +815,7 @@ struct StringStruct native native int CharCodeAt(int pos) const; native String Filter(); native int IndexOf(String substr, int startIndex = 0) const; - deprecated("3.5") native int LastIndexOf(String substr, int endIndex = 2147483647) const; + deprecated("3.5.1") native int LastIndexOf(String substr, int endIndex = 2147483647) const; native int RightIndexOf(String substr, int endIndex = 2147483647) const; native void ToUpper(); native void ToLower();