60 lines
1.4 KiB
C++
60 lines
1.4 KiB
C++
// Copyright (c) 2014, IOnU Security, Inc.
|
|
#include "internal.h"
|
|
|
|
#ifdef WIN32
|
|
#include <Windows.h>
|
|
#endif
|
|
|
|
using namespace sequencelogic;
|
|
|
|
|
|
namespace sequencelogic
|
|
{
|
|
int SplitString(const std::string &strToSplit, const char ch, std::vector<std::string> &splitStrings)
|
|
{
|
|
int nRetVal = 0;
|
|
splitStrings.clear();
|
|
|
|
std::string::size_type nStart = 0;
|
|
while (strToSplit.find(ch, nStart) != std::string::npos)
|
|
{
|
|
splitStrings.push_back(strToSplit.substr(nStart, strToSplit.find(ch, nStart) - nStart));
|
|
++nRetVal;
|
|
nStart = strToSplit.find(ch, nStart)+1;
|
|
}
|
|
|
|
// Check for a last arg...
|
|
if (nStart <= strToSplit.length())
|
|
{
|
|
splitStrings.push_back(strToSplit.substr(nStart));
|
|
++nRetVal;
|
|
}
|
|
return nRetVal;
|
|
}
|
|
|
|
#ifdef WIN32
|
|
std::string getLastError()
|
|
{
|
|
std::string retVal;
|
|
|
|
LPVOID lpMsgBuf;
|
|
DWORD dw = GetLastError();
|
|
|
|
FormatMessage(
|
|
FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
|
FORMAT_MESSAGE_FROM_SYSTEM |
|
|
FORMAT_MESSAGE_IGNORE_INSERTS,
|
|
NULL,
|
|
dw,
|
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
|
(LPTSTR) &lpMsgBuf,
|
|
0, NULL );
|
|
|
|
retVal = (LPTSTR)&lpMsgBuf;
|
|
LocalFree (lpMsgBuf);
|
|
|
|
return retVal;
|
|
}
|
|
#endif
|
|
}
|