1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>pcre++.cc Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.3-rc3 -->
<center>
<a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="namespaces.html">Namespace List</a> <a class="qindex" href="annotated.html">Compound List</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="functions.html">Compound Members</a> <a class="qindex" href="globals.html">File Members</a> </center>
<hr><h1>pcre++.cc</h1><a href="pcre++_8cc.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <span class="comment">/*</span>
00002 <span class="comment"> *</span>
00003 <span class="comment"> * This file is part of the PCRE++ Class Library.</span>
00004 <span class="comment"> *</span>
00005 <span class="comment"> * By accessing this software, PCRE++, you are duly informed</span>
00006 <span class="comment"> * of and agree to be bound by the conditions described below</span>
00007 <span class="comment"> * in this notice:</span>
00008 <span class="comment"> *</span>
00009 <span class="comment"> * This software product, PCRE++, is developed by Thomas Linden</span>
00010 <span class="comment"> * and copyrighted (C) 2002-2003 by Thomas Linden,with all rights </span>
00011 <span class="comment"> * reserved.</span>
00012 <span class="comment"> *</span>
00013 <span class="comment"> * There is no charge for PCRE++ software. You can redistribute</span>
00014 <span class="comment"> * it and/or modify it under the terms of the GNU Lesser General</span>
00015 <span class="comment"> * Public License, which is incorporated by reference herein.</span>
00016 <span class="comment"> *</span>
00017 <span class="comment"> * PCRE++ is distributed WITHOUT ANY WARRANTY, IMPLIED OR EXPRESS,</span>
00018 <span class="comment"> * OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE or that</span>
00019 <span class="comment"> * the use of it will not infringe on any third party's intellec-</span>
00020 <span class="comment"> * tual property rights.</span>
00021 <span class="comment"> *</span>
00022 <span class="comment"> * You should have received a copy of the GNU Lesser General Public</span>
00023 <span class="comment"> * License along with PCRE++. Copies can also be obtained from:</span>
00024 <span class="comment"> *</span>
00025 <span class="comment"> * http://www.gnu.org/licenses/lgpl.txt</span>
00026 <span class="comment"> *</span>
00027 <span class="comment"> * or by writing to:</span>
00028 <span class="comment"> *</span>
00029 <span class="comment"> * Free Software Foundation, Inc.</span>
00030 <span class="comment"> * 59 Temple Place, Suite 330</span>
00031 <span class="comment"> * Boston, MA 02111-1307</span>
00032 <span class="comment"> * USA</span>
00033 <span class="comment"> *</span>
00034 <span class="comment"> * Or contact:</span>
00035 <span class="comment"> *</span>
00036 <span class="comment"> * "Thomas Linden" <tom@daemon.de></span>
00037 <span class="comment"> *</span>
00038 <span class="comment"> *</span>
00039 <span class="comment"> */</span>
00040
00041
00042 <span class="preprocessor">#include "<a class="code" href="pcre++_8h.html">pcre++.h</a>"</span>
00043
00044 <span class="keyword">using</span> <span class="keyword">namespace </span>std;
00045 <span class="keyword">using</span> <span class="keyword">namespace </span>pcrepp;
00046
00047 <span class="comment">/*</span>
00048 <span class="comment"> * CONSTRUCTORS and stuff</span>
00049 <span class="comment"> */</span>
<a name="l00050"></a><a class="code" href="classpcrepp_1_1Pcre.html#a1">00050</a> Pcre::Pcre(<span class="keyword">const</span> string& expression) {
00051 _have_paren = <span class="keyword">false</span>;
00052 _expression = expression;
00053 _flags = 0;
00054 case_t = global_t = <span class="keyword">false</span>;
00055 zero();
00056 Compile(0);
00057 }
00058
<a name="l00059"></a><a class="code" href="classpcrepp_1_1Pcre.html#a2">00059</a> Pcre::Pcre(<span class="keyword">const</span> string& expression, <span class="keyword">const</span> string& flags) {
00060 _have_paren = <span class="keyword">false</span>;
00061 _expression = expression;
00062 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> FLAG = 0;
00063
00064 <span class="keywordflow">for</span>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> flag=0; flag<flags.length(); flag++) {
00065 <span class="keywordflow">switch</span>(flags[flag]) {
00066 <span class="keywordflow">case</span> <span class="charliteral">'i'</span>: FLAG |= PCRE_CASELESS; case_t = <span class="keyword">true</span>; <span class="keywordflow">break</span>;
00067 <span class="keywordflow">case</span> <span class="charliteral">'m'</span>: FLAG |= PCRE_MULTILINE; <span class="keywordflow">break</span>;
00068 <span class="keywordflow">case</span> <span class="charliteral">'s'</span>: FLAG |= PCRE_DOTALL; <span class="keywordflow">break</span>;
00069 <span class="keywordflow">case</span> <span class="charliteral">'x'</span>: FLAG |= PCRE_EXTENDED; <span class="keywordflow">break</span>;
00070 <span class="keywordflow">case</span> <span class="charliteral">'g'</span>: global_t = <span class="keyword">true</span>; <span class="keywordflow">break</span>;
00071 }
00072 }
00073
00074 _flags = FLAG;
00075
00076 zero();
00077 Compile(FLAG);
00078 }
00079
<a name="l00080"></a><a class="code" href="classpcrepp_1_1Pcre.html#a3">00080</a> Pcre::Pcre(<span class="keyword">const</span> string& expression, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> flags) {
00081 _have_paren = <span class="keyword">false</span>;
00082 _expression = expression;
00083 _flags = flags;
00084
00085 <span class="keywordflow">if</span>((_flags & PCRE_CASELESS) != 0)
00086 case_t = <span class="keyword">true</span>;
00087
00088 <span class="keywordflow">if</span>((_flags & <a class="code" href="pcre++_8h.html#a1">PCRE_GLOBAL</a>) != 0) {
00089 global_t = <span class="keyword">true</span>;
00090 _flags = _flags - <a class="code" href="pcre++_8h.html#a1">PCRE_GLOBAL</a>; <span class="comment">/* remove pcre++ flag before feeding _flags to pcre */</span>
00091 }
00092
00093 zero();
00094 Compile(_flags);
00095 }
00096
<a name="l00097"></a><a class="code" href="classpcrepp_1_1Pcre.html#a4">00097</a> Pcre::Pcre(<span class="keyword">const</span> <a class="code" href="classpcrepp_1_1Pcre.html">Pcre</a> &P) {
00098 _have_paren = P.<a class="code" href="classpcrepp_1_1Pcre.html#o11">_have_paren</a>;
00099 _expression = P.<a class="code" href="classpcrepp_1_1Pcre.html#o0">_expression</a>;
00100 _flags = P.<a class="code" href="classpcrepp_1_1Pcre.html#o1">_flags</a>;
00101 case_t = P.<a class="code" href="classpcrepp_1_1Pcre.html#o2">case_t</a>;
00102 global_t = P.<a class="code" href="classpcrepp_1_1Pcre.html#o3">global_t</a>;
00103 zero();
00104 Compile(_flags);
00105 }
00106
<a name="l00107"></a><a class="code" href="classpcrepp_1_1Pcre.html#a0">00107</a> Pcre::Pcre() {
00108 zero();
00109 }
00110
00111
00112
00113
00114
00115
00116
00117 <span class="comment">/*</span>
00118 <span class="comment"> * Destructor</span>
00119 <span class="comment"> */</span>
<a name="l00120"></a><a class="code" href="classpcrepp_1_1Pcre.html#a7">00120</a> Pcre::~Pcre() {
00121 <span class="comment">/* avoid deleting of uninitialized pointers */</span>
00122 <span class="keywordflow">if</span> (p_pcre != NULL) {
00123 pcre_free(p_pcre);
00124 }
00125 <span class="keywordflow">if</span> (p_pcre_extra != NULL) {
00126 pcre_free(p_pcre_extra);
00127 }
00128 <span class="keywordflow">if</span>(sub_vec != NULL) {
00129 <span class="keyword">delete</span>[] sub_vec;
00130 }
00131 <span class="keywordflow">if</span>(resultset != NULL) {
00132 <span class="keyword">delete</span> resultset;
00133 }
00134 }
00135
00136
00137
00138
00139 <span class="comment">/*</span>
00140 <span class="comment"> * operator= definitions</span>
00141 <span class="comment"> */</span>
<a name="l00142"></a><a class="code" href="classpcrepp_1_1Pcre.html#a5">00142</a> <span class="keyword">const</span> <a class="code" href="classpcrepp_1_1Pcre.html">Pcre</a>& Pcre::operator = (<span class="keyword">const</span> string& expression) {
00143 <span class="comment">/* reset the object and re-intialize it */</span>
00144 reset();
00145 _expression = expression;
00146 _flags = 0;
00147 case_t = global_t = <span class="keyword">false</span>;
00148 Compile(0);
00149 <span class="keywordflow">return</span> *<span class="keyword">this</span>;
00150 }
00151
00152
<a name="l00153"></a><a class="code" href="classpcrepp_1_1Pcre.html#a6">00153</a> <span class="keyword">const</span> <a class="code" href="classpcrepp_1_1Pcre.html">Pcre</a>& Pcre::operator = (<span class="keyword">const</span> <a class="code" href="classpcrepp_1_1Pcre.html">Pcre</a> &P) {
00154 reset();
00155 _expression = P.<a class="code" href="classpcrepp_1_1Pcre.html#o0">_expression</a>;
00156 _flags = P.<a class="code" href="classpcrepp_1_1Pcre.html#o1">_flags</a>;
00157 case_t = P.<a class="code" href="classpcrepp_1_1Pcre.html#o2">case_t</a>;
00158 global_t = P.<a class="code" href="classpcrepp_1_1Pcre.html#o3">global_t</a>;
00159 zero();
00160 Compile(_flags);
00161 <span class="keywordflow">return</span> *<span class="keyword">this</span>;
00162 }
00163
00164
00165
00166
00167
00168
00169 <span class="comment">/*</span>
00170 <span class="comment"> * mem resetting methods</span>
00171 <span class="comment"> */</span>
00172 <span class="keywordtype">void</span> Pcre::zero() {
00173 <span class="comment">/* what happens if p_pcre is already allocated? hm ... */</span>
00174 p_pcre_extra = NULL;
00175 p_pcre = NULL;
00176 sub_vec = NULL;
00177 resultset = NULL;
00178 err_str = NULL;
00179 num_matches = -1;
00180 tables = NULL;
00181 }
00182
00183 <span class="keywordtype">void</span> Pcre::reset() {
00184 did_match = <span class="keyword">false</span>;
00185 num_matches = -1;
00186 }
00187
00188
00189
00190
00191
00192 <span class="comment">/*</span>
00193 <span class="comment"> * accessing the underlying implementation</span>
00194 <span class="comment"> */</span>
<a name="l00195"></a><a class="code" href="classpcrepp_1_1Pcre.html#a25">00195</a> pcre* Pcre::get_pcre() {
00196 <span class="keywordflow">return</span> p_pcre;
00197 }
00198
<a name="l00199"></a><a class="code" href="classpcrepp_1_1Pcre.html#a26">00199</a> pcre_extra* Pcre::get_pcre_extra() {
00200 <span class="keywordflow">return</span> p_pcre_extra;
00201 }
00202
00203
00204
00205
00206
00207 <span class="comment">/*</span>
00208 <span class="comment"> * support stuff</span>
00209 <span class="comment"> */</span>
<a name="l00210"></a><a class="code" href="classpcrepp_1_1Pcre.html#a27">00210</a> <span class="keywordtype">void</span> Pcre::study() {
00211 p_pcre_extra = pcre_study(p_pcre, 0, (<span class="keyword">const</span> <span class="keywordtype">char</span> **)(&err_str));
00212 <span class="keywordflow">if</span>(err_str != NULL)
00213 <span class="keywordflow">throw</span> <a class="code" href="classpcrepp_1_1Pcre_1_1exception.html">exception</a>(<span class="stringliteral">"pcre_study(..) failed: "</span> + string(err_str));
00214 }
00215
00216
00217 <span class="comment">/*</span>
00218 <span class="comment"> * setting current locale</span>
00219 <span class="comment"> */</span>
<a name="l00220"></a><a class="code" href="classpcrepp_1_1Pcre.html#a28">00220</a> <span class="keywordtype">bool</span> Pcre::setlocale(<span class="keyword">const</span> <span class="keywordtype">char</span>* locale) {
00221 <span class="keywordflow">if</span> (std::setlocale(LC_CTYPE, locale) == NULL) <span class="keywordflow">return</span> <span class="keyword">false</span>;
00222 tables = pcre_maketables();
00223 <span class="keywordflow">return</span> <span class="keyword">true</span>;
00224 }
</pre></div><hr><address style="align: right;"><small>Generated on Wed Aug 25 01:38:04 2004 for PCRE++ by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border=0
width=110 height=53></a>1.3-rc3 </small></address>
</body>
</html>
|