📄 strsplitter.cpp
字号:
/////////////////////////////////////////////////////////////////////
//
//创建时间:2001-3-29
//修改时间:2001-3-29
//功能: 数据描述文件
//修改人: 杨祖明
//修改时间:2001-10-30
//修改原因:改版CMPP1.2
/////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "StrSplitter.h"
#include "winsock2.h"
StrSplitter::StrSplitter()
{
m_StrLen=0;
ZeroMemory(m_str,1024);
}
StrSplitter::StrSplitter(char* str,int len)
{
m_StrLen=0;
ZeroMemory(m_str,1024);
if (len>1024) len=1024;
int slen=strlen(str);
if (slen<len)
len=strlen(str);
strncpy(m_str,str,len);
m_StrLen=len;
}
StrSplitter::~StrSplitter()
{
}
void StrSplitter::add(char* strSource,int len)
{
memcpy(&m_str[m_StrLen],strSource,len);
m_StrLen=m_StrLen+len;
}
void StrSplitter::add(unsigned short nSource)
{
memcpy(&m_str[m_StrLen],&nSource,2);
m_StrLen=m_StrLen+2;
}
///////////////////////////////////////////////////////////////////////////////////
//函数名称:add(__int64 iSource)
//添加人: 杨祖明
//添加时间:2001-9-12
//备注:
//////////////////////////////////////////////////////////////////////////////////
void StrSplitter::add(__int64 iSource)
{
memcpy(&m_str[m_StrLen],&iSource,8);
m_StrLen=m_StrLen+8;
}
void StrSplitter::add(unsigned long lSource)
{
//lSource=htonl(lSource);//if use the network
memcpy(&m_str[m_StrLen],&lSource,4);
m_StrLen=m_StrLen+4;
}
void StrSplitter::add(unsigned char cSource)
{
memcpy(&m_str[m_StrLen],&cSource,1);
m_StrLen=m_StrLen+1;
}
void StrSplitter::del(int len,char* strbuf)
{
if (m_StrLen==0) return;
if (m_StrLen<=len)
{
strbuf=NULL;
return;
}
else
{
memcpy(strbuf,&m_str[m_StrLen-len],len);
m_str[m_StrLen-len]='\0';
}
m_StrLen=m_StrLen-len;
}
void StrSplitter::del(unsigned long &return_lDest)
{
if (m_StrLen==0) return;
memcpy(&return_lDest,&m_str[m_StrLen-4],4);
//return_lDest=ntohl(return_lDest);//convert back
m_str[m_StrLen-4]='\0';
m_StrLen=m_StrLen-4;
}
void StrSplitter::del(unsigned char &return_cDest)
{
if (m_StrLen==0) return;
memcpy(&return_cDest,&m_str[m_StrLen-1],1);
m_str[m_StrLen-1]='\0';
m_StrLen=m_StrLen-1;
}
char* StrSplitter::GetStr()
{
return m_str;
}
void StrSplitter::SetBuffer(void* str,int Len)
{
ZeroMemory(m_str,1024);
memcpy(m_str,str,Len);
m_StrLen=Len;
}
void StrSplitter::ResetBuff()
{
ZeroMemory(m_str,1024);
m_StrLen=0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -