mirror of
https://github.com/debauchee/barrier.git
synced 2026-02-08 04:45:03 +08:00
Add split string function #4933
This commit is contained in:
@@ -224,6 +224,26 @@ stringToSizeType(String string)
|
||||
return value;
|
||||
}
|
||||
|
||||
std::vector<String>
|
||||
splitString(String string, const char c)
|
||||
{
|
||||
std::vector<String> results;
|
||||
|
||||
size_t head = 0;
|
||||
size_t separator = string.find(c);
|
||||
while (separator != String::npos) {
|
||||
results.push_back(string.substr(head, separator - head));
|
||||
head = separator + 1;
|
||||
separator = string.find(c, head);
|
||||
}
|
||||
|
||||
if (head < string.size()) {
|
||||
results.push_back(string.substr(head, string.size() - head));
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
//
|
||||
// CaselessCmp
|
||||
//
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "common/stdstring.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <vector>
|
||||
|
||||
// use standard C++ string class for our string class
|
||||
typedef std::string String;
|
||||
@@ -100,6 +101,12 @@ Convert an a \c string to an size type
|
||||
*/
|
||||
size_t stringToSizeType(String string);
|
||||
|
||||
//! Split a string into substrings
|
||||
/*!
|
||||
Split a \c string that separated by a \c c into substrings
|
||||
*/
|
||||
std::vector<String> splitString(String string, const char c);
|
||||
|
||||
//! Case-insensitive comparisons
|
||||
/*!
|
||||
This class provides case-insensitve comparison functions.
|
||||
|
||||
Reference in New Issue
Block a user