vector<string> &Split(string &str, const char *&separate, vector<string> &matchs)
{
return Split((char *)str.c_str(), separate, matchs);
}
vector<string> &Split(string &str, const char &separate, vector<string> &matchs)
{
char delimiter[2] = { 0 };
#ifdef Platform_Windows // Windows
sprintf_s(delimiter, 2, "%c", separate);
#else
sprintf(delimiter, "%c", separate);
#endif
return Split((char *)str.c_str(), delimiter, matchs);
}
vector<string> &Split(char *str, const char &separate, vector<string> &matchs)
{
char delimiter[2] = { 0 };
#ifdef Platform_Windows // Windows
sprintf_s(delimiter, 2, "%c", separate);
#else
sprintf(delimiter, "%c", separate);
#endif
return Split(str, delimiter, matchs);
}
vector<string> &Split(char *str, const char *separate, vector<string> &matchs)
{
char *current = NULL;
char *remain = NULL;
if (NULL == str || NULL == separate)
{
return matchs;
}
#ifdef Platform_Windows // Windows
current = strtok_s(str, separate, &remain); // 多线程安全
while (NULL != current)
{
matchs.push_back(string(current, strlen(current)));
current = strtok_s(NULL, separate, &remain);
}
#elif defined(Platform_Embedded)
current = strtok(str, separate); // 多线程不安全
while (NULL != current)
{
matchs.push_back(string(current, strlen(current)));
current = strtok(NULL, separate);
}
#else // Linux/Android/iOS
current = strtok_r(str, ",", &remain); // 多线程安全
while (NULL != current)
{
matchs.push_back(string(current, strlen(current)));
current = strtok_r(NULL, ",", &remain);
}
#endif
return matchs;
}