mirror of
https://github.com/ZDoom/qzdoom-gpl.git
synced 2025-01-18 21:21:36 +00:00
- Added more string functions to ACS:
* The standard C functions strcmp and stricmp (aka strcasecmp), which double up as strncmp and strnicmp if you pass a third argument. * The BASIC-like functions strleft, strright, and strmid, which extract parts of a string to create a new string. SVN r4313 (trunk)
This commit is contained in:
parent
d40d7f2e77
commit
037477a20b
1 changed files with 74 additions and 0 deletions
|
@ -4127,6 +4127,11 @@ enum EACSFunctions
|
|||
ACSF_LineAttack,
|
||||
ACSF_PlaySound,
|
||||
ACSF_StopSound,
|
||||
ACSF_strcmp,
|
||||
ACSF_stricmp,
|
||||
ACSF_StrLeft,
|
||||
ACSF_StrRight,
|
||||
ACSF_StrMid,
|
||||
|
||||
// ZDaemon
|
||||
ACSF_GetTeamScore = 19620, // (int team)
|
||||
|
@ -4951,6 +4956,75 @@ doplaysound: if (!looping)
|
|||
}
|
||||
break;
|
||||
|
||||
case ACSF_strcmp:
|
||||
case ACSF_stricmp:
|
||||
if (argCount >= 2)
|
||||
{
|
||||
const char *a, *b;
|
||||
a = FBehavior::StaticLookupString(args[0]);
|
||||
b = FBehavior::StaticLookupString(args[1]);
|
||||
|
||||
// Don't crash on invalid strings.
|
||||
if (a == NULL) a = "";
|
||||
if (b == NULL) b = "";
|
||||
|
||||
if (argCount > 2)
|
||||
{
|
||||
int n = args[2];
|
||||
return (funcIndex == ACSF_strcmp) ? strncmp(a, b, n) : strnicmp(a, b, n);
|
||||
}
|
||||
else
|
||||
{
|
||||
return (funcIndex == ACSF_strcmp) ? strcmp(a, b) : stricmp(a, b);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case ACSF_StrLeft:
|
||||
case ACSF_StrRight:
|
||||
if (argCount >= 2)
|
||||
{
|
||||
const char *oldstr = FBehavior::StaticLookupString(args[0]);
|
||||
if (oldstr == NULL || *oldstr == '\0')
|
||||
{
|
||||
return GlobalACSStrings.AddString("");
|
||||
}
|
||||
size_t oldlen = strlen(oldstr);
|
||||
size_t newlen = args[1];
|
||||
|
||||
if (oldlen < newlen)
|
||||
{
|
||||
newlen = oldlen;
|
||||
}
|
||||
FString newstr(funcIndex == ACSF_StrLeft ? oldstr : oldstr + oldlen - newlen, newlen);
|
||||
return GlobalACSStrings.AddString(newstr);
|
||||
}
|
||||
break;
|
||||
|
||||
case ACSF_StrMid:
|
||||
if (argCount >= 3)
|
||||
{
|
||||
const char *oldstr = FBehavior::StaticLookupString(args[0]);
|
||||
if (oldstr == NULL || *oldstr == '\0')
|
||||
{
|
||||
return GlobalACSStrings.AddString("");
|
||||
}
|
||||
size_t oldlen = strlen(oldstr);
|
||||
size_t pos = args[1];
|
||||
size_t newlen = args[2];
|
||||
|
||||
if (pos >= oldlen)
|
||||
{
|
||||
return GlobalACSStrings.AddString("");
|
||||
}
|
||||
if (pos + newlen > oldlen || pos + newlen < pos)
|
||||
{
|
||||
newlen = oldlen - pos;
|
||||
}
|
||||
return GlobalACSStrings.AddString(FString(oldstr + pos, newlen));
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue