⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 strsplitter.cpp

📁 模拟手机源程序,做短信系统(源码)
💻 CPP
字号:
/////////////////////////////////////////////////////////////////////
// 创建人:钟广荣
//创建时间:2001-3-29
//修改时间:2001-3-29
//功能:数据描述文件
/////////////////////////////////////////////////////////////////////

#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);*/
   memcpy(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(__int64 lSource/*,bool Transform*/)
{
	//if(Transform)
	//	lSource=htonl(lSource);//if use the network
	memcpy(&m_str[m_StrLen],&lSource,8);	
	m_StrLen=m_StrLen+8;
}
void StrSplitter::add(unsigned long lSource,bool Transform)
{
	if(Transform)
		lSource=htonl(lSource);//if use the network
	memcpy(&m_str[m_StrLen],&lSource,4);	
	m_StrLen=m_StrLen+4;
}
void StrSplitter::add(WORD lSource,bool Transform)
{
	if(Transform)
		lSource=htons(lSource);//if use the network
	memcpy(&m_str[m_StrLen],&lSource,2);	
	m_StrLen=m_StrLen+2;
}
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,bool Transform)
{		
	if (m_StrLen==0) return;
	memcpy(&return_lDest,&m_str[m_StrLen-4],4);
	if(Transform)
		return_lDest=ntohl(return_lDest);//convert back
	m_str[m_StrLen-4]='\0';
    m_StrLen=m_StrLen-4;
}
void StrSplitter::del(WORD &return_lDest,bool Transform)
{		
	if (m_StrLen==0) return;
	memcpy(&return_lDest,&m_str[m_StrLen-2],2);
	if(Transform)
		return_lDest=ntohs(return_lDest);//convert back
	m_str[m_StrLen-2]='\0';
    m_StrLen=m_StrLen-2;
}
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 + -