MCPcopy Create free account
hub / github.com/AutoHotkey/AutoHotkey / lstrcasestr

Function lstrcasestr

source/util.cpp:800–894  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

798
799
800LPTSTR lstrcasestr(LPCTSTR phaystack, LPCTSTR pneedle)
801// This is the locale-obeying variant of strcasestr. It uses CharUpper/Lower in place of toupper/lower,
802// which sees chars like ä as the same as Ä (depending on code page/locale). This function is about
803// 1 to 8 times slower than strcasestr() depending on factors such as how many partial matches for needle
804// are in haystack.
805// License: GNU GPL
806// Copyright (C) 1994,1996,1997,1998,1999,2000 Free Software Foundation, Inc.
807// See strcasestr() for more comments.
808{
809 register const TBYTE *haystack, *needle;
810 register unsigned bl, bu, cl, cu;
811
812 haystack = (const TBYTE *) phaystack;
813 needle = (const TBYTE *) pneedle;
814
815 bl = (UINT)ltolower(*needle);
816 if (bl != 0)
817 {
818 // Scan haystack until the first character of needle is found:
819 bu = (UINT)(size_t)ltoupper(bl);
820 haystack--; /* possible ANSI violation */
821 do
822 {
823 cl = *++haystack;
824 if (cl == '\0')
825 goto ret0;
826 }
827 while ((cl != bl) && (cl != bu));
828
829 // See if the rest of needle is a one-for-one match with this part of haystack:
830 cl = (UINT)ltolower(*++needle);
831 if (cl == '\0') // Since needle consists of only one character, it is already a match as found above.
832 goto foundneedle;
833 cu = (UINT)ltoupper(cl);
834 ++needle;
835 goto jin;
836
837 for (;;)
838 {
839 register unsigned a;
840 register const TBYTE *rhaystack, *rneedle;
841 do
842 {
843 a = *++haystack;
844 if (a == '\0')
845 goto ret0;
846 if ((a == bl) || (a == bu))
847 break;
848 a = *++haystack;
849 if (a == '\0')
850 goto ret0;
851shloop:
852 ;
853 }
854 while ((a != bl) && (a != bu));
855
856jin:
857 a = *++haystack;

Callers 1

CollectCharMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected