2025-05-25 16:16:36 -04:00
|
|
|
//::///////////////////////////////////////////////
|
|
|
|
//:: String Util
|
2025-05-30 23:23:08 -04:00
|
|
|
//:: prc_string_inc
|
2025-05-25 16:16:36 -04:00
|
|
|
//:://////////////////////////////////////////////
|
|
|
|
/*
|
|
|
|
A util class for providing useful string functions.
|
|
|
|
*/
|
|
|
|
//:://////////////////////////////////////////////
|
|
|
|
//:: Created By: Rakiov
|
|
|
|
//:: Created On: 22.05.2005
|
|
|
|
//:://////////////////////////////////////////////
|
|
|
|
|
2025-05-30 23:23:08 -04:00
|
|
|
#include "inc_utility"
|
|
|
|
|
2025-05-25 16:16:36 -04:00
|
|
|
//
|
|
|
|
// StringSplit
|
|
|
|
// Takes a string and splits it by " " into a json list of strings
|
|
|
|
// i.e. "this is a test" returns
|
|
|
|
// {
|
|
|
|
// "this",
|
|
|
|
// "is",
|
|
|
|
// "a",
|
|
|
|
// "test"
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// Parameters:
|
|
|
|
// string input the string input
|
|
|
|
//
|
|
|
|
// Returns:
|
|
|
|
// json the json list of words
|
|
|
|
//
|
|
|
|
json StringSplit(string input);
|
|
|
|
|
|
|
|
json StringSplit(string input)
|
|
|
|
{
|
|
|
|
json retValue = JsonArray();
|
|
|
|
|
|
|
|
string subString = "";
|
|
|
|
//trim any whitespace characters first
|
2025-05-30 23:23:08 -04:00
|
|
|
string currString = PRCTrimString(input);
|
2025-05-25 16:16:36 -04:00
|
|
|
|
|
|
|
// loop until we process the whole string
|
|
|
|
while(currString != "")
|
|
|
|
{
|
|
|
|
string currChar = GetStringLeft(currString, 1);
|
|
|
|
if (currChar != "" && currChar != " ")
|
|
|
|
{
|
|
|
|
// if the current character isn't nothing or whitespace, then add it
|
|
|
|
// to the current sub string.
|
|
|
|
subString += currChar;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// otherwise if the substring is not empty, then add it to the list
|
|
|
|
// of words to return
|
|
|
|
if(subString != "")
|
|
|
|
{
|
|
|
|
retValue = JsonArrayInsert(retValue, JsonString(subString));
|
|
|
|
subString = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// pop and move to next character
|
|
|
|
currString = GetStringRight(currString, GetStringLength(currString)-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// if there is any sub string left at the end of the loop, add it to the list
|
|
|
|
if(subString != "")
|
|
|
|
{
|
|
|
|
retValue = JsonArrayInsert(retValue, JsonString(subString));
|
|
|
|
}
|
|
|
|
|
|
|
|
return retValue;
|
|
|
|
}
|