diff --git a/Makefile b/Makefile index 857d2ee..c640f46 100644 --- a/Makefile +++ b/Makefile @@ -17,14 +17,15 @@ PYTHON != if (python --version 2>&1 | grep -q 'Python 2\..*'); then \ CFLAGS := -O3 -Wall -Wextra -std=c99 -I. all: - @$(CC) $(CFLAGS) re.c tests/test1.c -o tests/test1 - @$(CC) $(CFLAGS) re.c tests/test2.c -o tests/test2 - @$(CC) $(CFLAGS) re.c tests/test_rand.c -o tests/test_rand - @$(CC) $(CFLAGS) re.c tests/test_rand_neg.c -o tests/test_rand_neg - @$(CC) $(CFLAGS) re.c tests/test_compile.c -o tests/test_compile + @$(CC) $(CFLAGS) re.c tests/test1.c -o tests/test1 + @$(CC) $(CFLAGS) re.c tests/test2.c -o tests/test2 + @$(CC) $(CFLAGS) re.c tests/test_rand.c -o tests/test_rand + @$(CC) $(CFLAGS) re.c tests/test_rand_neg.c -o tests/test_rand_neg + @$(CC) $(CFLAGS) re.c tests/test_compile.c -o tests/test_compile + @$(CC) $(CFLAGS) re.c tests/test_end_anchor.c -o tests/test_end_anchor clean: - @rm -f tests/test1 tests/test2 tests/test_rand tests/test_compile + @rm -f tests/test1 tests/test2 tests/test_rand tests/test_compile tests/test_end_anchor @#@$(foreach test_bin,$(TEST_BINS), rm -f $(test_bin) ; ) @rm -f a.out @rm -f *.o @@ -106,4 +107,9 @@ test: all @./tests/test2 @echo @echo + @echo + @echo + @./tests/test_end_anchor + @echo + @echo diff --git a/re.c b/re.c index 20d1474..06bab58 100644 --- a/re.c +++ b/re.c @@ -99,6 +99,10 @@ int re_matchp(re_t pattern, const char* text, int* matchlength) return idx; } + + // Reset match length for the next starting point + *matchlength = 0; + } while (*text++ != '\0'); } diff --git a/tests/test_end_anchor.c b/tests/test_end_anchor.c new file mode 100644 index 0000000..1809f7c --- /dev/null +++ b/tests/test_end_anchor.c @@ -0,0 +1,20 @@ +#include +#include +#include "re.h" + +int main() { + + const char *text = "table football"; + const char *pattern = "l$"; + int index,len; + + index = re_match(pattern, text, &len); + + if (index==13 && len==1) { + return 0; + } else { + printf("ERROR! index=%d len=%d \n",index,len); + return -1; + } + +}