1c2c66affSColin Finck /*
2c2c66affSColin Finck * Copyright 2008 Jacek Caban for CodeWeavers
3c2c66affSColin Finck *
4c2c66affSColin Finck * This library is free software; you can redistribute it and/or
5c2c66affSColin Finck * modify it under the terms of the GNU Lesser General Public
6c2c66affSColin Finck * License as published by the Free Software Foundation; either
7c2c66affSColin Finck * version 2.1 of the License, or (at your option) any later version.
8c2c66affSColin Finck *
9c2c66affSColin Finck * This library is distributed in the hope that it will be useful,
10c2c66affSColin Finck * but WITHOUT ANY WARRANTY; without even the implied warranty of
11c2c66affSColin Finck * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12c2c66affSColin Finck * Lesser General Public License for more details.
13c2c66affSColin Finck *
14c2c66affSColin Finck * You should have received a copy of the GNU Lesser General Public
15c2c66affSColin Finck * License along with this library; if not, write to the Free Software
16c2c66affSColin Finck * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17c2c66affSColin Finck */
18c2c66affSColin Finck
19c2c66affSColin Finck /*
20c2c66affSColin Finck * Code in this file is based on files:
21c2c66affSColin Finck * js/src/jsregexp.h
22c2c66affSColin Finck * js/src/jsregexp.c
23c2c66affSColin Finck * from Mozilla project, released under LGPL 2.1 or later.
24c2c66affSColin Finck *
25c2c66affSColin Finck * The Original Code is Mozilla Communicator client code, released
26c2c66affSColin Finck * March 31, 1998.
27c2c66affSColin Finck *
28c2c66affSColin Finck * The Initial Developer of the Original Code is
29c2c66affSColin Finck * Netscape Communications Corporation.
30c2c66affSColin Finck * Portions created by the Initial Developer are Copyright (C) 1998
31c2c66affSColin Finck * the Initial Developer. All Rights Reserved.
32c2c66affSColin Finck */
33c2c66affSColin Finck
34*9f8faabaSAmine Khaldi #pragma once
35*9f8faabaSAmine Khaldi
36c2c66affSColin Finck #define REG_FOLD 0x01 /* fold uppercase to lowercase */
37c2c66affSColin Finck #define REG_GLOB 0x02 /* global exec, creates array of matches */
38c2c66affSColin Finck #define REG_MULTILINE 0x04 /* treat ^ and $ as begin and end of line */
39c2c66affSColin Finck #define REG_STICKY 0x08 /* only match starting at lastIndex */
40c2c66affSColin Finck
41c2c66affSColin Finck typedef struct RECapture {
42c2c66affSColin Finck ptrdiff_t index; /* start of contents, -1 for empty */
43c2c66affSColin Finck size_t length; /* length of capture */
44c2c66affSColin Finck } RECapture;
45c2c66affSColin Finck
46c2c66affSColin Finck typedef struct match_state_t {
47c2c66affSColin Finck const WCHAR *cp;
48c2c66affSColin Finck DWORD match_len;
49c2c66affSColin Finck
50c2c66affSColin Finck DWORD paren_count;
51c2c66affSColin Finck RECapture parens[1];
52c2c66affSColin Finck } match_state_t;
53c2c66affSColin Finck
54c2c66affSColin Finck typedef BYTE jsbytecode;
55c2c66affSColin Finck
56c2c66affSColin Finck typedef struct regexp_t {
57c2c66affSColin Finck WORD flags; /* flags, see jsapi.h's REG_* defines */
58c2c66affSColin Finck size_t parenCount; /* number of parenthesized submatches */
59c2c66affSColin Finck size_t classCount; /* count [...] bitmaps */
60c2c66affSColin Finck struct RECharSet *classList; /* list of [...] bitmaps */
61c2c66affSColin Finck const WCHAR *source; /* locked source string, sans // */
62c2c66affSColin Finck DWORD source_len;
63c2c66affSColin Finck jsbytecode program[1]; /* regular expression bytecode */
64c2c66affSColin Finck } regexp_t;
65c2c66affSColin Finck
66c2c66affSColin Finck regexp_t* regexp_new(void*, heap_pool_t*, const WCHAR*, DWORD, WORD, BOOL) DECLSPEC_HIDDEN;
67c2c66affSColin Finck void regexp_destroy(regexp_t*) DECLSPEC_HIDDEN;
68c2c66affSColin Finck HRESULT regexp_execute(regexp_t*, void*, heap_pool_t*, const WCHAR*,
69c2c66affSColin Finck DWORD, match_state_t*) DECLSPEC_HIDDEN;
70c2c66affSColin Finck HRESULT regexp_set_flags(regexp_t**, void*, heap_pool_t*, WORD) DECLSPEC_HIDDEN;
71c2c66affSColin Finck
alloc_match_state(regexp_t * regexp,heap_pool_t * pool,const WCHAR * pos)72c2c66affSColin Finck static inline match_state_t* alloc_match_state(regexp_t *regexp,
73c2c66affSColin Finck heap_pool_t *pool, const WCHAR *pos)
74c2c66affSColin Finck {
75c2c66affSColin Finck size_t size = offsetof(match_state_t, parens) + regexp->parenCount*sizeof(RECapture);
76c2c66affSColin Finck match_state_t *ret;
77c2c66affSColin Finck
78c2c66affSColin Finck ret = pool ? heap_pool_alloc(pool, size) : heap_alloc(size);
79c2c66affSColin Finck if(!ret)
80c2c66affSColin Finck return NULL;
81c2c66affSColin Finck
82c2c66affSColin Finck ret->cp = pos;
83c2c66affSColin Finck return ret;
84c2c66affSColin Finck }
85