Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Internet Explorer AdBlock

, 17 Jan 2008 GPL3
Internet Explorer AdBlock Add-on
ieadblock_src.zip
IE AdBlockPS
IE AdBlockps.def
IE AdBlock
AdBlockBand.rgs
AdBlockBHO.rgs
bin
XListCtrlSSDU.lib
XListCtrlSSRU.lib
IE AdBlock.def
IE AdBlock.rgs
res
bmpToolbar.bmp
checkboxes.bmp
icoSettings.ico
XListCtrl
checkboxes.bmp
//*********************************************************************
// INCLUDES
//*********************************************************************

#include "stdafx.h"

//*********************************************************************
// FUNCTIONS
//*********************************************************************

CString StringUpper(CString sText)
{
	// Declare variables
	CString sTemp = _T("");

	// Make uppercase
#if (_MFC_VER < 0x0700)
	sText.MakeUpper();
#else
	sTemp = sText;
	sText = sTemp.MakeUpper();
#endif

	// Return string
	return sText;
}

//=====================================================================

CString StringLower(CString sText)
{
	// Declare variables
	CString sTemp = _T("");

	// Make lowercase
#if (_MFC_VER < 0x0700)
	sText.MakeLower();
#else
	sTemp = sText;
	sText = sTemp.MakeLower();
#endif

	// Return string
	return sText;
}

//=====================================================================

bool CompareWildCards(CString sString, CString sWild, CString sLimitChar /* = _T("") */)
{
	// Declare variables
    bool bAny = false;
    bool bNextIsOptional = false;
    bool bAutorizedChar = true;
    int i = 0;
    int j = 0;
	int iStringLength = sString.GetLength();
	int iWildLength = sWild.GetLength();

	// Check all the string char by char
    while (i < iStringLength) 
    {
		// Check index for array overflow
		if (j < iWildLength)
		{
			// Manage '*' in the wildcard
			if (sWild[j] == _T('*')) 
			{
				// Go to next character in the wildcard
				j++;

				// Enf of the string and wildcard end 
				// with *, only test string validity
				if (j >= iWildLength) 
				{
					// Check end of the string
					while ((sLimitChar != _T("")) && (i < iStringLength))
					{
						// If this char is not ok, return false
						if (sLimitChar.Find(sString[i]) < 0)
						{
							// Return FALSE
							return FALSE;
						}

						i++;
					}

					// Return TRUE
					return TRUE;
				}

				bAny = TRUE;
				bNextIsOptional = FALSE;
			} 
			else 
			{
				// Optional char in the wildcard
				if (sWild[j] == _T('^'))
				{
					// Go to next char in the wildcard and indicate 
					// that the next is optional
					j++;
 
					bNextIsOptional = TRUE;
				}
				else
				{
					bAutorizedChar = 
					  ((sLimitChar == _T("")) || (sLimitChar.Find(sString[i]) >= 0));

					// IF :
                    if (// Current char match the wildcard
						sWild[j] == sString[i] 
						// '?' is used and current char is in autorized char list
						|| (sWild[j] == _T('?') && bAutorizedChar)
						// Char is optional and it's not in the string
						// and it's necessary to test if '*' make any 
						// char browsing
						|| (bNextIsOptional && !(bAny && bAutorizedChar))) 
                    {
						// If current char match wildcard, 
						// we stop for any char browsing
						if (sWild[j] == sString[i])
						{
							bAny = FALSE;
						}

						// If it's not an optional char who is not present,
						// go to next
						if (sWild[j] == sString[i] || sWild[j] == _T('?'))
						{
							i++;
						}

						j++;

						bNextIsOptional = FALSE;
                    } 
                    else
					{
						// If we are in any char browsing ('*') 
						// and curent char is autorized
						if (bAny && bAutorizedChar)
						{
							// Go to next
							i++;
						}
						else
						{
							return FALSE;
						}
					}
				}
            }
        }
        else
        // End of the wildcard but not the 
        // end of the string => 
        // not matching
        return FALSE;
    }

	if ((j < iWildLength) && (sWild[j] == _T('^')))
	{
		bNextIsOptional = TRUE;
		j++;
	}

    // If the string is shorter than wildcard 
    // we test end of the 
    // wildcard to check matching
    while ((((j < iWildLength) && (sWild[j] == _T('*')))) || bNextIsOptional)
    {
        j++;
        bNextIsOptional = FALSE;

        if ((j < iWildLength) && (sWild[j] == _T('^')))
        {
            bNextIsOptional = TRUE;
            j++;
        }
    }

    return j >= iWildLength;
}

//=====================================================================

LPSTR ConvertToANSI(LPCWSTR sText)
{
	// len will hold the required length of converted string
	int len = WideCharToMultiByte(CP_ACP, 0, sText, -1, 0, 0, 0, 0);

	// allocate the buffer to hold the converted string
	LPSTR result = new char[len + 1];

	// do the conversion
	WideCharToMultiByte(CP_ACP, 0, sText, -1, result, len, 0, 0);

	// Return result
	return result;
}

//=====================================================================

LPCTSTR ConvertToUnicode(LPCSTR sText)
{
	// len will hold the required length of converted string
	int len = MultiByteToWideChar(CP_UTF8, 0, sText, -1, 0, 0);

	// allocate the buffer to hold the converted string
	LPTSTR result = new TCHAR[len];

	// do the conversion
#ifdef _UNICODE
	MultiByteToWideChar(CP_UTF8, 0, sText, -1, result, len);
#else
	MultiByteToWideChar(CP_UTF8, 0, sText, -1, (unsigned short *)result, len);
#endif

	// Return result
	return result;
}

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, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)

Share

About the Author

Geert van Horrik
Software Developer CatenaLogic
Netherlands Netherlands
I am Geert van Horrik, and I have studied Computer Science in the Netherlands.
 
I love to write software using .NET (especially the combination of WPF and C#). I am also the lead developer of Catel, an open-source application development framework for WPF, Silverlight, WP7 and WinRT with the focus on MVVM.
 
I have my own company since January 1st 2007, called CatenaLogic. This company develops commercial and non-commercial software.
 
To download (or buy) applications I have written, visit my website: http://www.catenalogic.com
Follow on   Twitter

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.141223.1 | Last Updated 17 Jan 2008
Article Copyright 2008 by Geert van Horrik
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid