30.12.2013, 04:19
This function checks if the specified game text is faulty or can cause crashes.
Outputs:
pawn Code:
static stock isFaultyGameText(const string[])
{
new
i,
len;
while ((i = strfind(string, "~", true, (!i) ? (0) : (i + 1))) != -1) {
len++;
}
if (len % 2 != 0)
return 1;
else for (i = 0, len = strlen(string); i != len; i ++)
{
if (string[i] != '~')
continue;
else switch (string[i + 1])
{
case 'k', 'K':
{
if (!string[(i += strfind(string, "~", true, i + 4))])
break;
continue;
}
case 'a'..'j', 'l'..'z', 'A'..'J', 'L'..'Z':
{
if (string[(i += 2)] == '~')
continue;
return 1;
}
default:
{
return 1;
}
}
}
return 0;
}
pawn Code:
main()
{
if (isFaultyGameText("I am a ~r~boss")) print("1");
if (isFaultyGameText("Press ~k~~VEHICLE_FIREWEAPON_ALT~ to answer your phone.")) print("2");
if (isFaultyGameText("I like to eat ~~cookies.")) print("3");
if (isFaultyGameText("This is ~r~red~w~ and this is ~y~yellow.")) print("4");
if (isFaultyGameText("Dude, ~r~~where's ~~r~~ my car?")) print("5");
}
Code:
3 5