tokenizer.h

来自「我用VC写的一个路面弯沉计算程序,可进行弯沉数据的批处理,简单使用」· C头文件 代码 · 共 71 行

H
71
字号
// Tokenizer.h: interface for the CTokenizer class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_TOKENIZER_H__508A9DAF_C77F_4BA0_9077_96D3121D6319__INCLUDED_)
#define AFX_TOKENIZER_H__508A9DAF_C77F_4BA0_9077_96D3121D6319__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <math.h>

#if !defined(_BITSET_)
#	include <bitset>
#endif // !defined(_BITSET_
class CTokenizer  
{
public:
	CTokenizer(const CString& cs, const CString& csDelim) : m_cs(cs), m_nCurPos(0)
	{
		SetDelimiters(csDelim);
	}
	void SetDelimiters(const CString& csDelim)
	{
		for(int i = 0; i < csDelim.GetLength(); ++i)
			m_sDelimiter.set(static_cast<BYTE>(csDelim[i]));
	}

	BOOL Next(CString& cs)
	{
		cs.Empty();

		while(m_nCurPos < m_cs.GetLength() && m_sDelimiter[static_cast<BYTE>(m_cs[m_nCurPos])])
			++m_nCurPos;

		if(m_nCurPos >= m_cs.GetLength())
			return FALSE;

		int nStartPos = m_nCurPos;
		while(m_nCurPos < m_cs.GetLength() && !m_sDelimiter[static_cast<BYTE>(m_cs[m_nCurPos])])
			++m_nCurPos;
		
		cs = m_cs.Mid(nStartPos, m_nCurPos - nStartPos);

		return TRUE;
	}

	CString	Tail() const
	{
		int nCurPos = m_nCurPos;

		while(nCurPos < m_cs.GetLength() && m_sDelimiter[static_cast<BYTE>(m_cs[nCurPos])])
			++nCurPos;

		CString csResult;

		if(nCurPos < m_cs.GetLength())
			csResult = m_cs.Mid(nCurPos);

		return csResult;
	}

private:
	CString m_cs;
	std::bitset<256> m_sDelimiter;
	int m_nCurPos;

};

#endif // !defined(AFX_TOKENIZER_H__508A9DAF_C77F_4BA0_9077_96D3121D6319__INCLUDED_)

⌨️ 快捷键说明

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