From 510d6384033259be44b55e73283bafe38a53190a Mon Sep 17 00:00:00 2001 From: dx Date: Thu, 7 May 2020 02:58:56 +0100 Subject: +find_string algorithm This algorithm looks for substrings in a big string, attempting to find the index of the first occurence. --- Converter/includes/compiler.h | 3 ++- Converter/src/compiler.c | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'Converter') diff --git a/Converter/includes/compiler.h b/Converter/includes/compiler.h index 8b2fa1f..3b89b49 100644 --- a/Converter/includes/compiler.h +++ b/Converter/includes/compiler.h @@ -4,6 +4,7 @@ #include typedef char *string; -string compile_line(string line, size_t size_of_line, string line_or_source); +string compile_line(string line, size_t sz_line, string line_or_source); +int find_string(string src, string query, size_t sz_src, size_t sz_query); #endif // __COMPILER_H_ diff --git a/Converter/src/compiler.c b/Converter/src/compiler.c index 7efa032..df97c22 100644 --- a/Converter/src/compiler.c +++ b/Converter/src/compiler.c @@ -2,7 +2,14 @@ #include #include -void compile_inner_text(string dest, string src, size_t size_of_line, +int find_string(string src, string query, size_t sz_src, size_t sz_query) +{ + int j = 0; + while ((j < (sz_src - sz_query)) && (strncmp(query, src + j, sz_query))) ++j; + return j; +} + +void compile_inner_text(string dest, string src, size_t sz_src, string line_or_source) { /* cursor is the current index on the dest pointer -- cgit v1.2.3-13-gbd6f