|
Here's mine (ANSI only) :-
char * stristr (const char * string , const char * strCharSet )
{
char *pstart = (char *) string ;
char *s1, *s2;
if ( !*strCharSet )
return((char *)string );
while (*pstart)
{
s1 = pstart;
s2 = (char *) strCharSet ;
char c1, c2;
while ( *s1 && *s2 )
{
c1 = *s1;
c2 = *s2;
if( __isascii(c1) && isupper(c1) )
c1 = islower(c1);
if( __isascii(c2) && isupper(c2) )
c2 = islower(c2);
if(c1 - c2)
break;
s1++;
s2++;
}
if (!*s2)
return(pstart);
pstart++;
}
return(NULL);
}
Author of the romantic comedy
Summer Love and Some more Cricket [New Win]
Review by Shog9
Click here for review[NW]
|
|
|
|
|
Nishant S wrote:
s2 = (char *) strCharSet ;
Why all that casting?
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
strstr returns a non-const pointer. Sooner or later he has to cast.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
|
c1 = *s1;
c2 = *s2;
if( __isascii(c1) && isupper(c1) )
c1 = islower(c1);
if( __isascii(c2) && isupper(c2) )
c2 = islower(c2);
That won't work as is. You should have tolower and not islower. Also, the other tests are redundant.
c1 = tolower (*s1);
c2 = tolower (*s2);
The docs in MSDN aren't totally correct. They say to use isascii and isupper, but that is only true for _tolower, not tolower. However, if you want to keep that code in there, then you can switch to using _tolower which is just a blind macro to add the proper value to convert the case.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
|
Converting both characters to lower case is wasteful though.
You can get better performance using a test like so:
const int uc='a'-'A';
bool bMatch=c==d || c+uc==d && c>='A' && c<='Z' || c==d+uc && d>='A' && d<='Z';
This usually short-circuits to three comparisons in the majority case of no match. Where this code is located, every bit counts..
|
|
|
|
|
Cute...
stricmp uses some assembler tricks to do the following:
if (c1 != c2)
{
c1 = tolower (c1);
c2 = tolower (c2);
}
With the assebler tricks, it can avoid all the "jumps" associated with short cicuiting.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
yeah, there's something to be said for going back to
assembly at really crucial places. Just so long as it
is easy little jobs, it shouldn't make the whole too
unreadable.
|
|
|
|
|
Check my new post, the assembler version was slower than a stricmp version using your code.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Very interesting...
I just made a stricmp with your clause and compared it to MS's __ascii_stricmp and your version won by around 25-30%.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
I'm doing some text parsing for a simple, scripted language and I'd like to use regular expression matching to check syntax. Is there any support for regular expression matching in MFC?
|
|
|
|
|
|
Dov Sherman wrote:
Is there any support for regular expression matching in MFC?
Yes if you use VC 7.
|
|
|
|
|
boost.org has a regular expression class.
Todd Smith
|
|
|
|
|
O.K. need some directions on what to even call this function/call.
what I need to do is call another application, and fill out the fields with my application.
Part of an automation thing. In simple I wanted to call a simple .ini file, and have it use the information to fill out the dialog boxes in the other application.
could any one point me to what to search for or any links that could help in this process?
Note: NEWBEEE!!!!!!!
|
|
|
|
|
You will to determine the window id of all the windows on the dialog you want to fill out and a handle to window you are filling out. Then simply use
::SetDlgItemText( hWnd, WindowId, "value" );
There was a password retival tool posted here, some of the code from it should help you to determine the window ids.
|
|
|
|
|
Ahh I will continue to search, just had no clue what to search for.
would love to make it command lin based since it is to support at least 50 PC's.
Thanks for the direction!!!
|
|
|
|
|
I'm trying to use the PrintDlgEx method with Visual C++ 6.0. I have installed the Platform SDK (October 2002) and the include, lib, and exe directories for this are first in the directories option.
But I keep getting "error C2065: 'PRINTDLGEX' : undeclared identifier." It appears the complier is not look at the stuff in my "C:\Microsoft SDK" directories.
So what is required to get Visual C++ using the Platform SDK includes, libs, and exes?
Thanks for all input
Jonathan Craig
www.mcw-tech.com
|
|
|
|
|
You must define _WIN_NT 0x500 in stdafx before you include the common dialog files. This means that your application will only run on windows 2000 / xp (which is when printdlgex as added).
|
|
|
|
|
I don't see anywhere in the SDK include files a reference to _WIN_NT. I have added
#define _WIN32_WINNT 0x0500
and
#define WINVER 0x0500
to the stdafx.h file but I still get the same error.
Jonathan Craig
www.mcw-tech.com
|
|
|
|
|
Sorry, my mistake.
From CommDlg.h:
#if(WINVER >= 0x0500)
//
// PrintDlgEx structure.
//
typedef struct tagPDEXA {
DWORD lStructSize; // size of structure in bytes
HWND hwndOwner; // caller's window handle
HGLOBAL hDevMode; // handle to DevMode
HGLOBAL hDevNames; // handle to DevNames
HDC hDC; // printer DC/IC or NULL
DWORD Flags; // PD_ flags
DWORD Flags2; // reserved
DWORD ExclusionFlags; // items to exclude from driver pages
DWORD nPageRanges; // number of page ranges
DWORD nMaxPageRanges; // max number of page ranges
LPPRINTPAGERANGE lpPageRanges; // array of page ranges
DWORD nMinPage; // min page number
DWORD nMaxPage; // max page number
DWORD nCopies; // number of copies
HINSTANCE hInstance; // instance handle
LPCSTR lpPrintTemplateName; // template name for app specific area
LPUNKNOWN lpCallback; // app callback interface
DWORD nPropertyPages; // number of app property pages in lphPropertyPages
HPROPSHEETPAGE *lphPropertyPages; // array of app property page handles
DWORD nStartPage; // start page id
DWORD dwResultAction; // result action if S_OK is returned
} PRINTDLGEXA, *LPPRINTDLGEXA;
#endif
That means you need to define WINVER at 0x0500 before including Windows.h or CommDlg.h.
|
|
|
|
|
I have Dell with Windows 2000; the application is a MFC EXE developed using Visual C++ 6.0 enterprise.
After applying some modifications to the application, some of my client computers are receiving "Application Error" message. But this does not appeariing in the development computer.
The client computers and the developer computer have the same model and RAM size.
I am very frustrated. The "Application Error" is very difficult to trouble shoot.
Eilzabeth
|
|
|
|
|
|
I downloaded and installed CrashFinder with the CLW file dated 5/6/2002. I received compilation errors:
Compiling...
CrashFinderDoc.cpp
C:\download\CrashFinder\CrashFinderDoc.cpp(1107) : error C2065: 'SymDia' : undeclared identifier
C:\download\CrashFinder\CrashFinderDoc.cpp(1107) : error C2051: case expression not constant
Error executing cl.exe.
Do I have the good version?
Eilzabeth
|
|
|
|