1 /**
2  * D bindings to the Perl-Compatible Regular Expressions library (libpcre)
3  *
4  * http://www.pcre.org/
5  *
6  * Needs linking using -lpcre
7  *
8  * Copyright:
9  *     Copyright (c) 2009-2016 dunnhumby Germany GmbH.
10  *     All rights reserved.
11  *
12  * License:
13  *     Boost Software License Version 1.0. See LICENSE_BOOST.txt for details.
14  *     Alternatively, this file may be distributed under the terms of the Tango
15  *     3-Clause BSD License (see LICENSE_BSD.txt for details).
16  *
17  *     Bear in mind this module provides bindings to an external library that
18  *     has its own license, which might be more restrictive. Please check the
19  *     external library license to see which conditions apply for linking.
20  */
21 
22 module ocean.text.regex.c.pcre;
23 
24 import ocean.meta.types.Qualifiers;
25 
26 extern (C):
27 
28 char* PCRE_SPTR;
29 
30 struct real_pcre;
31 alias real_pcre pcre;
32 
33 
34 // ulong might be also uint...needs to be checked...
35 struct pcre_extra {
36   ulong flags;
37   void* study_data;
38   ulong match_limit;
39   void* callout_data;
40   ubyte* tables;
41   ulong* match_limit_recursion;
42 };
43 
44 
45 static immutable int PCRE_CASELESS = 0x00000001;
46 static immutable int PCRE_MULTILINE = 0x00000002;
47 static immutable int PCRE_DOTALL = 0x00000004;
48 static immutable int PCRE_EXTENDED = 0x00000008;
49 static immutable int PCRE_ANCHORED = 0x00000010;
50 static immutable int PCRE_DOLLAR_ENDONLY = 0x00000020;
51 static immutable int PCRE_EXTRA = 0x00000040;
52 static immutable int PCRE_NOTBOL = 0x00000080;
53 static immutable int PCRE_NOTEOL = 0x00000100;
54 static immutable int PCRE_UNGREEDY = 0x00000200;
55 static immutable int PCRE_NOTEMPTY = 0x00000400;
56 static immutable int PCRE_UTF8 = 0x00000800;
57 static immutable int PCRE_NO_AUTO_CAPTURE = 0x00001000;
58 static immutable int PCRE_NO_UTF8_CHECK = 0x00002000;
59 static immutable int PCRE_AUTO_CALLOUT = 0x00004000;
60 static immutable int PCRE_PARTIAL = 0x00008000;
61 static immutable int PCRE_DFA_SHORTEST = 0x00010000;
62 static immutable int PCRE_DFA_RESTART = 0x00020000;
63 static immutable int PCRE_FIRSTLINE = 0x00040000;
64 static immutable int PCRE_DUPNAMES = 0x00080000;
65 static immutable int PCRE_NEWLINE_CR = 0x00100000;
66 static immutable int PCRE_NEWLINE_LF = 0x00200000;
67 static immutable int PCRE_NEWLINE_CRLF = 0x00300000;
68 static immutable int PCRE_NEWLINE_ANY = 0x00400000;
69 static immutable int PCRE_NEWLINE_ANYCRLF = 0x00500000;
70 static immutable int PCRE_BSR_ANYCRLF = 0x00800000;
71 static immutable int PCRE_BSR_UNICODE = 0x01000000;
72 static immutable int PCRE_JAVASCRIPT_COMPAT = 0x02000000;
73 
74 
75 static immutable int PCRE_ERROR_NOMATCH = (-1);
76 static immutable int PCRE_ERROR_NULL = (-2);
77 static immutable int PCRE_ERROR_BADOPTION = (-3);
78 static immutable int PCRE_ERROR_BADMAGIC = (-4);
79 static immutable int PCRE_ERROR_UNKNOWN_OPCODE = (-5);
80 static immutable int PCRE_ERROR_UNKNOWN_NODE = (-5);
81 static immutable int PCRE_ERROR_NOMEMORY = (-6);
82 static immutable int PCRE_ERROR_NOSUBSTRING = (-7);
83 static immutable int PCRE_ERROR_MATCHLIMIT = (-8);
84 static immutable int PCRE_ERROR_CALLOUT = (-9);
85 static immutable int PCRE_ERROR_BADUTF8 = (-10);
86 static immutable int PCRE_ERROR_BADUTF8_OFFSET = (-11);
87 static immutable int PCRE_ERROR_PARTIAL = (-12);
88 static immutable int PCRE_ERROR_BADPARTIAL = (-13);
89 static immutable int PCRE_ERROR_INTERNAL = (-14);
90 static immutable int PCRE_ERROR_BADCOUNT = (-15);
91 static immutable int PCRE_ERROR_DFA_UITEM = (-16);
92 static immutable int PCRE_ERROR_DFA_UCOND = (-17);
93 static immutable int PCRE_ERROR_DFA_UMLIMIT = (-18);
94 static immutable int PCRE_ERROR_DFA_WSSIZE = (-19);
95 static immutable int PCRE_ERROR_DFA_RECURSE = (-20);
96 static immutable int PCRE_ERROR_RECURSIONLIMIT = (-21);
97 static immutable int PCRE_ERROR_NULLWSLIMIT = (-22);
98 static immutable int PCRE_ERROR_BADNEWLINE = (-23);
99 
100 
101 static immutable int PCRE_INFO_OPTIONS = 0;
102 static immutable int PCRE_INFO_SIZE = 1;
103 static immutable int PCRE_INFO_CAPTURECOUNT = 2;
104 static immutable int PCRE_INFO_BACKREFMAX = 3;
105 static immutable int PCRE_INFO_FIRSTBYTE = 4;
106 static immutable int PCRE_INFO_FIRSTCHAR = 4;
107 static immutable int PCRE_INFO_FIRSTTABLE = 5;
108 static immutable int PCRE_INFO_LASTLITERAL = 6;
109 static immutable int PCRE_INFO_NAMEENTRYSIZE = 7;
110 static immutable int PCRE_INFO_NAMECOUNT = 8;
111 static immutable int PCRE_INFO_NAMETABLE = 9;
112 static immutable int PCRE_INFO_STUDYSIZE = 10;
113 static immutable int PCRE_INFO_DEFAULT_TABLES = 11;
114 static immutable int PCRE_INFO_OKPARTIAL = 12;
115 static immutable int PCRE_INFO_JCHANGED = 13;
116 static immutable int PCRE_INFO_HASCRORLF = 14;
117 
118 
119 static immutable int PCRE_CONFIG_UTF8 = 0;
120 static immutable int PCRE_CONFIG_NEWLINE = 1;
121 static immutable int PCRE_CONFIG_LINK_SIZE = 2;
122 static immutable int PCRE_CONFIG_POSIX_MALLOC_THRESHOLD = 3;
123 static immutable int PCRE_CONFIG_MATCH_LIMIT = 4;
124 static immutable int PCRE_CONFIG_STACKRECURSE = 5;
125 static immutable int PCRE_CONFIG_UNICODE_PROPERTIES = 6;
126 static immutable int PCRE_CONFIG_MATCH_LIMIT_RECURSION = 7;
127 static immutable int PCRE_CONFIG_BSR = 8;
128 
129 
130 static immutable int PCRE_EXTRA_STUDY_DATA = 0x0001;
131 static immutable int PCRE_EXTRA_MATCH_LIMIT = 0x0002;
132 static immutable int PCRE_EXTRA_CALLOUT_DATA = 0x0004;
133 static immutable int PCRE_EXTRA_TABLES = 0x0008;
134 static immutable int PCRE_EXTRA_MATCH_LIMIT_RECURSION = 0x0010;
135 
136 
137 pcre*  pcre_compile(char* pattern, int options, char** errptr, int* erroffset, ubyte* tableptr);
138 pcre*  pcre_compile2(char* pattern, int options, int* errorcodeptr, char** errptr, int* erroffset, ubyte* tableptr);
139 int    pcre_config(int what, void* where);
140 int    pcre_copy_named_substring(pcre* code, char* subject, int* ovector, int stringcount, char* stringname, char* buffer, int buffersize);
141 int    pcre_copy_substring(char* subject, int* ovector, int stringcount, int stringnumber, char* buffer, int buffersize);
142 int    pcre_dfa_exec(pcre* code, pcre_extra* extra, char* subject, int length, int startoffset, int options, int* ovector, int ovecsize, int* workspace, int wscount);
143 int    pcre_exec(pcre* code, pcre_extra* extra, const(char)* subject, int length, int startoffset, int options, int* ovector, int ovecsize);
144 void   pcre_free_substring(char* stringptr);
145 void   pcre_free_substring_list(char** stringptr);
146 int    pcre_fullinfo(pcre* code, pcre_extra* extra, int what, void* where);
147 int    pcre_get_named_substring(pcre* code, char* subject, int* ovector, int stringcount, char* stringname, char** stringptr);
148 int    pcre_get_stringnumber(pcre* code, char* name);
149 int    pcre_get_stringtable_entries(pcre* code, char* name, char** first, char** last);
150 int    pcre_get_substring(char* subject, int* ovector, int stringcount, int stringnumber, char** stringptr);
151 int    pcre_get_substring_list(char* subject, int* ovector, int stringcount, char*** listptr);
152 int    pcre_info(pcre* code, int* optptr, int* firstcharptr);
153 ubyte* pcre_maketables();
154 int    pcre_refcount(pcre* code, int adjust);
155 pcre_extra* pcre_study(pcre* code, int options, char ** errptr);
156