From e6f7aee8c27d87047857b9daf0075e90062b4ac2 Mon Sep 17 00:00:00 2001 From: Dmitry Mikhirev Date: Sun, 15 Feb 2015 15:10:15 +0300 Subject: added php-like options `A' and `D' --- README.md | 4 ++++ pcre.c | 4 ++++ tests.mk | 14 +++++++++++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9b3e3a2..6fc02d9 100644 --- a/README.md +++ b/README.md @@ -104,6 +104,10 @@ of one ore more characters, each of which enables some option: The following options are implemented: +- `A` makes expression anchored, i. e. constrained to match only at the first + matching point in the string. The same as in PHP; +- `D` forces a `$` metacharacter to match only before a newline at the end + of the string, not before any other newlines. The same as in PHP; - `E` enables expansion of pattern before compilation. Note that you will need to use `$$` instead `$` for matching end of line in this case; - `g` enables global search, like in Perl. `pcre_find` will return space diff --git a/pcre.c b/pcre.c index 3245d79..40f6c14 100644 --- a/pcre.c +++ b/pcre.c @@ -202,6 +202,10 @@ static int parse_comp_opt(const char flag, const char *func) int b; /* PCRE configuration option value */ switch (flag) { + case 'A': /* anchored regexp */ + return PCRE_ANCHORED; + case 'D': /* $ matches at the and of string only */ + return PCRE_DOLLAR_ENDONLY; case 'i': /* ignore case */ return PCRE_CASELESS; case 'm': /* multi-line */ diff --git a/tests.mk b/tests.mk index ce00b89..353735a 100644 --- a/tests.mk +++ b/tests.mk @@ -2,7 +2,7 @@ ifneq ($(findstring 4.,$(MAKE_VERSION)),4.) $(error you need GNU make 4.x to run tests) endif -NUMTESTS = 32 +NUMTESTS = 34 tests := $(foreach num,$(shell seq -f%03g $(NUMTESTS)),test$(num)) load pcre.so @@ -117,6 +117,18 @@ test030 = -z "$(m test.test,$(subj029))" -a \ test031 = "$(m x?,aaa,g)" = "" test032 = "$(s x?,!,abcd,g)" = "!a!b!c!d!" +# test `A' option +test033 = -z "$(m test,atest,A)" -a "$(m test,test,A)" = "test" + +# test `D' option +define subj034 +line1 +line2 + +endef +test034 = "$(m line\d$,$(subj034))" = "line2" -a -z "$(m line\d$,$(subj034),D)" -a \ + "$(m test$,test,D)" = "test" + ### END OF TEST EXPRESSIONS ### test%: -- cgit v1.2.1