Help - Search - Members - Calendar
Full Version: Case Insensitive UTF8 strstr (find_first)
Hydrogenaudio Forums > Hosted Forums > foobar2000 > Development - (fb2k)
cwbowron
I'm looking for a case insensitive strstr / find_first operation that works on utf8 for the searching in my playlist tree plugin. Is there one in the sdk or has anyone ever written one?

The code I am using is below, but only will only be case insensitive for ascii characters...

CODE
static const char * stristr(const char *haystack, const char *needle)
{
int i,j;

int len_haystack = strlen(haystack);
int len_needle = strlen(needle);
int max_haystack = strlen(haystack) - strlen(needle) + 1;

for (i=0;i<max_haystack;i++)
{
 for (j=0;;j++)
 {
  if (j == len_needle)
   return haystack+i;
 
  if (tolower(haystack[i+j]) != tolower(needle[j]))
   break;
 }
}
return 0;
}
cwbowron
I think I am just going to convert both to lower case then do a normal find_first...

JackieKu
Use StrStrI() (or StrStrIA(), the A means ANSI version) in Win32 API should be a good solution?
If you need to get the position of the matched string and need to reserve the original string.
And I think it perform a more efficient algorithm to finding the string than you introduced.
oshah
QUOTE(JackieKu @ Aug 24 2005, 02:52 PM)
Use StrStrI() (or StrStrIA(), the A means ANSI version) in Win32 API should be a good solution?
If you need to get the position of the matched string and need to reserve the original string.
And I think it perform a more efficient algorithm to finding the string than you introduced.
*



Using StrStrI comes with one caveat: Internet Explorer 4.0 must be installed, because StrStrI is implemented in SHLWAPI.DLL. SHLWAPI.DLL is a non-system DLL that is only present if the user downloaded IE4. If the user has not installed internet explorer, your plugin will fail to load (missing export error).

IE4 Is installed by default in Windows 98 and later, and it cannot be removed (well it can, but only by using some 3rd party utilities that completely mutilate the OS to the point where nothing runs on it anyway). However, for Windows 95/NT, that's another story.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.