mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2025-02-21 11:01:36 +00:00
Add the "RIndexOf" method to FString, which works like String.lastIndexOf from JavaScript
RIndexOf returns the index where the substring starts, instead of the index where the substring ends - 1. Deprecate the LastIndexOf method of StringStruct
This commit is contained in:
parent
908f7d639d
commit
b57d2f11f3
4 changed files with 56 additions and 5 deletions
|
@ -335,7 +335,7 @@ static FFlagDef ActorFlagDefs[]=
|
||||||
DEFINE_FLAG(RF, INVISIBLE, AActor, renderflags),
|
DEFINE_FLAG(RF, INVISIBLE, AActor, renderflags),
|
||||||
DEFINE_FLAG(RF, FORCEYBILLBOARD, AActor, renderflags),
|
DEFINE_FLAG(RF, FORCEYBILLBOARD, AActor, renderflags),
|
||||||
DEFINE_FLAG(RF, FORCEXYBILLBOARD, AActor, renderflags),
|
DEFINE_FLAG(RF, FORCEXYBILLBOARD, AActor, renderflags),
|
||||||
DEFINE_FLAG(RF, ROLLSPRITE, AActor, renderflags), // [marrub] roll the sprite billboard
|
DEFINE_FLAG(RF, ROLLSPRITE, AActor, renderflags), // [marrub] roll the sprite billboard
|
||||||
// [fgsfds] Flat sprites
|
// [fgsfds] Flat sprites
|
||||||
DEFINE_FLAG(RF, FLATSPRITE, AActor, renderflags),
|
DEFINE_FLAG(RF, FLATSPRITE, AActor, renderflags),
|
||||||
DEFINE_FLAG(RF, WALLSPRITE, AActor, renderflags),
|
DEFINE_FLAG(RF, WALLSPRITE, AActor, renderflags),
|
||||||
|
@ -601,7 +601,7 @@ FFlagDef *FindFlag (const PClass *type, const char *part1, const char *part2, bo
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
//
|
//
|
||||||
// Gets the name of an actor flag
|
// Gets the name of an actor flag
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
|
@ -1281,6 +1281,14 @@ DEFINE_ACTION_FUNCTION(FStringStruct, LastIndexOf)
|
||||||
ACTION_RETURN_INT(self->LastIndexOf(substr, endIndex));
|
ACTION_RETURN_INT(self->LastIndexOf(substr, endIndex));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DEFINE_ACTION_FUNCTION(FStringStruct, RIndexOf)
|
||||||
|
{
|
||||||
|
PARAM_SELF_STRUCT_PROLOGUE(FString);
|
||||||
|
PARAM_STRING(substr);
|
||||||
|
PARAM_INT_DEF(endIndex);
|
||||||
|
ACTION_RETURN_INT(self->RIndexOf(substr, endIndex));
|
||||||
|
}
|
||||||
|
|
||||||
DEFINE_ACTION_FUNCTION(FStringStruct, ToUpper)
|
DEFINE_ACTION_FUNCTION(FStringStruct, ToUpper)
|
||||||
{
|
{
|
||||||
PARAM_SELF_STRUCT_PROLOGUE(FString);
|
PARAM_SELF_STRUCT_PROLOGUE(FString);
|
||||||
|
|
|
@ -596,6 +596,43 @@ long FString::LastIndexOfAny (const char *charset, long endIndex) const
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
long FString::RIndexOf (const FString &substr) const
|
||||||
|
{
|
||||||
|
return RIndexOf(substr.Chars, Len() - substr.Len(), substr.Len());
|
||||||
|
}
|
||||||
|
|
||||||
|
long FString::RIndexOf (const FString &substr, long endIndex) const
|
||||||
|
{
|
||||||
|
return RIndexOf(substr.Chars, endIndex, substr.Len());
|
||||||
|
}
|
||||||
|
|
||||||
|
long FString::RIndexOf (const char *substr) const
|
||||||
|
{
|
||||||
|
return RIndexOf(substr, Len() - strlen(substr), strlen(substr));
|
||||||
|
}
|
||||||
|
|
||||||
|
long FString::RIndexOf (const char *substr, long endIndex) const
|
||||||
|
{
|
||||||
|
return RIndexOf(substr, endIndex, strlen(substr));
|
||||||
|
}
|
||||||
|
|
||||||
|
long FString::RIndexOf (const char *substr, long endIndex, size_t substrlen) const
|
||||||
|
{
|
||||||
|
if ((size_t)endIndex + substrlen > Len())
|
||||||
|
{
|
||||||
|
endIndex = Len() - substrlen;
|
||||||
|
}
|
||||||
|
while (endIndex >= 0)
|
||||||
|
{
|
||||||
|
if (strncmp (substr, Chars + endIndex, substrlen) == 0)
|
||||||
|
{
|
||||||
|
return endIndex;
|
||||||
|
}
|
||||||
|
endIndex--;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
void FString::ToUpper ()
|
void FString::ToUpper ()
|
||||||
{
|
{
|
||||||
LockBuffer();
|
LockBuffer();
|
||||||
|
@ -1003,7 +1040,7 @@ void FString::Substitute (const char *oldstr, const char *newstr, size_t oldstrl
|
||||||
|
|
||||||
bool FString::IsInt () const
|
bool FString::IsInt () const
|
||||||
{
|
{
|
||||||
// String must match: [whitespace] [{+ | –}] [0 [{ x | X }]] [digits] [whitespace]
|
// String must match: [whitespace] [{+ | <EFBFBD>}] [0 [{ x | X }]] [digits] [whitespace]
|
||||||
|
|
||||||
/* This state machine is based on a simplification of re2c's output for this input:
|
/* This state machine is based on a simplification of re2c's output for this input:
|
||||||
digits = [0-9];
|
digits = [0-9];
|
||||||
|
|
|
@ -214,6 +214,12 @@ public:
|
||||||
long LastIndexOfAny (const FString &charset, long endIndex) const;
|
long LastIndexOfAny (const FString &charset, long endIndex) const;
|
||||||
long LastIndexOfAny (const char *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;
|
||||||
|
|
||||||
void ToUpper ();
|
void ToUpper ();
|
||||||
void ToLower ();
|
void ToLower ();
|
||||||
void SwapCase ();
|
void SwapCase ();
|
||||||
|
@ -463,4 +469,3 @@ template<> struct THashTraits<FString>
|
||||||
// Compares two keys, returning zero if they are the same.
|
// Compares two keys, returning zero if they are the same.
|
||||||
int Compare(const FString &left, const FString &right) { return left.Compare(right); }
|
int Compare(const FString &left, const FString &right) { return left.Compare(right); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -809,7 +809,8 @@ struct StringStruct native
|
||||||
native int CharCodeAt(int pos) const;
|
native int CharCodeAt(int pos) const;
|
||||||
native String Filter();
|
native String Filter();
|
||||||
native int IndexOf(String substr, int startIndex = 0) const;
|
native int IndexOf(String substr, int startIndex = 0) const;
|
||||||
native int LastIndexOf(String substr, int endIndex = 2147483647) const;
|
deprecated("3.5") native int LastIndexOf(String substr, int endIndex = 2147483647) const;
|
||||||
|
native int RIndexOf(String substr, int endIndex = 2147483647) const;
|
||||||
native void ToUpper();
|
native void ToUpper();
|
||||||
native void ToLower();
|
native void ToLower();
|
||||||
native int ToInt(int base = 0) const;
|
native int ToInt(int base = 0) const;
|
||||||
|
|
Loading…
Reference in a new issue