Click here to Skip to main content
15,883,855 members
Articles / Desktop Programming / MFC

SmartReplace AddIn [VC 6.0]

Rate me:
Please Sign up or sign in to vote.
4.62/5 (16 votes)
23 Aug 20033 min read 68.5K   2K   32  
Yet another replace dialog
//***************************************************************************
//*
//*	File:			StringEx.h
//*	Description:	Adds some methods to CString
//*
//***************************************************************************
//*
//*	Note:			This source code is provided "as is" meaning that you may 
//*					use it at your own risk. 
//*					You are free to use it in any way you like.
//*
//***************************************************************************
//*
//*	History:		
//*
//*	-------------------------------------------------------------------------
//*	2003/07/27	|	Initial release									|	rk
//*	-------------------------------------------------------------------------
//*
//***************************************************************************

//
//-------------------------------------------------------------- PREPROCESSOR 
//

#ifndef			_STRINGEX_H_INCLUDED
#define			_STRINGEX_H_INCLUDED

#if				_MSC_VER > 1000
#pragma once
#ifdef			__SWITCH_SHOW_HEADER
#pragma message ("-- StringEx.h\n")
#endif
#ifdef			__SWITCH_SHOW_HEADER_TREE
#pragma message ("-- "__FILE__"\n")
#endif
#endif 

//
//-------------------------------------------------------------- DEPENDENCIES
//

//
//--------------------------------------------------------- CLASS DECLARATION
//

//***************************************************************************
//**	@DOC		CLASS CStringEx
//***************************************************************************
//*		@CLASS		Adds some methods to CString
//***************************************************************************
class CStringEx : public CString  
{
	//																										
	//-----------------------------------------------------------------------								
	//****************************     ENUMS     ****************************
	//-----------------------------------------------------------------------								
	//																										
public:																							// @ACCESS	Public Enumerations
	enum EMatchFlag																				// @CMEMBER	Replace flags
	{																							//
		EMatchFlag_Word			= 1 << 0														// @CMEMBER	Match whole words only
	,	EMatchFlag_Case			= 1 << 1														// @CMEMBER	Match case
	,	EMatchFlag_RegExpr		= 1 << 2														// @CMEMBER	Search string is a regular expression 
	,	EMatchFlag_AllCases		= 1 << 3														// @CMEMBER	Match all cases
	};

	//																										
	//-----------------------------------------------------------------------								
	//****************************     FIND     *****************************
	//-----------------------------------------------------------------------								
	//																										
public:																							// @ACCESS	Public Search and Replace Methods
			int		FindNoCase		( const CString&	a_strText
									,		int			a_iStart		= 0		)	const	;	// @CMEMBER	Finds the specified text while ignoring case
			int		FindAllCases	( const CString&	a_strText
									,		int			a_iStart		= 0		
									,		BOOL*		a_pbIsUpper		= NULL		
									,		BOOL*		a_pbIsLower		= NULL	)	const	;	// @CMEMBER	Finds the specified text or it's upper or lower case representation
			int		ReplaceNoCase	( const CString&	a_strFind
									, const CString&	a_strReplace			)			;	// @CMEMBER	Replaces all instances of the find string with the replace string while ignoring the case of the find string
			int		ReplaceAllCases	( const CString&	a_strFind
									, const CString&	a_strReplace			)			;	// @CMEMBER	Replaces all instances of the find string with the replace string for each case (as-is, lower and upper)
					
public:																							// @ACCESS	Public Extended Search and Replace Methods
			BOOL	Matches			( const CString&	a_strFind		
									,		DWORD		a_dwFlags				)	const	;	// @CMEMBER	Determines whether the string matches the specified search string
			int		FindEx			( const CString&	a_strFind				
									,		DWORD		a_dwFlags				)	const	;	// @CMEMBER	Finds the specfied text
			int		ReplaceEx		( const CString&	a_strFind				
									, const CString&	a_strReplace					
									,		DWORD		a_dwFlags				)			;	// @CMEMBER	Replaces all instances of the find string with the replace string 

	//																								
	//-----------------------------------------------------------------------						
	//***********************     CON/DESTRUCTION     ***********************						
	//-----------------------------------------------------------------------						
	//																								
public:																							// @ACCESS	Public Con-/Destruction Methods	
			 CStringEx( const	CStringEx&	a_strText )										;	// @CMEMBER	Copy		constructor
			 CStringEx( const	CString&	a_strText )										;	// @CMEMBER	Assignment	constructor
			 CStringEx( const	UCHAR		a_pchText )										;	// @CMEMBER	Assignment	constructor
			 CStringEx(			LPCTSTR		a_pchText )										;	// @CMEMBER	Assignment	constructor
			 CStringEx(			LPCWSTR		a_pchText )										;	// @CMEMBER	Assignment	constructor
			 CStringEx(			LPCTSTR		a_pchText	, int a_iLength 	)				;	// @CMEMBER	Assignment	constructor
			 CStringEx(			TCHAR		a_chChar	, int a_iRepeat = 1	)				;	// @CMEMBER	Assignment	constructor
			 CStringEx();																		// @CMEMBER	Default		constructor
};
//***************************************************************************
//**	@END
//***************************************************************************

#endif // _STRINGEX_H_INCLUDED

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions