Click here to Skip to main content
15,885,365 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Radio Btns in Studio2008 - help Pin
john john mackey26-Mar-09 2:55
john john mackey26-Mar-09 2:55 
QuestionHow to Write DllMain Function Pin
dataminers23-Mar-09 6:49
dataminers23-Mar-09 6:49 
AnswerRe: How to Write DllMain Function Pin
TinyDevices23-Mar-09 7:21
professionalTinyDevices23-Mar-09 7:21 
AnswerRe: How to Write DllMain Function Pin
David Crow23-Mar-09 7:45
David Crow23-Mar-09 7:45 
QuestionC Implementation of Boyer-Moore of BMH Pin
Jeffrey Walton23-Mar-09 5:15
Jeffrey Walton23-Mar-09 5:15 
QuestionRe: C Implementation of Boyer-Moore of BMH Pin
David Crow23-Mar-09 5:54
David Crow23-Mar-09 5:54 
AnswerRe: C Implementation of Boyer-Moore of BMH Pin
Jeffrey Walton23-Mar-09 6:12
Jeffrey Walton23-Mar-09 6:12 
AnswerRe: C Implementation of Boyer-Moore of BMH Pin
Joe Woodbury23-Mar-09 12:20
professionalJoe Woodbury23-Mar-09 12:20 
This is from my bag-o-tricks library, but it's been a long time since I've tested or used them.

const char* CBTextSearch(const char* pSearchStr, const char* pStr, int textLen)
{
	if (!pSearchStr || !*pSearchStr)
		return pStr;

	if (!pStr || !*pStr)
		return NULL;

	if (textLen < 0)
		textLen = (int)strlen(pStr);

	int searchStrLen = (int)strlen(pSearchStr);

	// Setup m_skip table
	int pSkipTable[256];

	int i;
	for (i = 0; i < 256; i++)
		pSkipTable[i] = searchStrLen;

	for (i = 0; pSearchStr[i]; i++)
		pSkipTable[(BYTE)pSearchStr[i]] = searchStrLen - 1 - i;

	register int right = searchStrLen - 1;
	while (right < textLen)
	{
		int j;
		for (j = searchStrLen - 1, i = right; j >= 0 && pSearchStr[j] == pStr[i]; j--)
			i--;

		if (j == -1)
			return &pStr[i + 1];

		right = max(i + pSkipTable[(BYTE)pStr[i]], right + 1);
	}
	return NULL;
}

const wchar_t* CBTextSearch(const wchar_t* pSearchStr, const wchar_t* pStr, int textLen)
{
	if (!pSearchStr || !*pSearchStr)
		return pStr;

	if (!pStr || !*pStr)
		return NULL;

	if (textLen < 0)
		textLen = (int)wcslen(pStr);

	int searchStrLen = (int)wcslen(pSearchStr);

	// Setup m_skip table
	int* pSkipTable = (int*) _alloca(searchStrLen * sizeof(int));

	int i;
	for (i = 0; i < searchStrLen; i++)
		pSkipTable[i] = searchStrLen - 1 - i;

	register int right = searchStrLen - 1;
	while (right < textLen)
	{
		int j;
		for (j = searchStrLen - 1, i = right; j >= 0 && pSearchStr[j] == pStr[i]; j--)
			i--;

		if (j == -1)
			return &pStr[i + 1];

		for (j = searchStrLen - 1; j >= 0; j--)
		{
			if (pSearchStr[j] == pStr[i])
			{
				right = max(i + pSkipTable[j], right + 1);
				break;
			}
		}
		if (j < 0)
			right = max(i + searchStrLen, right + 1);
	}
	return NULL;
}



Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke


GeneralRe: C Implementation of Boyer-Moore of BMH Pin
Jeffrey Walton23-Mar-09 21:22
Jeffrey Walton23-Mar-09 21:22 
Questionreusable dialog code Pin
tnarb23-Mar-09 3:39
tnarb23-Mar-09 3:39 
AnswerRe: reusable dialog code Pin
Code-o-mat23-Mar-09 3:43
Code-o-mat23-Mar-09 3:43 
GeneralRe: reusable dialog code Pin
tnarb23-Mar-09 3:57
tnarb23-Mar-09 3:57 
GeneralRe: reusable dialog code Pin
David Crow23-Mar-09 3:59
David Crow23-Mar-09 3:59 
GeneralRe: reusable dialog code Pin
tnarb23-Mar-09 4:10
tnarb23-Mar-09 4:10 
GeneralRe: reusable dialog code Pin
Code-o-mat23-Mar-09 4:12
Code-o-mat23-Mar-09 4:12 
GeneralRe: reusable dialog code Pin
Yusuf23-Mar-09 7:49
Yusuf23-Mar-09 7:49 
GeneralRe: reusable dialog code Pin
Code-o-mat23-Mar-09 10:01
Code-o-mat23-Mar-09 10:01 
AnswerRe: reusable dialog code Pin
Alan Balkany23-Mar-09 4:03
Alan Balkany23-Mar-09 4:03 
AnswerRe: reusable dialog code Pin
Jonathan Davies23-Mar-09 4:03
Jonathan Davies23-Mar-09 4:03 
Questiondates Pin
Neal beavis23-Mar-09 3:34
Neal beavis23-Mar-09 3:34 
AnswerRe: dates Pin
Iain Clarke, Warrior Programmer23-Mar-09 3:36
Iain Clarke, Warrior Programmer23-Mar-09 3:36 
AnswerRe: dates Pin
Cedric Moonen23-Mar-09 3:37
Cedric Moonen23-Mar-09 3:37 
GeneralRe: dates Pin
Neal beavis23-Mar-09 3:41
Neal beavis23-Mar-09 3:41 
GeneralRe: dates Pin
Cedric Moonen23-Mar-09 3:46
Cedric Moonen23-Mar-09 3:46 
GeneralRe: dates Pin
Neal beavis23-Mar-09 3:49
Neal beavis23-Mar-09 3:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.