Skip to content

Commit f3c6771

Browse files
committed
fix: check_line to end the check at the next \n after begin_with
1 parent afd7d6f commit f3c6771

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/main.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,20 @@ static char *file_read(const char *path, size_t *len) {
189189
// MARK: -
190190

191191
static bool check_line (const char *current, const char *begin_with, const char *end_with) {
192-
char *found1 = NULL;
193-
char *found2 = NULL;
192+
// find the end of the current line
193+
if (strlen(begin_with) > strlen(current)) return false;
194+
const char *line_end = strchr(current+strlen(begin_with), '\n');
195+
if (!line_end) line_end = current + strlen(current); // No newline, use end of string
194196

195-
found1 = strstr(current, begin_with);
196-
if (found1) found2 = strstr(current, end_with);
197+
// search for begin_with within the line
198+
const char *found1 = strstr(current, begin_with);
199+
if (!found1 || found1 > line_end) return false;
197200

198-
return ((found1 != NULL) && (found2 != NULL));
201+
// search for end_with after found1 but within the line
202+
const char *found2 = strstr(found1 + strlen(begin_with), end_with);
203+
if (!found2 || found2 > line_end) return false;
204+
205+
return true;
199206
}
200207

201208
static char *match_copy(const char *str, const char match) {

0 commit comments

Comments
 (0)