1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 2<html> 3<head> 4<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 5<title>Struct template regex_compiler</title> 6<link rel="stylesheet" href="../../../../doc/src/boostbook.css" type="text/css"> 7<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> 8<link rel="home" href="../../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset"> 9<link rel="up" href="../../xpressive/reference.html#header.boost.xpressive.xpressive_fwd_hpp" title="Header <boost/xpressive/xpressive_fwd.hpp>"> 10<link rel="prev" href="reference.html" title="Struct template reference"> 11<link rel="next" href="regex_id_filter_predicate.html" title="Struct template regex_id_filter_predicate"> 12</head> 13<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> 14<table cellpadding="2" width="100%"><tr> 15<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../boost.png"></td> 16<td align="center"><a href="../../../../index.html">Home</a></td> 17<td align="center"><a href="../../../../libs/libraries.htm">Libraries</a></td> 18<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> 19<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> 20<td align="center"><a href="../../../../more/index.htm">More</a></td> 21</tr></table> 22<hr> 23<div class="spirit-nav"> 24<a accesskey="p" href="reference.html"><img src="../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../xpressive/reference.html#header.boost.xpressive.xpressive_fwd_hpp"><img src="../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="regex_id_filter_predicate.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a> 25</div> 26<div class="refentry"> 27<a name="boost.xpressive.regex_compiler"></a><div class="titlepage"></div> 28<div class="refnamediv"> 29<h2><span class="refentrytitle">Struct template regex_compiler</span></h2> 30<p>boost::xpressive::regex_compiler — Class template <a class="link" href="regex_compiler.html" title="Struct template regex_compiler">regex_compiler</a> is a factory for building <a class="link" href="basic_regex.html" title="Struct template basic_regex">basic_regex</a> objects from a string. </p> 31</div> 32<h2 xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv-title">Synopsis</h2> 33<div xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv"><pre class="synopsis"><span class="comment">// In header: <<a class="link" href="../../xpressive/reference.html#header.boost.xpressive.xpressive_fwd_hpp" title="Header <boost/xpressive/xpressive_fwd.hpp>">boost/xpressive/xpressive_fwd.hpp</a>> 34 35</span><span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> BidiIter<span class="special">,</span> <span class="keyword">typename</span> RegexTraits<span class="special">,</span> <span class="keyword">typename</span> CompilerTraits<span class="special">></span> 36<span class="keyword">struct</span> <a class="link" href="regex_compiler.html" title="Struct template regex_compiler">regex_compiler</a> <span class="special">{</span> 37 <span class="comment">// <a class="link" href="regex_compiler.html#boost.xpressive.regex_compilerconstruct-copy-destruct">construct/copy/destruct</a></span> 38 <span class="keyword">explicit</span> <a class="link" href="regex_compiler.html#id-1_3_47_5_18_2_1_11_5-bb"><span class="identifier">regex_compiler</span></a><span class="special">(</span><span class="identifier">RegexTraits</span> <span class="keyword">const</span> <span class="special">&</span> <span class="special">=</span> <span class="identifier">RegexTraits</span><span class="special">(</span><span class="special">)</span><span class="special">)</span><span class="special">;</span> 39 40 <span class="comment">// <a class="link" href="regex_compiler.html#id-1_3_47_5_18_2_1_11_4-bb">public member functions</a></span> 41 <span class="identifier">locale_type</span> <a class="link" href="regex_compiler.html#id-1_3_47_5_18_2_1_11_4_1-bb"><span class="identifier">imbue</span></a><span class="special">(</span><span class="identifier">locale_type</span><span class="special">)</span><span class="special">;</span> 42 <span class="identifier">locale_type</span> <a class="link" href="regex_compiler.html#id-1_3_47_5_18_2_1_11_4_2-bb"><span class="identifier">getloc</span></a><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span> 43 <span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> InputIter<span class="special">></span> 44 <a class="link" href="basic_regex.html" title="Struct template basic_regex">basic_regex</a><span class="special"><</span> <span class="identifier">BidiIter</span> <span class="special">></span> 45 <a class="link" href="regex_compiler.html#id-1_3_47_5_18_2_1_11_4_3-bb"><span class="identifier">compile</span></a><span class="special">(</span><span class="identifier">InputIter</span><span class="special">,</span> <span class="identifier">InputIter</span><span class="special">,</span> <span class="identifier">flag_type</span> <span class="special">=</span> <span class="identifier">regex_constants</span><span class="special">::</span><span class="identifier">ECMAScript</span><span class="special">)</span><span class="special">;</span> 46 <span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> InputRange<span class="special">></span> 47 <span class="identifier">disable_if</span><span class="special"><</span> <span class="identifier">is_pointer</span><span class="special"><</span> <span class="identifier">InputRange</span> <span class="special">></span><span class="special">,</span> <a class="link" href="basic_regex.html" title="Struct template basic_regex">basic_regex</a><span class="special"><</span> <span class="identifier">BidiIter</span> <span class="special">></span> <span class="special">></span><span class="special">::</span><span class="identifier">type</span> 48 <a class="link" href="regex_compiler.html#id-1_3_47_5_18_2_1_11_4_4-bb"><span class="identifier">compile</span></a><span class="special">(</span><span class="identifier">InputRange</span> <span class="keyword">const</span> <span class="special">&</span><span class="special">,</span> <span class="identifier">flag_type</span> <span class="special">=</span> <span class="identifier">regex_constants</span><span class="special">::</span><span class="identifier">ECMAScript</span><span class="special">)</span><span class="special">;</span> 49 <a class="link" href="basic_regex.html" title="Struct template basic_regex">basic_regex</a><span class="special"><</span> <span class="identifier">BidiIter</span> <span class="special">></span> 50 <a class="link" href="regex_compiler.html#id-1_3_47_5_18_2_1_11_4_5-bb"><span class="identifier">compile</span></a><span class="special">(</span><span class="identifier">char_type</span> <span class="keyword">const</span> <span class="special">*</span><span class="special">,</span> <span class="identifier">flag_type</span> <span class="special">=</span> <span class="identifier">regex_constants</span><span class="special">::</span><span class="identifier">ECMAScript</span><span class="special">)</span><span class="special">;</span> 51 <a class="link" href="basic_regex.html" title="Struct template basic_regex">basic_regex</a><span class="special"><</span> <span class="identifier">BidiIter</span> <span class="special">></span> <a class="link" href="regex_compiler.html#id-1_3_47_5_18_2_1_11_4_6-bb"><span class="identifier">compile</span></a><span class="special">(</span><span class="identifier">char_type</span> <span class="keyword">const</span> <span class="special">*</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span><span class="special">,</span> <span class="identifier">flag_type</span><span class="special">)</span><span class="special">;</span> 52 <a class="link" href="basic_regex.html" title="Struct template basic_regex">basic_regex</a><span class="special"><</span> <span class="identifier">BidiIter</span> <span class="special">></span> <span class="special">&</span> <a class="link" href="regex_compiler.html#id-1_3_47_5_18_2_1_11_4_7-bb"><span class="keyword">operator</span> <span class="special">[</span><span class="special">]</span></a><span class="special">(</span><span class="identifier">string_type</span> <span class="keyword">const</span> <span class="special">&</span><span class="special">)</span><span class="special">;</span> 53 <a class="link" href="basic_regex.html" title="Struct template basic_regex">basic_regex</a><span class="special"><</span> <span class="identifier">BidiIter</span> <span class="special">></span> <span class="keyword">const</span> <span class="special">&</span> <a class="link" href="regex_compiler.html#id-1_3_47_5_18_2_1_11_4_8-bb"><span class="keyword">operator</span> <span class="special">[</span><span class="special">]</span></a><span class="special">(</span><span class="identifier">string_type</span> <span class="keyword">const</span> <span class="special">&</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span> 54 55 <span class="comment">// <a class="link" href="regex_compiler.html#id-1_3_47_5_18_2_1_11_6-bb">private member functions</a></span> 56 <span class="keyword">bool</span> <a class="link" href="regex_compiler.html#id-1_3_47_5_18_2_1_11_6_1-bb"><span class="identifier">is_upper_</span></a><span class="special">(</span><span class="identifier">char_type</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span> 57<span class="special">}</span><span class="special">;</span></pre></div> 58<div class="refsect1"> 59<a name="id-1.3.47.5.19.21.4"></a><h2>Description</h2> 60<p>Class template <a class="link" href="regex_compiler.html" title="Struct template regex_compiler">regex_compiler</a> is used to construct a <a class="link" href="basic_regex.html" title="Struct template basic_regex">basic_regex</a> object from a string. The string should contain a valid regular expression. You can imbue a <a class="link" href="regex_compiler.html" title="Struct template regex_compiler">regex_compiler</a> object with a locale, after which all <a class="link" href="basic_regex.html" title="Struct template basic_regex">basic_regex</a> objects created with that <a class="link" href="regex_compiler.html" title="Struct template regex_compiler">regex_compiler</a> object will use that locale. After creating a <a class="link" href="regex_compiler.html" title="Struct template regex_compiler">regex_compiler</a> object, and optionally imbueing it with a locale, you can call the compile() method to construct a <a class="link" href="basic_regex.html" title="Struct template basic_regex">basic_regex</a> object, passing it the string representing the regular expression. You can call compile() multiple times on the same <a class="link" href="regex_compiler.html" title="Struct template regex_compiler">regex_compiler</a> object. Two <a class="link" href="basic_regex.html" title="Struct template basic_regex">basic_regex</a> objects compiled from the same string will have different regex_id's. </p> 61<div class="refsect2"> 62<a name="id-1.3.47.5.19.21.4.3"></a><h3> 63<a name="boost.xpressive.regex_compilerconstruct-copy-destruct"></a><code class="computeroutput">regex_compiler</code> 64 public 65 construct/copy/destruct</h3> 66<div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem"><pre class="literallayout"><span class="keyword">explicit</span> <a name="id-1_3_47_5_18_2_1_11_5-bb"></a><span class="identifier">regex_compiler</span><span class="special">(</span><span class="identifier">RegexTraits</span> <span class="keyword">const</span> <span class="special">&</span> traits <span class="special">=</span> <span class="identifier">RegexTraits</span><span class="special">(</span><span class="special">)</span><span class="special">)</span><span class="special">;</span></pre></li></ol></div> 67</div> 68<div class="refsect2"> 69<a name="id-1.3.47.5.19.21.4.4"></a><h3> 70<a name="id-1_3_47_5_18_2_1_11_4-bb"></a><code class="computeroutput">regex_compiler</code> public member functions</h3> 71<div class="orderedlist"><ol class="orderedlist" type="1"> 72<li class="listitem"> 73<pre class="literallayout"><span class="identifier">locale_type</span> <a name="id-1_3_47_5_18_2_1_11_4_1-bb"></a><span class="identifier">imbue</span><span class="special">(</span><span class="identifier">locale_type</span> loc<span class="special">)</span><span class="special">;</span></pre> 74<p>Specify the locale to be used by a <code class="computeroutput"><a class="link" href="regex_compiler.html" title="Struct template regex_compiler">regex_compiler</a></code>.</p> 75<p> 76 77</p> 78<div class="variablelist"><table border="0" class="variablelist compact"> 79<colgroup> 80<col align="left" valign="top"> 81<col> 82</colgroup> 83<tbody> 84<tr> 85<td><p><span class="term">Parameters:</span></p></td> 86<td><div class="variablelist"><table border="0" class="variablelist compact"> 87<colgroup> 88<col align="left" valign="top"> 89<col> 90</colgroup> 91<tbody><tr> 92<td><p><span class="term"><code class="computeroutput">loc</code></span></p></td> 93<td><p>The locale that this <code class="computeroutput"><a class="link" href="regex_compiler.html" title="Struct template regex_compiler">regex_compiler</a></code> should use. </p></td> 94</tr></tbody> 95</table></div></td> 96</tr> 97<tr> 98<td><p><span class="term">Returns:</span></p></td> 99<td><p>The previous locale. </p></td> 100</tr> 101</tbody> 102</table></div> 103</li> 104<li class="listitem"> 105<pre class="literallayout"><span class="identifier">locale_type</span> <a name="id-1_3_47_5_18_2_1_11_4_2-bb"></a><span class="identifier">getloc</span><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre> 106<p>Get the locale used by a <code class="computeroutput"><a class="link" href="regex_compiler.html" title="Struct template regex_compiler">regex_compiler</a></code>.</p> 107<p> 108</p> 109<div class="variablelist"><table border="0" class="variablelist compact"> 110<colgroup> 111<col align="left" valign="top"> 112<col> 113</colgroup> 114<tbody><tr> 115<td><p><span class="term">Returns:</span></p></td> 116<td><p>The locale used by this <a class="link" href="regex_compiler.html" title="Struct template regex_compiler">regex_compiler</a>. </p></td> 117</tr></tbody> 118</table></div> 119</li> 120<li class="listitem"> 121<pre class="literallayout"><span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> InputIter<span class="special">></span> 122 <a class="link" href="basic_regex.html" title="Struct template basic_regex">basic_regex</a><span class="special"><</span> <span class="identifier">BidiIter</span> <span class="special">></span> 123 <a name="id-1_3_47_5_18_2_1_11_4_3-bb"></a><span class="identifier">compile</span><span class="special">(</span><span class="identifier">InputIter</span> begin<span class="special">,</span> <span class="identifier">InputIter</span> end<span class="special">,</span> 124 <span class="identifier">flag_type</span> flags <span class="special">=</span> <span class="identifier">regex_constants</span><span class="special">::</span><span class="identifier">ECMAScript</span><span class="special">)</span><span class="special">;</span></pre> 125<p>Builds a <code class="computeroutput"><a class="link" href="basic_regex.html" title="Struct template basic_regex">basic_regex</a></code> object from a range of characters.</p> 126<p> 127 128 129 130 131 132</p> 133<div class="variablelist"><table border="0" class="variablelist compact"> 134<colgroup> 135<col align="left" valign="top"> 136<col> 137</colgroup> 138<tbody> 139<tr> 140<td><p><span class="term">Parameters:</span></p></td> 141<td><div class="variablelist"><table border="0" class="variablelist compact"> 142<colgroup> 143<col align="left" valign="top"> 144<col> 145</colgroup> 146<tbody> 147<tr> 148<td><p><span class="term"><code class="computeroutput">begin</code></span></p></td> 149<td><p>The beginning of a range of characters representing the regular expression to compile. </p></td> 150</tr> 151<tr> 152<td><p><span class="term"><code class="computeroutput">end</code></span></p></td> 153<td><p>The end of a range of characters representing the regular expression to compile. </p></td> 154</tr> 155<tr> 156<td><p><span class="term"><code class="computeroutput">flags</code></span></p></td> 157<td><p>Optional bitmask that determines how the pat string is interpreted. (See syntax_option_type.) </p></td> 158</tr> 159</tbody> 160</table></div></td> 161</tr> 162<tr> 163<td><p><span class="term">Requires:</span></p></td> 164<td><p>InputIter is a model of the InputIterator concept. </p></td> 165</tr> 166<tr> 167<td><p><span class="term">Requires:</span></p></td> 168<td><p>[begin,end) is a valid range. </p></td> 169</tr> 170<tr> 171<td><p><span class="term">Requires:</span></p></td> 172<td><p>The range of characters specified by [begin,end) contains a valid string-based representation of a regular expression. </p></td> 173</tr> 174<tr> 175<td><p><span class="term">Returns:</span></p></td> 176<td><p>A <a class="link" href="basic_regex.html" title="Struct template basic_regex">basic_regex</a> object corresponding to the regular expression represented by the character range. </p></td> 177</tr> 178<tr> 179<td><p><span class="term">Throws:</span></p></td> 180<td> 181<a class="link" href="regex_error.html" title="Struct regex_error">regex_error</a> when the range of characters has invalid regular expression syntax. </td> 182</tr> 183</tbody> 184</table></div> 185</li> 186<li class="listitem"> 187<pre class="literallayout"><span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> InputRange<span class="special">></span> 188 <span class="identifier">disable_if</span><span class="special"><</span> <span class="identifier">is_pointer</span><span class="special"><</span> <span class="identifier">InputRange</span> <span class="special">></span><span class="special">,</span> <a class="link" href="basic_regex.html" title="Struct template basic_regex">basic_regex</a><span class="special"><</span> <span class="identifier">BidiIter</span> <span class="special">></span> <span class="special">></span><span class="special">::</span><span class="identifier">type</span> 189 <a name="id-1_3_47_5_18_2_1_11_4_4-bb"></a><span class="identifier">compile</span><span class="special">(</span><span class="identifier">InputRange</span> <span class="keyword">const</span> <span class="special">&</span> pat<span class="special">,</span> 190 <span class="identifier">flag_type</span> flags <span class="special">=</span> <span class="identifier">regex_constants</span><span class="special">::</span><span class="identifier">ECMAScript</span><span class="special">)</span><span class="special">;</span></pre> 191<p>This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. </p> 192</li> 193<li class="listitem"> 194<pre class="literallayout"><a class="link" href="basic_regex.html" title="Struct template basic_regex">basic_regex</a><span class="special"><</span> <span class="identifier">BidiIter</span> <span class="special">></span> 195<a name="id-1_3_47_5_18_2_1_11_4_5-bb"></a><span class="identifier">compile</span><span class="special">(</span><span class="identifier">char_type</span> <span class="keyword">const</span> <span class="special">*</span> begin<span class="special">,</span> 196 <span class="identifier">flag_type</span> flags <span class="special">=</span> <span class="identifier">regex_constants</span><span class="special">::</span><span class="identifier">ECMAScript</span><span class="special">)</span><span class="special">;</span></pre> 197<p>This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. </p> 198</li> 199<li class="listitem"> 200<pre class="literallayout"><a class="link" href="basic_regex.html" title="Struct template basic_regex">basic_regex</a><span class="special"><</span> <span class="identifier">BidiIter</span> <span class="special">></span> 201<a name="id-1_3_47_5_18_2_1_11_4_6-bb"></a><span class="identifier">compile</span><span class="special">(</span><span class="identifier">char_type</span> <span class="keyword">const</span> <span class="special">*</span> begin<span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> size<span class="special">,</span> <span class="identifier">flag_type</span> flags<span class="special">)</span><span class="special">;</span></pre> 202<p>This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. </p> 203</li> 204<li class="listitem"> 205<pre class="literallayout"><a class="link" href="basic_regex.html" title="Struct template basic_regex">basic_regex</a><span class="special"><</span> <span class="identifier">BidiIter</span> <span class="special">></span> <span class="special">&</span> <a name="id-1_3_47_5_18_2_1_11_4_7-bb"></a><span class="keyword">operator</span> <span class="special">[</span><span class="special">]</span><span class="special">(</span><span class="identifier">string_type</span> <span class="keyword">const</span> <span class="special">&</span> name<span class="special">)</span><span class="special">;</span></pre> 206<p>Return a reference to the named regular expression. If no such named regular expression exists, create a new regular expression and return a reference to it.</p> 207<p> 208 209 210</p> 211<div class="variablelist"><table border="0" class="variablelist compact"> 212<colgroup> 213<col align="left" valign="top"> 214<col> 215</colgroup> 216<tbody> 217<tr> 218<td><p><span class="term">Parameters:</span></p></td> 219<td><div class="variablelist"><table border="0" class="variablelist compact"> 220<colgroup> 221<col align="left" valign="top"> 222<col> 223</colgroup> 224<tbody><tr> 225<td><p><span class="term"><code class="computeroutput">name</code></span></p></td> 226<td><p>A std::string containing the name of the regular expression. </p></td> 227</tr></tbody> 228</table></div></td> 229</tr> 230<tr> 231<td><p><span class="term">Requires:</span></p></td> 232<td><p>The string is not empty. </p></td> 233</tr> 234<tr> 235<td><p><span class="term">Throws:</span></p></td> 236<td>bad_alloc on allocation failure. </td> 237</tr> 238</tbody> 239</table></div> 240</li> 241<li class="listitem"> 242<pre class="literallayout"><a class="link" href="basic_regex.html" title="Struct template basic_regex">basic_regex</a><span class="special"><</span> <span class="identifier">BidiIter</span> <span class="special">></span> <span class="keyword">const</span> <span class="special">&</span> <a name="id-1_3_47_5_18_2_1_11_4_8-bb"></a><span class="keyword">operator</span> <span class="special">[</span><span class="special">]</span><span class="special">(</span><span class="identifier">string_type</span> <span class="keyword">const</span> <span class="special">&</span> name<span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre> 243<p>This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. </p> 244</li> 245</ol></div> 246</div> 247<div class="refsect2"> 248<a name="id-1.3.47.5.19.21.4.5"></a><h3> 249<a name="id-1_3_47_5_18_2_1_11_6-bb"></a><code class="computeroutput">regex_compiler</code> private member functions</h3> 250<div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem"><pre class="literallayout"><span class="keyword">bool</span> <a name="id-1_3_47_5_18_2_1_11_6_1-bb"></a><span class="identifier">is_upper_</span><span class="special">(</span><span class="identifier">char_type</span> ch<span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre></li></ol></div> 251</div> 252</div> 253</div> 254<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 255<td align="left"></td> 256<td align="right"><div class="copyright-footer">Copyright © 2007 Eric Niebler<p> 257 Distributed under the Boost Software License, Version 1.0. (See accompanying 258 file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>) 259 </p> 260</div></td> 261</tr></table> 262<hr> 263<div class="spirit-nav"> 264<a accesskey="p" href="reference.html"><img src="../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../xpressive/reference.html#header.boost.xpressive.xpressive_fwd_hpp"><img src="../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="regex_id_filter_predicate.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a> 265</div> 266</body> 267</html> 268