You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
806 B
C++
39 lines
806 B
C++
#include "common.h"
|
|
#include <string>
|
|
#include "stdarg.h"
|
|
int string_split(std::string str, std::string pattern,std::vector<std::string> &out)
|
|
{
|
|
std::string::size_type pos;
|
|
int cnt = 0;
|
|
str += pattern;
|
|
int size = str.size();
|
|
|
|
for (int i = 0; i<size; i++)
|
|
{
|
|
pos = str.find(pattern, i);
|
|
if (pos<size)
|
|
{
|
|
cnt++;
|
|
std::string s = str.substr(i, pos - i);
|
|
out.push_back(s);
|
|
i = pos + pattern.size() - 1;
|
|
}
|
|
}
|
|
return cnt;
|
|
}
|
|
|
|
std::string format(const char *pszFmt, ...)
|
|
{
|
|
std::string str;
|
|
va_list args;
|
|
va_start(args, pszFmt);
|
|
{
|
|
int nLength = _vscprintf(pszFmt, args);
|
|
nLength += 1;
|
|
std::vector<char> chars(nLength);
|
|
_vsnprintf(chars.data(), nLength, pszFmt, args);
|
|
str.assign(chars.data());
|
|
}
|
|
va_end(args);
|
|
return str;
|
|
} |