Skip to content

Commit 12fcf4b

Browse files
committed
Replace strcasestr with custom implementation
1 parent 4d554c5 commit 12fcf4b

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

src/input.c

+25-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include <assert.h>
2424
#include <math.h>
25+
#include <wctype.h>
2526

2627
#define ARRLEN(x) (sizeof(x)/sizeof(x[0]))
2728
#define MAX(x, y) ((x) > (y) ? (x) : (y))
@@ -1009,11 +1010,33 @@ static bool handle_code_panel_key_press(void) {
10091010
return false;
10101011
}
10111012

1013+
static bool search_string(char* str, char* substr) {
1014+
if (*substr == 0) return true;
1015+
1016+
int next_ch, next_subch, cur_ch, cur_subch;
1017+
char* cur_substr = substr;
1018+
char* cur_str = str;
1019+
1020+
while (*cur_str != 0 && *cur_substr != 0) {
1021+
cur_ch = GetCodepointNext(cur_str, &next_ch);
1022+
cur_subch = GetCodepointNext(cur_substr, &next_subch);
1023+
1024+
if (towlower(cur_ch) == towlower(cur_subch)) {
1025+
cur_substr += next_subch;
1026+
cur_str += next_ch;
1027+
} else {
1028+
if (cur_substr == substr) cur_str += next_ch;
1029+
cur_substr = substr;
1030+
}
1031+
}
1032+
return *cur_substr == 0;
1033+
}
1034+
10121035
static bool search_blockdef(ScrBlockdef* blockdef) {
1013-
if (strcasestr(blockdef->id, search_list_search)) return true;
1036+
if (search_string(blockdef->id, search_list_search)) return true;
10141037
for (size_t i = 0; i < vector_size(blockdef->inputs); i++) {
10151038
if (blockdef->inputs[i].type != INPUT_TEXT_DISPLAY) continue;
1016-
if (strcasestr(blockdef->inputs[i].data.text, search_list_search)) return true;
1039+
if (search_string(blockdef->inputs[i].data.text, search_list_search)) return true;
10171040
}
10181041
return false;
10191042
}

0 commit comments

Comments
 (0)