Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Case Insensitive UTF8 strstr (find_first) (Read 5250 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Case Insensitive UTF8 strstr (find_first)

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: [Select]
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;
}
There used to be a link to my website here.

Case Insensitive UTF8 strstr (find_first)

Reply #1
I think I am just going to convert both to lower case then do a normal find_first...
There used to be a link to my website here.

Case Insensitive UTF8 strstr (find_first)

Reply #2
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.

 

Case Insensitive UTF8 strstr (find_first)

Reply #3
Quote
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.
[a href=\"index.php?act=findpost&pid=322313\"][{POST_SNAPBACK}][/a]

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.