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

📄 nstring.h

📁 EVC环境下用SDK开发WINCE的应用程序
💻 H
字号:
// CNString.h : header file
//
// CNString Header
//
// Written by Paul E. Bible <pbible@littlefishsoftware.N>
// Copyright (c) 2000. All Rights Reserved.
//
// This code may be used in Npiled form in any way you desire. This
// file may be redistributed unmodified by any means PROVIDING it is 
// not sold for profit without the authors written consent, and 
// providing that this notice and the authors name and all copyright 
// notices remains intact. If the source code in this file is used in 
// any  Nmercial application then a statement along the lines of 
// "Portions copyright (c) Paul E. Bible, 2000" must be included in
// the startup banner, "About" box -OR- printed documentation. An email 
// letting me know that you are using it would be nice as well. That's 
// not much to ask considering the amount of work that went into this.
// If even this small restriction is a problem send me an email.
//
// This file is provided "as is" with no expressed or implied warranty.
// The author accepts no liability for any damage/loss of business that
// this product may cause.
//
// Expect bugs!
// 
// Please use and enjoy, and let me know of any bugs/mods/improvements 
// that you have found/implemented and I will fix/incorporate them into 
// this file. 
//
/////////////////////////////////////////////////////////////////////////////

#if !defined(AFX_NSTRING_H__C514A391_FB4C_11D3_AABC_0000E215F0C2__INCLUDED_)
#define AFX_NSTRING_H__C514A391_FB4C_11D3_AABC_0000E215F0C2__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <WTYPES.h>

// The max size for buffer array.
// if the length of string is smaller than it, it will be stored 
// in buffer array(avoid to memory allocation), otherwise we allocate
// a large enough memory block to hold the string.
const int NSTR_MAX_BUFFER = 255;
class CNString  
{
public: 
	CNString();
	CNString(CNString& szString);
	CNString(LPCTSTR pszString);
	CNString(BSTR bstrString);
	CNString(TCHAR ch, int nRepeat);
	virtual ~CNString();
	
	// Assignment Operations
	const CNString& operator=(CNString& strSrc);
	const CNString& operator=(LPCTSTR lpsz);
	const CNString& operator=(BSTR bstrStr);
	operator LPCTSTR() const	{ return m_pszString; }
	TCHAR*	GetString()			{ return m_pszString; }
	BSTR	AllocSysString();
	
	// Concatenation
	const CNString& operator+=(CNString& strSrc);
	const CNString& operator+=(LPCTSTR lpsz);
	const CNString& operator+=(BSTR bstrStr);
	const CNString& operator+=(TCHAR ch);
	friend CNString operator+(CNString& strSrc1, CNString& strSrc2);
	friend CNString operator+(CNString& strSrc, LPCTSTR lpsz);
	friend CNString operator+(LPCTSTR lpsz, CNString& strSrc);
	friend CNString operator+(CNString& strSrc, BSTR bstrStr);
	friend CNString operator+(BSTR bstrStr, CNString& strSrc);

	// Accessors for the String as an Array
	int		GetLength() const;
	bool	IsEmpty() const;
	void	Empty();
	TCHAR	GetAt(int nIndex);
	void	SetAt(int nIndex, TCHAR ch);
	TCHAR	operator[] (int nIndex);

	// Conversions
	void	MakeUpper();
	void	MakeLower();
	void	MakeReverse();
	void	TrimLeft();
	void	TrimRight();

	// Searching
	int		Find(TCHAR ch) const;
	int		Find(TCHAR ch, int nStart) const;
	int		Find(LPCTSTR lpszSub);
	int		Find(LPCTSTR lpszSub, int nStart);
	int		FindOneOf(LPCTSTR lpszCharSet) const;

	// Extraction
	CNString Mid(int nFirst) const;
	CNString Mid(int nFirst, int nCount) const;
	CNString Left(int nCount) const;
	CNString Right(int nCount) const;
	CNString SpanIncluding(LPCTSTR lpszCharSet) const;
	CNString SpanExcluding(LPCTSTR lpszCharSet) const;

	// Comparison
	int Compare(CNString& str) const;
	int Compare(LPCTSTR lpsz) const;
	int CompareNoCase(CNString& str) const;
	int CompareNoCase(LPCTSTR lpsz) const;
//	int Collate(CNString& str) const;
//	int Collate(LPCTSTR lpsz) const;

	// Formatting
	void Format(LPCTSTR pszCharSet, ...);

	// Replacing
	int Replace(TCHAR chOld, TCHAR chNew);
	int Replace(LPCTSTR lpszOld, LPCTSTR lpszNew);
	
protected:
	LPTSTR	m_pszString;
	TCHAR	m_szString[NSTR_MAX_BUFFER+1];
	void	StringCopy(CNString& str, int nLen, int nIndex, int nExtra) const;
	void	StringCopy(int nSrcLen, LPCTSTR lpszSrcData);
	void	ConcatCopy(LPCTSTR lpszData);
	void	ConcatCopy(TCHAR ch);
	void	ConcatCopy(LPCTSTR lpszData1, LPCTSTR lpszData2);
	void	AllocString(int nLen);
	void	ReAllocString(int nLen);
};	

// compare operations
bool operator==(const CNString& s1, const CNString& s2);
bool operator==(const CNString& s1, LPCTSTR s2);
bool operator==(LPCTSTR s1, const CNString& s2);
bool operator!=(const CNString& s1, const CNString& s2);
bool operator!=(const CNString& s1, LPCTSTR s2);
bool operator!=(LPCTSTR s1, const CNString& s2);

// compare implementations
inline bool operator==(const CNString& s1, const CNString& s2)
	{ return s1.Compare(s2) == 0; }
inline bool operator==(const CNString& s1, LPCTSTR s2)
	{ return s1.Compare(s2) == 0; }
inline bool operator==(LPCTSTR s1, const CNString& s2)
	{ return s2.Compare(s1) == 0; }
inline bool operator!=(const CNString& s1, const CNString& s2)
	{ return s1.Compare(s2) != 0; }
inline bool operator!=(const CNString& s1, LPCTSTR s2)
	{ return s1.Compare(s2) != 0; }
inline bool operator!=(LPCTSTR s1, const CNString& s2)
	{ return s2.Compare(s1) != 0; }

#endif // !defined(AFX_NSTRING_H__C514A391_FB4C_11D3_AABC_0000E215F0C2__INCLUDED_)

⌨️ 快捷键说明

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