char* MemFind(const void* src_buf, int src_len, const void* find_buf, int find_len);
BOOL ParserMem(const void* src_buf, int src_len, const vector< vector<char> >& vec_par, vector< vector<char> >& vec_result);//---- 多重二进制分割
BOOL ParserMem(const void* src_buf, int src_len, const vector<char>& vec_par, vector< vector<char> >& vec_result);//---- 单层二进制分割
BOOL ParserMem(const void* src_buf, int src_len, const char* par_buf, vector< vector<char> >& vec_result);//---- 字符分割
BOOL ParserMem(const void* src_buf, int src_len, const char* par_buf, vector<string>& vec_result);//---- 字符分割
char* Glob_Fun::MemFind(const void* src_buf, int src_len, const void* find_buf, int find_len)
{
if ((NULL == src_buf) || (NULL == find_buf)
|| (src_len <= 0) || (find_len <= 0))
return NULL;
char*cp = (char*)src_buf;
char*src_end = (char*)src_buf + src_len;
char*find_end = (char*)find_buf + find_len;
char*s_src = NULL, *s_find = NULL;
while (cp < src_end)
{
s_src = cp;
s_find = (char*)find_buf;
while (s_src < src_end && s_find < find_end && *s_src == *s_find)
++s_src, ++s_find;
if (s_find == find_end)
return(cp);
++cp;
}
return(NULL);
}
BOOL Glob_Fun::ParserMem(
const void* src_buf,
int src_len,
const vector< vector<char> >& vec_par,
vector< vector<char> >& vec_result)
{
if ((NULL == src_buf) || (src_len <= 0) || vec_par.size() <= 0)
return FALSE;
for (size_t t = 0; t < vec_par.size(); ++t)
{
if(0 >= vec_par[t].size())
return FALSE;
}
vec_result.clear();
vector<char> vec_tmp;
BOOL bMatched = FALSE;
int nParCount = vec_par.size();
int nParTick = 0;
char*cp = (char*)src_buf;
char*src_end = (char*)src_buf + src_len;
int nParLen = (int)vec_par[0].size();
char*find_buf = (char*)&(vec_par[0][0]);
char*find_end = find_buf + nParLen;
char*s_src = NULL, *s_find = NULL;
while (cp < src_end)
{
s_src = cp;
s_find = (char*)find_buf;
while (s_src < src_end && s_find < find_end && *s_src == *s_find)
++s_src,++s_find;
if (s_find == find_end)
{
bMatched = TRUE;
cp += nParLen;
vec_result.push_back(vec_tmp);
vec_tmp.clear();
++nParTick;
if(nParCount == nParTick)
nParTick = 0;
nParLen = (int)(vec_par[nParTick].size());
find_buf = (char*)&(vec_par[nParTick][0]);
find_end = find_buf + nParLen;
}
else
{
vec_tmp.push_back(*cp);
++cp;
}
}
if(TRUE == bMatched)
vec_result.push_back(vec_tmp);
return(bMatched);
}
BOOL Glob_Fun::ParserMem(
const void* src_buf,
int src_len,
const vector<char>& vec_par,
vector< vector<char> >& vec_result)
{
if ((NULL == src_buf) || (src_len <= 0) || vec_par.size() <= 0)
return FALSE;
vec_result.clear();
vector<char> vec_tmp;
BOOL bMatched = FALSE;
char*cp = (char*)src_buf;
char*src_end = (char*)src_buf + src_len;
int nParLen = (int)vec_par.size();
char*find_buf = (char*)&(vec_par[0]);
char*find_end = find_buf + nParLen;
char*s_src = NULL, *s_find = NULL;
while (cp < src_end)
{
s_src = cp;
s_find = (char*)find_buf;
while (s_src < src_end && s_find < find_end && *s_src == *s_find)
++s_src, ++s_find;
if (s_find == find_end)
{
bMatched = TRUE;
cp += nParLen;
vec_result.push_back(vec_tmp);
vec_tmp.clear();
}
else
{
vec_tmp.push_back(*cp);
++cp;
}
}
if(TRUE == bMatched)
vec_result.push_back(vec_tmp);
return(bMatched);
}
BOOL Glob_Fun::ParserMem(
const void* src_buf,
int src_len,
const char* par_buf,
vector< vector<char> >& vec_result)
{
if ((NULL == src_buf) || (src_len <= 0) || strlen(par_buf) <= 0)
return FALSE;
vec_result.clear();
vector<char> vec_tmp;
BOOL bMatched = FALSE;
char*cp = (char*)src_buf;
char*src_end = (char*)src_buf + src_len;
int nParLen = strlen(par_buf);
char*find_buf = (char*)par_buf;
char*find_end = find_buf + nParLen;
char*s_src = NULL, *s_find = NULL;
while (cp < src_end)
{
s_src = cp;
s_find = (char*)find_buf;
while (s_src < src_end && s_find < find_end && *s_src == *s_find)
++s_src, ++s_find;
if (s_find == find_end)
{
bMatched = TRUE;
cp += nParLen;
vec_result.push_back(vec_tmp);
vec_tmp.clear();
}
else
{
vec_tmp.push_back(*cp);
++cp;
}
}
if(TRUE == bMatched)
vec_result.push_back(vec_tmp);
return(bMatched);
}
BOOL Glob_Fun::ParserMem(
const void* src_buf,
int src_len,
const char* par_buf,
vector<string>& vec_result)
{
if ((NULL == src_buf) || (src_len <= 0) || strlen(par_buf) <= 0)
return FALSE;
vec_result.clear();
string vec_tmp;
BOOL bMatched = FALSE;
char*cp = (char*)src_buf;
char*src_end = (char*)src_buf + src_len;
int nParLen = strlen(par_buf);
char*find_buf = (char*)par_buf;
char*find_end = find_buf + nParLen;
char*s_src = NULL, *s_find = NULL;
while (cp < src_end)
{
s_src = cp;
s_find = (char*)find_buf;
while (s_src < src_end && s_find < find_end && *s_src == *s_find)
++s_src, ++s_find;
if (s_find == find_end)
{
bMatched = TRUE;
cp += nParLen;
vec_result.push_back(vec_tmp);
vec_tmp.clear();
}
else
{
vec_tmp.push_back(*cp);
++cp;
}
}
if(TRUE == bMatched)
vec_result.push_back(vec_tmp);
return(bMatched);
}