- 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.

This commit is contained in:
Christoph Oelckers 2018-08-25 20:54:16 +02:00
parent c04c48d157
commit d263f7bcc8
4 changed files with 22 additions and 43 deletions

View file

@ -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)

View file

@ -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())
{

View file

@ -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 ();

View file

@ -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();