#include <string>
#ifdef _UNICODE
#define tstring std::wstring
#define __T(quote) L##quote
#else
#define tstring string
#define __T(quote) quote
#endif
#define _T(quote) __T(quote)
#define _TEXT(quote) __T(quote)
#define TEXT(quote) __T(quote)
std::string T2A(const tstring& sInput)
{
#ifdef _UNICODE
return std::string(sInput.begin(), sInput.end());
#else
return sInput;
#endif
};
tstring A2T(const std::string& sInput)
{
#ifdef _UNICODE
return tstring(sInput.begin(), sInput.end());
#else
return sInput;
#endif
};
int replace_all(tstring& str, const tstring& pattern, const tstring& newpat)
{
int count = 0;
const size_t nsize = newpat.size();
const size_t psize = pattern.size();
for(size_t pos = str.find(pattern, 0);
pos != tstring::npos;
pos = str.find(pattern,pos + nsize))
{
str.replace(pos, psize, newpat);
count++;
}
return count;
}