|
Nishant S wrote:
Is there a case in-sensitive version of the CRT function strstr?
Unfortunately not, I always wondered why there is no strstri() or stristr() same like stricmp()
Possibly a good idea for a simple article. The aim is to have an optimised stristr().
Regards,
Victor
phpWebNotes is a page annotation system modelled after php.net.
http://webnotes.sourceforge.net/demo.php[^]
|
|
|
|
|
I guess that would be a Boyer-Moore[^] implementation
using a character test something like:
const int uc='a'-'A';
bool bMatch=c==d || c+uc==d && c>='A' && c<='Z' || c==d+uc && d>='A' && d<='Z';
|
|
|
|
|
|
|
Something I wrote a loooong time ago...
#ifdef UNICODE
#define _tcsustr wcsustr
#else
#define _tcsustr strustr
#endif
char* strustr(char *source, char *s);
wchar_t* wcsustr(wchar_t *source, wchar_t *s);
char* strustr(char *source, char *s)
{
char *csource = strdup(source);
char *cs = strdup(s);
strupr(csource);
strupr(cs);
char *result = strstr(csource, cs);
if (result != NULL)
{
int pos = result - csource;
result = source;
result += pos;
}
free(csource);
free(cs);
return result;
}
wchar_t* wcsustr(wchar_t *source, wchar_t *s)
{
wchar_t *csource = wcsdup(source);
wchar_t *cs = wcsdup(s);
wcsupr(csource);
wcsupr(cs);
wchar_t *result = wcsstr(csource, cs);
if (result != NULL)
{
int pos = result - csource;
result = source;
result += pos;
}
free(csource);
free(cs);
return result;
}
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
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).
|
|
|
|