Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dda6696

Browse files
committed
AMK's revised version of the previous patch.
1 parent 0ef1b07 commit dda6696

3 files changed

Lines changed: 29 additions & 11 deletions

File tree

Modules/pcre-int.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*************************************************/
44

55

6-
#define PCRE_VERSION "1.07 16-Feb-1998"
6+
#define PCRE_VERSION "1.09 28-Apr-1998"
77

88

99
/* This is a library of functions to support regular expressions whose syntax
@@ -80,11 +80,12 @@ only some permitted at run or study time. */
8080
#ifdef FOR_PYTHON
8181
#define PUBLIC_OPTIONS \
8282
(PCRE_CASELESS|PCRE_EXTENDED|PCRE_ANCHORED|PCRE_MULTILINE| \
83-
PCRE_DOTALL|PCRE_DOLLAR_ENDONLY|PCRE_EXTRA|PCRE_LOCALE)
83+
PCRE_DOTALL|PCRE_DOLLAR_ENDONLY|PCRE_EXTRA|PCRE_UNGREEDY| \
84+
PCRE_LOCALE)
8485
#else
8586
#define PUBLIC_OPTIONS \
8687
(PCRE_CASELESS|PCRE_EXTENDED|PCRE_ANCHORED|PCRE_MULTILINE| \
87-
PCRE_DOTALL|PCRE_DOLLAR_ENDONLY|PCRE_EXTRA)
88+
PCRE_DOTALL|PCRE_DOLLAR_ENDONLY|PCRE_EXTRA|PCRE_UNGREEDY)
8889
#endif
8990
#define PUBLIC_EXEC_OPTIONS \
9091
(PCRE_CASELESS|PCRE_ANCHORED|PCRE_MULTILINE|PCRE_NOTBOL|PCRE_NOTEOL| \

Modules/pcre.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ extern "C" {
3434
#define PCRE_EXTRA 0x0040
3535
#define PCRE_NOTBOL 0x0080
3636
#define PCRE_NOTEOL 0x0100
37+
#define PCRE_UNGREEDY 0x0400
3738
#ifdef FOR_PYTHON
3839
#define PCRE_LOCALE 0x0200
3940
#endif

Modules/pypcre.c

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,6 +1216,7 @@ compile_branch(int options, int *brackets, uschar **codeptr,
12161216
int repeat_type, op_type;
12171217
int repeat_min, repeat_max;
12181218
int bravalue, length;
1219+
int greedy_default, greedy_non_default;
12191220
register int c;
12201221
register uschar *code = *codeptr;
12211222
const uschar *ptr = *ptrptr;
@@ -1224,6 +1225,11 @@ uschar *previous = NULL;
12241225
uschar class[32];
12251226
uschar *class_flag; /* Pointer to the single-byte flag for OP_CLASS_L */
12261227

1228+
/* Set up the default and non-default settings for greediness */
1229+
1230+
greedy_default = ((options & PCRE_UNGREEDY) != 0);
1231+
greedy_non_default = greedy_default ^ 1;
1232+
12271233
/* Switch on next character until the end of the branch */
12281234

12291235
for (;; ptr++)
@@ -1536,10 +1542,13 @@ for (;; ptr++)
15361542
goto FAILED;
15371543
}
15381544

1539-
/* If the next character is '?' this is a minimizing repeat. Advance to the
1545+
/* If the next character is '?' this is a minimizing repeat, by default,
1546+
but if PCRE_UNGREEDY is set, it works the other way round. Advance to the
15401547
next character. */
15411548

1542-
if (ptr[1] == '?') { repeat_type = 1; ptr++; } else repeat_type = 0;
1549+
if (ptr[1] == '?')
1550+
{ repeat_type = greedy_non_default; ptr++; }
1551+
else repeat_type = greedy_default;
15431552

15441553
/* If the maximum is zero then the minimum must also be zero; Perl allows
15451554
this case, so we do too - by simply omitting the item altogether. */
@@ -1628,14 +1637,20 @@ for (;; ptr++)
16281637
/* If the mininum is 1 and the previous item was a character string,
16291638
we either have to put back the item that got cancelled if the string
16301639
length was 1, or add the character back onto the end of a longer
1631-
string. For a character type nothing need be done; it will just get put
1632-
back naturally. */
1640+
string. For a character type nothing need be done; it will just get
1641+
put back naturally. Note that the final character is always going to
1642+
get added below. */
16331643

16341644
else if (*previous == OP_CHARS)
16351645
{
16361646
if (code == previous) code += 2; else previous[1]++;
16371647
}
16381648

1649+
/* For a single negated character we also have to put back the
1650+
item that got cancelled. */
1651+
1652+
else if (*previous == OP_NOT) code++;
1653+
16391654
/* If the maximum is unlimited, insert an OP_STAR. */
16401655

16411656
if (repeat_max < 0)
@@ -2484,7 +2499,7 @@ while ((c = *(++ptr)) != 0)
24842499
ptr += 2;
24852500
break;
24862501
}
2487-
/* Else fall thourh */
2502+
/* Else fall through */
24882503

24892504
/* Else loop setting valid options until ) is met. Anything else is an
24902505
error. */
@@ -2725,14 +2740,15 @@ printf("Length = %d top_bracket = %d top_backref=%d\n",
27252740

27262741
if (re->options != 0)
27272742
{
2728-
printf("%s%s%s%s%s%s%s\n",
2743+
printf("%s%s%s%s%s%s%s%s\n",
27292744
((re->options & PCRE_ANCHORED) != 0)? "anchored " : "",
27302745
((re->options & PCRE_CASELESS) != 0)? "caseless " : "",
27312746
((re->options & PCRE_EXTENDED) != 0)? "extended " : "",
27322747
((re->options & PCRE_MULTILINE) != 0)? "multiline " : "",
27332748
((re->options & PCRE_DOTALL) != 0)? "dotall " : "",
27342749
((re->options & PCRE_DOLLAR_ENDONLY) != 0)? "endonly " : "",
2735-
((re->options & PCRE_EXTRA) != 0)? "extra " : "");
2750+
((re->options & PCRE_EXTRA) != 0)? "extra " : "",
2751+
((re->options & PCRE_UNGREEDY) != 0)? "ungreedy " : "");
27362752
}
27372753

27382754
if ((re->options & PCRE_FIRSTSET) != 0)
@@ -3070,7 +3086,7 @@ static int grow_stack(match_data *md)
30703086
if (md->offset_top == NULL || md->eptr == NULL || md->ecode == NULL ||
30713087
md->off_num == NULL || md->r1 == NULL || md->r2 == NULL)
30723088
{
3073-
PyErr_SetString(PyExc_MemoryError, "Can't increase failure stack for re operation");
3089+
PyErr_NoMemory();
30743090
longjmp(md->error_env, 1);
30753091
}
30763092
return 0;

0 commit comments

Comments
 (0)