Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added some new string manipulation stocks #1224

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions plugins/include/string.inc
Original file line number Diff line number Diff line change
Expand Up @@ -588,3 +588,86 @@ stock int ImplodeStrings(const char[][] strings, int numStrings, const char[] jo
}
return total;
}

/**
* Checks if the given string is an integer (Supports negative values)
*
* @param szString Input string
* @return Boolean
*/
stock bool IsStringNumber(const char[] str, int nBase=10)
{
int result;
return StringToIntEx(str, result, nBase) == strlen(str);
}

/**
* Checks if the given string is a float (Supports negative values)
*
* @param szString Input string
* @return Boolean
*/
stock bool IsStringFloat(const char[] str)
{
float result;
return StringToFloatEx(str, result) == strlen(str);
}

/**
* Converts the given string to lower case
*
* @param szString Input string for conversion and also the output
* @return void
*/
stock void StringToLowerCase(char[] szInput)
{
int iIterator = 0;

while (szInput[iIterator] != EOS)
{
szInput[iIterator] = CharToLower(szInput[iIterator]);
++iIterator;
}
}

/**
* Converts the given string to upper case
*
* @param szString Input string for conversion and also the output
* @return void
*/
stock void StringToUpperCase(char[] szInput)
{
int iIterator = 0;

while (szInput[iIterator] != EOS)
{
szInput[iIterator] = CharToUpper(szInput[iIterator]);
++iIterator;
}
}

/**
Headline marked this conversation as resolved.
Show resolved Hide resolved
* Finds the position (index) of character in the given string (A wrapper around FindCharInString)
*
* @param szString Input string
* @param szString Input character
* @param szString Do we need the last index (Optional, default: false)
* @return Integer, index of the found character (returns -1 if the character was not found)
*/
stock int IndexOfChar(const char[] szText, const char cCharacter, bool bLast = false)
{
return FindCharInString(szText, cCharacter, bLast);
}

/**
Headline marked this conversation as resolved.
Show resolved Hide resolved
* Finds the last position (index) of character in the given string (A wrapper around IndexOfChar)
*
* @param szString Input string
* @param szString Input character
* @return Integer, index of the found character. (returns -1 if the character was not found)
*/
stock int LastIndexOfChar(const char[] szText, const char cCharacter)
{
return IndexOfChar(szText, cCharacter, true);
}