--- code/trunk/pcre.c 2007/02/24 21:38:29 17 +++ code/trunk/pcre.c 2007/02/24 21:38:33 19 @@ -623,6 +623,7 @@ int repeat_type, op_type; int repeat_min, repeat_max; int bravalue, length; +int greedy_default, greedy_non_default; register int c; register uschar *code = *codeptr; const uschar *ptr = *ptrptr; @@ -630,6 +631,11 @@ uschar *previous = NULL; uschar class[32]; +/* Set up the default and non-default settings for greediness */ + +greedy_default = ((options & PCRE_UNGREEDY) != 0); +greedy_non_default = greedy_default ^ 1; + /* Switch on next character until the end of the branch */ for (;; ptr++) @@ -907,10 +913,13 @@ goto FAILED; } - /* If the next character is '?' this is a minimizing repeat. Advance to the + /* If the next character is '?' this is a minimizing repeat, by default, + but if PCRE_UNGREEDY is set, it works the other way round. Advance to the next character. */ - if (ptr[1] == '?') { repeat_type = 1; ptr++; } else repeat_type = 0; + if (ptr[1] == '?') + { repeat_type = greedy_non_default; ptr++; } + else repeat_type = greedy_default; /* If the maximum is zero then the minimum must also be zero; Perl allows this case, so we do too - by simply omitting the item altogether. */ @@ -1149,6 +1158,8 @@ case 'm': case 's': case 'x': + case 'U': + case 'X': ptr++; while (*ptr != ')') ptr++; previous = NULL; @@ -1752,7 +1763,7 @@ ptr += 2; break; } - /* Else fall thourh */ + /* Else fall through */ /* Else loop setting valid options until ) is met. Anything else is an error. */ @@ -1782,6 +1793,16 @@ length -= spaces; /* Already counted spaces */ continue; } + else if (c == 'X') + { + options |= PCRE_EXTRA; + continue; + } + else if (c == 'U') + { + options |= PCRE_UNGREEDY; + continue; + } else if (c == ')') break; *errorptr = ERR12; @@ -1987,14 +2008,15 @@ if (re->options != 0) { - printf("%s%s%s%s%s%s%s\n", + printf("%s%s%s%s%s%s%s%s\n", ((re->options & PCRE_ANCHORED) != 0)? "anchored " : "", ((re->options & PCRE_CASELESS) != 0)? "caseless " : "", ((re->options & PCRE_EXTENDED) != 0)? "extended " : "", ((re->options & PCRE_MULTILINE) != 0)? "multiline " : "", ((re->options & PCRE_DOTALL) != 0)? "dotall " : "", ((re->options & PCRE_DOLLAR_ENDONLY) != 0)? "endonly " : "", - ((re->options & PCRE_EXTRA) != 0)? "extra " : ""); + ((re->options & PCRE_EXTRA) != 0)? "extra " : "", + ((re->options & PCRE_UNGREEDY) != 0)? "ungreedy " : ""); } if ((re->options & PCRE_FIRSTSET) != 0)