2020 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2121 */
2222
23- #include <stdio.h>
2423#include <stdint.h>
2524#include <string.h>
25+ #include <ctype.h>
2626
2727#include <lists/string_list.h>
2828#include <compat/strl.h>
2929#include <compat/posix_string.h>
30- #include <string/stdstring.h>
3130
3231static bool string_list_deinitialize_internal (struct string_list * list )
3332{
@@ -349,13 +348,20 @@ bool string_split_noalloc(struct string_list *list,
349348
350349int string_list_find_elem (const struct string_list * list , const char * elem )
351350{
352- if (list )
351+ if (list && elem )
353352 {
354353 size_t i ;
355354 for (i = 0 ; i < list -> size ; i ++ )
356355 {
357- if (string_is_equal_noncase (list -> elems [i ].data , elem ))
358- return (int )(i + 1 );
356+ const unsigned char * p1 = (const unsigned char * )list -> elems [i ].data ;
357+ const unsigned char * p2 = (const unsigned char * )elem ;
358+ while ((* p1 | 32 ) == (* p2 | 32 ) || (* p1 == * p2 ))
359+ {
360+ if (* p1 == '\0' )
361+ return (int )(i + 1 );
362+ p1 ++ ;
363+ p2 ++ ;
364+ }
359365 }
360366 }
361367 return 0 ;
@@ -372,9 +378,26 @@ bool string_list_find_elem_prefix(const struct string_list *list,
372378 strlcpy (prefixed + _len , elem , sizeof (prefixed ) - _len );
373379 for (i = 0 ; i < list -> size ; i ++ )
374380 {
375- if ( string_is_equal_noncase (list -> elems [i ].data , elem )
376- || string_is_equal_noncase (list -> elems [i ].data , prefixed ))
377- return true;
381+ const char * data = list -> elems [i ].data ;
382+ const char * a = data ;
383+ const char * b = elem ;
384+ while (tolower ((unsigned char )* a ) == tolower ((unsigned char )* b ))
385+ {
386+ if (* a == '\0' )
387+ return true;
388+ a ++ ;
389+ b ++ ;
390+ }
391+
392+ a = data ;
393+ b = prefixed ;
394+ while (tolower ((unsigned char )* a ) == tolower ((unsigned char )* b ))
395+ {
396+ if (* a == '\0' )
397+ return true;
398+ a ++ ;
399+ b ++ ;
400+ }
378401 }
379402 }
380403 return false;
0 commit comments