Skip to content

Commit

Permalink
Add string position flags
Browse files Browse the repository at this point in the history
  • Loading branch information
vmg committed Oct 10, 2014
1 parent 0194688 commit f2b1a56
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
3 changes: 3 additions & 0 deletions pcre.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,12 @@ with J. */
/* This pair use the same bit. */
#define PCRE_NEVER_UTF 0x00010000 /* C1 ) Overlaid */
#define PCRE_DFA_SHORTEST 0x00010000 /* D ) Overlaid */
#define PCRE_NOTBOS 0x00010000 /* D ) Overlaid */

/* This pair use the same bit. */
#define PCRE_NO_AUTO_POSSESS 0x00020000 /* C1 ) Overlaid */
#define PCRE_DFA_RESTART 0x00020000 /* D ) Overlaid */
#define PCRE_NOTEOS 0x00020000 /* D ) Overlaid */

#define PCRE_FIRSTLINE 0x00040000 /* C3 */
#define PCRE_DUPNAMES 0x00080000 /* C1 */
Expand All @@ -169,6 +171,7 @@ with J. */
#define PCRE_PARTIAL_HARD 0x08000000 /* E D J */
#define PCRE_NOTEMPTY_ATSTART 0x10000000 /* E D J */
#define PCRE_UCP 0x20000000 /* C3 */
#define PCRE_NOTGPOS 0x40000000 /* C3 */

/* Exec-time and get/set-time error codes */

Expand Down
6 changes: 6 additions & 0 deletions pcre_exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -2075,6 +2075,7 @@ for (;;)

case OP_SOD:
if (eptr != md->start_subject) RRETURN(MATCH_NOMATCH);
if (op == OP_SOD && md->notbos) RRETURN(MATCH_NOMATCH);
ecode++;
break;

Expand All @@ -2092,6 +2093,7 @@ for (;;)

case OP_SOM:
if (eptr != md->start_subject + md->start_offset) RRETURN(MATCH_NOMATCH);
if (md->notgpos) RRETURN(MATCH_NOMATCH);
ecode++;
break;

Expand Down Expand Up @@ -2143,6 +2145,7 @@ for (;;)

case OP_EOD:
if (eptr < md->end_subject) RRETURN(MATCH_NOMATCH);
if (md->noteos) RRETURN(MATCH_NOMATCH);
SCHECK_PARTIAL();
ecode++;
break;
Expand Down Expand Up @@ -6554,6 +6557,9 @@ them will be faster than individual option bits. */

md->notbol = (options & PCRE_NOTBOL) != 0;
md->noteol = (options & PCRE_NOTEOL) != 0;
md->notbos = (options & PCRE_NOTBOS) != 0;
md->noteos = (options & PCRE_NOTEOS) != 0;
md->notgpos = (options & PCRE_NOTGPOS) != 0;
md->notempty = (options & PCRE_NOTEMPTY) != 0;
md->notempty_atstart = (options & PCRE_NOTEMPTY_ATSTART) != 0;

Expand Down
7 changes: 5 additions & 2 deletions pcre_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,7 @@ time, run time, or study time, respectively. */
#define PUBLIC_EXEC_OPTIONS \
(PCRE_ANCHORED|PCRE_NOTBOL|PCRE_NOTEOL|PCRE_NOTEMPTY|PCRE_NOTEMPTY_ATSTART| \
PCRE_NO_UTF8_CHECK|PCRE_PARTIAL_HARD|PCRE_PARTIAL_SOFT|PCRE_NEWLINE_BITS| \
PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE|PCRE_NO_START_OPTIMIZE)
PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE|PCRE_NO_START_OPTIMIZE|PCRE_NOTBOS|PCRE_NOTEOS|PCRE_NOTGPOS)

#define PUBLIC_DFA_EXEC_OPTIONS \
(PCRE_ANCHORED|PCRE_NOTBOL|PCRE_NOTEOL|PCRE_NOTEMPTY|PCRE_NOTEMPTY_ATSTART| \
Expand All @@ -1135,7 +1135,7 @@ time, run time, or study time, respectively. */

#define PUBLIC_JIT_EXEC_OPTIONS \
(PCRE_NO_UTF8_CHECK|PCRE_NOTBOL|PCRE_NOTEOL|PCRE_NOTEMPTY|\
PCRE_NOTEMPTY_ATSTART|PCRE_PARTIAL_SOFT|PCRE_PARTIAL_HARD)
PCRE_NOTEMPTY_ATSTART|PCRE_PARTIAL_SOFT|PCRE_PARTIAL_HARD|PCRE_NOTBOS|PCRE_NOTEOS|PCRE_NOTGPOS)

