Working on Prefab Parser updates
This commit is contained in:
@ -32,4 +32,67 @@ static inline char * stringFindNext(
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits a string into a vector of strings, using a delimiter.
|
||||
*
|
||||
* @param s String to split.
|
||||
* @param delim Delimiter to split by.
|
||||
* @return Vector of strings.
|
||||
*/
|
||||
static inline std::vector<std::string> stringSplit(
|
||||
const std::string &s,
|
||||
const std::string delim
|
||||
) {
|
||||
size_t posStart = 0, posEnd, delimLength = delim.length();
|
||||
std::string token;
|
||||
std::vector<std::string> res;
|
||||
|
||||
while((posEnd = s.find(delim, posStart)) != std::string::npos) {
|
||||
token = s.substr(posStart, posEnd - posStart);
|
||||
posStart = posEnd + delimLength;
|
||||
res.push_back (token);
|
||||
}
|
||||
|
||||
res.push_back(s.substr(posStart));
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Trims the whitespace from the left side of a string.
|
||||
*
|
||||
* @param i Input string to trim.
|
||||
* @return Trimmed string.
|
||||
*/
|
||||
static inline std::string stringLTrim(const std::string &i) {
|
||||
std::string s = i;
|
||||
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) {
|
||||
return !std::isspace(ch);
|
||||
}));
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Trims the whitespace from the right side of a string.
|
||||
*
|
||||
* @param i Input string to trim.
|
||||
* @return Trimmed string.
|
||||
*/
|
||||
static inline std::string stringRTrim(const std::string &i) {
|
||||
std::string s = i;
|
||||
s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) {
|
||||
return !std::isspace(ch);
|
||||
}).base(), s.end());
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Trims the whitespace from both sides of a string.
|
||||
*
|
||||
* @param s Input string to trim.
|
||||
* @return Trimmed string.
|
||||
*/
|
||||
static inline std::string stringTrim(const std::string &s) {
|
||||
return stringLTrim(stringRTrim(s));
|
||||
}
|
Reference in New Issue
Block a user