parsecstring.cpp

来自「**SgipSmg: 1、自己编写的遵循SGIP1.1的短信网关模拟程序。仅」· C++ 代码 · 共 95 行

CPP
95
字号
// Parsecstring.cpp: implementation of the CParsecstring class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Parsecstring.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CParsecstring::CParsecstring(CString *strtoparse)
{
	m_strtoparse = strtoparse;
	m_strToken  = ",";
	m_iCurTKPos = 0;//Cur Token pos
	m_iNextTKPos = 0;//next token pos
}

CParsecstring::~CParsecstring()
{

}

void CParsecstring::SetTocken(CString strToken)
{
	m_strToken = strToken;
}

////////////////////////////////////////////////////////
//ret value:-1:get nothing,then the caller must reset this calss' instances
//           0:get ok
//          1:get the last substr
////////////////////////////////////////////////////////
int CParsecstring::GetNextStr(CString &strnext)
{
	strnext = "";
	while(strnext == "")
	{
		if(m_iNextTKPos == -1)
		{
			return -1;
		}
		m_iNextTKPos = m_strtoparse->Find(m_strToken,m_iCurTKPos+1);
		if(m_iNextTKPos == -1)
		{
			if(m_iCurTKPos == 0)
			{
				strnext = m_strtoparse->Mid(m_iCurTKPos,m_strtoparse->GetLength() - m_iCurTKPos);
			}
			else
			{
				strnext = m_strtoparse->Mid(m_iCurTKPos+1,m_strtoparse->GetLength() - m_iCurTKPos-1);
			}
			strnext.TrimLeft();
			strnext.TrimRight();
			return 1;
		}
		else
		{
			if(m_iCurTKPos == 0)
			{
				strnext = m_strtoparse->Mid(m_iCurTKPos,m_iNextTKPos - m_iCurTKPos);
			}
			else
			{
				strnext = m_strtoparse->Mid(m_iCurTKPos+1,m_iNextTKPos - m_iCurTKPos-1);
			}
			m_iCurTKPos = m_iNextTKPos;
			strnext.TrimLeft();
			strnext.TrimRight();
		}
	}
	return 0;
}

void CParsecstring::Reset()
{
	m_iCurTKPos = 0;//Cur Token pos
	m_iNextTKPos = 0;//next token pos
}

void CParsecstring::SetParsestr(CString *strtoparse)
{
	m_strtoparse = strtoparse;
	m_iCurTKPos = 0;//Cur Token pos
	m_iNextTKPos = 0;//next token pos
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?