mirror of
https://gittea.dev/nova/th.git
synced 2025-10-21 10:20:15 -04:00
55 lines
1.1 KiB
C
55 lines
1.1 KiB
C
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
char* concat(const char *s1, const char *s2){
|
|
const size_t len1 = strlen(s1);
|
|
const size_t len2 = strlen(s2);
|
|
char *result = malloc(len1 + len2 + 1);
|
|
memcpy(result, s1, len1);
|
|
memcpy(result + len1, s2, len2 + 1);
|
|
return result;
|
|
}
|
|
char* smartstrcasestr(char *haystack, const char *needle){
|
|
char smart = 0;
|
|
char *ret;
|
|
char passes = 0;
|
|
while (*needle) {
|
|
if (*needle >= 'A' && *needle <= 'Z') {
|
|
smart = 1;
|
|
break;
|
|
}
|
|
passes++;
|
|
needle++;
|
|
}
|
|
needle -= passes;
|
|
if (smart == 0) {
|
|
char *needle_case = malloc(strlen(needle)+1);
|
|
strcpy(needle_case, needle);
|
|
passes = 0;
|
|
while (*needle_case) {
|
|
*needle_case = *needle_case | ' ';
|
|
needle_case++;
|
|
passes++;
|
|
}
|
|
needle_case -= passes;
|
|
|
|
char *haystack_case = malloc(strlen(haystack)+1);
|
|
strcpy(haystack_case, haystack);
|
|
passes = 0;
|
|
while (*haystack_case) {
|
|
*haystack_case = *haystack_case | ' ';
|
|
haystack_case++;
|
|
passes++;
|
|
}
|
|
haystack_case -= passes;
|
|
|
|
ret = strstr(haystack_case, needle_case);
|
|
free(needle_case);
|
|
free(haystack_case);
|
|
} else {
|
|
ret = strstr(haystack, needle);
|
|
}
|
|
return ret;
|
|
}
|
|
|