/* Magic number to provide a small check against being handed junk. */

Expand Down Expand Up @@ -2513,6 +2513,9 @@ typedef struct match_data {
const pcre_uint8 *ctypes; /* Points to table of type maps */
BOOL notbol; /* NOTBOL flag */
BOOL noteol; /* NOTEOL flag */
BOOL notbos; /* NOTBOS flag */
BOOL noteos; /* NOTEOS flag */
BOOL notgpos; /* NOTGPOS flag */
BOOL utf; /* UTF-8 / UTF-16 flag */
BOOL jscript_compat; /* JAVASCRIPT_COMPAT flag */
BOOL use_ucp; /* PCRE_UCP flag */
Expand Down
18 changes: 18 additions & 0 deletions pcre_jit_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ typedef struct jit_arguments {
int offset_count;
pcre_uint8 notbol;
pcre_uint8 noteol;
pcre_uint8 notbos;
pcre_uint8 noteos;
pcre_uint8 notgpos;
pcre_uint8 notempty;
pcre_uint8 notempty_atstart;
} jit_arguments;
Expand Down Expand Up @@ -5249,14 +5252,20 @@ switch(type)
{
case OP_SOD:
OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
OP1(SLJIT_MOV, TMP2, 0, ARGUMENTS, 0);
OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, begin));
add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, STR_PTR, 0, TMP1, 0));
OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(jit_arguments, notbos));
add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0));
return cc;

case OP_SOM:
OP1(SLJIT_MOV, TMP1, 0, ARGUMENTS, 0);
OP1(SLJIT_MOV, TMP2, 0, ARGUMENTS, 0);
OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(TMP1), SLJIT_OFFSETOF(jit_arguments, str));
add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, STR_PTR, 0, TMP1, 0));
OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(jit_arguments, notgpos));
add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0));
return cc;

case OP_NOT_WORD_BOUNDARY:
Expand Down Expand Up @@ -5519,7 +5528,10 @@ switch(type)
return cc;

case OP_EOD:
OP1(SLJIT_MOV, TMP2, 0, ARGUMENTS, 0);
add_jump(compiler, backtracks, CMP(SLJIT_C_LESS, STR_PTR, 0, STR_END, 0));
OP1(SLJIT_MOV_UB, TMP2, 0, SLJIT_MEM1(TMP2), SLJIT_OFFSETOF(jit_arguments, noteos));
add_jump(compiler, backtracks, CMP(SLJIT_C_NOT_EQUAL, TMP2, 0, SLJIT_IMM, 0));
check_partial(common, FALSE);
return cc;

Expand Down Expand Up @@ -10410,6 +10422,9 @@ if (functions->limit_match != 0 && functions->limit_match < arguments.limit_matc
arguments.limit_match = functions->limit_match;
arguments.notbol = (options & PCRE_NOTBOL) != 0;
arguments.noteol = (options & PCRE_NOTEOL) != 0;
arguments.notbos = (options & PCRE_NOTBOS) != 0;
arguments.noteos = (options & PCRE_NOTEOS) != 0;
arguments.notgpos = (options & PCRE_NOTGPOS) != 0;
arguments.notempty = (options & PCRE_NOTEMPTY) != 0;
arguments.notempty_atstart = (options & PCRE_NOTEMPTY_ATSTART) != 0;
arguments.offsets = offsets;
Expand Down Expand Up @@ -10503,6 +10518,9 @@ if (functions->limit_match != 0 && functions->limit_match < arguments.limit_matc
arguments.limit_match = functions->limit_match;
arguments.notbol = (options & PCRE_NOTBOL) != 0;
arguments.noteol = (options & PCRE_NOTEOL) != 0;
arguments.notbos = (options & PCRE_NOTBOS) != 0;
arguments.noteos = (options & PCRE_NOTEOS) != 0;
arguments.notgpos = (options & PCRE_NOTGPOS) != 0;
arguments.notempty = (options & PCRE_NOTEMPTY) != 0;
arguments.notempty_atstart = (options & PCRE_NOTEMPTY_ATSTART) != 0;
arguments.offsets = offsets;
Expand Down

0 comments on commit f2b1a56

Please sign in to comment.