<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Iterating Over the Matches Within An MFC String</title>
<link rel="stylesheet" href="../../../../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.74.0">
<link rel="home" href="../../../../index.html" title="Boost.Regex">
<link rel="up" href="../mfc_strings.html" title="Using Boost Regex With MFC Strings">
<link rel="prev" href="mfc_algo.html" title="Overloaded Algorithms For MFC String Types">
<link rel="next" href="../../posix.html" title="POSIX Compatible C API's">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="mfc_algo.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../mfc_strings.html"><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="../../posix.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section" lang="en">
<div class="titlepage"><div><div><h5 class="title">
<a name="boost_regex.ref.non_std_strings.mfc_strings.mfc_iter"></a><a class="link" href="mfc_iter.html" title="Iterating Over the Matches Within An MFC String">Iterating
          Over the Matches Within An MFC String</a>
</h5></div></div></div>
<p>
            The following helper functions are provided to ease the conversion from
            an MFC/ATL string to a <a class="link" href="../../regex_iterator.html" title="regex_iterator"><code class="computeroutput"><span class="identifier">regex_iterator</span></code></a> or <a class="link" href="../../regex_token_iterator.html" title="regex_token_iterator"><code class="computeroutput"><span class="identifier">regex_token_iterator</span></code></a>:
          </p>
<a name="boost_regex.ref.non_std_strings.mfc_strings.mfc_iter.regex_iterator_creation_helper"></a><h5>
<a name="id1108946"></a>
            <a class="link" href="mfc_iter.html#boost_regex.ref.non_std_strings.mfc_strings.mfc_iter.regex_iterator_creation_helper">regex_iterator
            creation helper</a>
          </h5>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">charT</span><span class="special">&gt;</span>
<span class="identifier">regex_iterator</span><span class="special">&lt;</span><span class="identifier">charT</span> <span class="keyword">const</span><span class="special">*&gt;</span> 
   <span class="identifier">make_regex_iterator</span><span class="special">(</span>
      <span class="keyword">const</span> <span class="identifier">ATL</span><span class="special">::</span><span class="identifier">CSimpleStringT</span><span class="special">&lt;</span><span class="identifier">charT</span><span class="special">&gt;&amp;</span> <span class="identifier">s</span><span class="special">,</span> 
      <span class="keyword">const</span> <span class="identifier">basic_regex</span><span class="special">&lt;</span><span class="identifier">charT</span><span class="special">&gt;&amp;</span> <span class="identifier">e</span><span class="special">,</span> 
      <span class="special">::</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">regex_constants</span><span class="special">::</span><span class="identifier">match_flag_type</span> <span class="identifier">f</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">regex_constants</span><span class="special">::</span><span class="identifier">match_default</span><span class="special">);</span>
</pre>
<p>
            <span class="bold"><strong>Effects</strong></span>: returns <code class="computeroutput"><span class="identifier">regex_iterator</span><span class="special">(</span><span class="identifier">s</span><span class="special">.</span><span class="identifier">GetString</span><span class="special">(),</span> <span class="identifier">s</span><span class="special">.</span><span class="identifier">GetString</span><span class="special">()</span> <span class="special">+</span> <span class="identifier">s</span><span class="special">.</span><span class="identifier">GetLength</span><span class="special">(),</span>
            <span class="identifier">e</span><span class="special">,</span>
            <span class="identifier">f</span><span class="special">);</span></code>
          </p>
<p>
            <span class="bold"><strong>Example</strong></span>:
          </p>
<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">enumerate_links</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">CString</span><span class="special">&amp;</span> <span class="identifier">html</span><span class="special">)</span>
<span class="special">{</span>
   <span class="comment">// enumerate and print all the  links in some HTML text,
</span>   <span class="comment">// the expression used is by Andew Lee on www.regxlib.com:
</span>   <span class="identifier">boost</span><span class="special">::</span><span class="identifier">tregex</span> <span class="identifier">r</span><span class="special">(</span>
      <span class="identifier">__T</span><span class="special">(</span><span class="string">"href=[\"\']((http:\\/\\/|\\.\\/|\\/)?\\w+"</span>
          <span class="string">"(\\.\\w+)*(\\/\\w+(\\.\\w+)?)*"</span>
          <span class="string">"(\\/|\\?\\w*=\\w*(&amp;\\w*=\\w*)*)?)[\"\']"</span><span class="special">));</span>
   <span class="identifier">boost</span><span class="special">::</span><span class="identifier">tregex_iterator</span> <span class="identifier">i</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">make_regex_iterator</span><span class="special">(</span><span class="identifier">html</span><span class="special">,</span> <span class="identifier">r</span><span class="special">)),</span> <span class="identifier">j</span><span class="special">;</span>
   <span class="keyword">while</span><span class="special">(</span><span class="identifier">i</span> <span class="special">!=</span> <span class="identifier">j</span><span class="special">)</span>
   <span class="special">{</span>
      <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="special">(*</span><span class="identifier">i</span><span class="special">)[</span><span class="number">1</span><span class="special">]</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
      <span class="special">++</span><span class="identifier">i</span><span class="special">;</span>
   <span class="special">}</span>
<span class="special">}</span>
</pre>
<a name="boost_regex.ref.non_std_strings.mfc_strings.mfc_iter.regex_token_iterator_creation_helpers"></a><h5>
<a name="id1109494"></a>
            <a class="link" href="mfc_iter.html#boost_regex.ref.non_std_strings.mfc_strings.mfc_iter.regex_token_iterator_creation_helpers">regex_token_iterator
            creation helpers</a>
          </h5>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">charT</span><span class="special">&gt;</span> 
<span class="identifier">regex_token_iterator</span><span class="special">&lt;</span><span class="identifier">charT</span> <span class="keyword">const</span><span class="special">*&gt;</span> 
   <span class="identifier">make_regex_token_iterator</span><span class="special">(</span>
      <span class="keyword">const</span> <span class="identifier">ATL</span><span class="special">::</span><span class="identifier">CSimpleStringT</span><span class="special">&lt;</span><span class="identifier">charT</span><span class="special">&gt;&amp;</span> <span class="identifier">s</span><span class="special">,</span> 
      <span class="keyword">const</span> <span class="identifier">basic_regex</span><span class="special">&lt;</span><span class="identifier">charT</span><span class="special">&gt;&amp;</span> <span class="identifier">e</span><span class="special">,</span> 
      <span class="keyword">int</span> <span class="identifier">sub</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span> 
      <span class="special">::</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">regex_constants</span><span class="special">::</span><span class="identifier">match_flag_type</span> <span class="identifier">f</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">regex_constants</span><span class="special">::</span><span class="identifier">match_default</span><span class="special">);</span>
</pre>
<p>
            <span class="bold"><strong>Effects</strong></span>: returns <code class="computeroutput"><span class="identifier">regex_token_iterator</span><span class="special">(</span><span class="identifier">s</span><span class="special">.</span><span class="identifier">GetString</span><span class="special">(),</span> <span class="identifier">s</span><span class="special">.</span><span class="identifier">GetString</span><span class="special">()</span> <span class="special">+</span> <span class="identifier">s</span><span class="special">.</span><span class="identifier">GetLength</span><span class="special">(),</span>
            <span class="identifier">e</span><span class="special">,</span>
            <span class="identifier">sub</span><span class="special">,</span>
            <span class="identifier">f</span><span class="special">);</span></code>
          </p>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">charT</span><span class="special">&gt;</span> 
<span class="identifier">regex_token_iterator</span><span class="special">&lt;</span><span class="identifier">charT</span> <span class="keyword">const</span><span class="special">*&gt;</span> 
   <span class="identifier">make_regex_token_iterator</span><span class="special">(</span>
      <span class="keyword">const</span> <span class="identifier">ATL</span><span class="special">::</span><span class="identifier">CSimpleStringT</span><span class="special">&lt;</span><span class="identifier">charT</span><span class="special">&gt;&amp;</span> <span class="identifier">s</span><span class="special">,</span> 
      <span class="keyword">const</span> <span class="identifier">basic_regex</span><span class="special">&lt;</span><span class="identifier">charT</span><span class="special">&gt;&amp;</span> <span class="identifier">e</span><span class="special">,</span> 
      <span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;&amp;</span> <span class="identifier">subs</span><span class="special">,</span> 
      <span class="special">::</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">regex_constants</span><span class="special">::</span><span class="identifier">match_flag_type</span> <span class="identifier">f</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">regex_constants</span><span class="special">::</span><span class="identifier">match_default</span><span class="special">);</span>
</pre>
<p>
            <span class="bold"><strong>Effects</strong></span>: returns <code class="computeroutput"><span class="identifier">regex_token_iterator</span><span class="special">(</span><span class="identifier">s</span><span class="special">.</span><span class="identifier">GetString</span><span class="special">(),</span> <span class="identifier">s</span><span class="special">.</span><span class="identifier">GetString</span><span class="special">()</span> <span class="special">+</span> <span class="identifier">s</span><span class="special">.</span><span class="identifier">GetLength</span><span class="special">(),</span>
            <span class="identifier">e</span><span class="special">,</span>
            <span class="identifier">subs</span><span class="special">,</span>
            <span class="identifier">f</span><span class="special">);</span></code>
          </p>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">charT</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">N</span><span class="special">&gt;</span> 
<span class="identifier">regex_token_iterator</span><span class="special">&lt;</span><span class="identifier">charT</span> <span class="keyword">const</span><span class="special">*&gt;</span> 
   <span class="identifier">make_regex_token_iterator</span><span class="special">(</span>
      <span class="keyword">const</span> <span class="identifier">ATL</span><span class="special">::</span><span class="identifier">CSimpleStringT</span><span class="special">&lt;</span><span class="identifier">charT</span><span class="special">&gt;&amp;</span> <span class="identifier">s</span><span class="special">,</span> 
      <span class="keyword">const</span> <span class="identifier">basic_regex</span><span class="special">&lt;</span><span class="identifier">charT</span><span class="special">&gt;&amp;</span> <span class="identifier">e</span><span class="special">,</span> 
      <span class="keyword">const</span> <span class="keyword">int</span> <span class="special">(&amp;</span> <span class="identifier">subs</span><span class="special">)[</span><span class="identifier">N</span><span class="special">],</span> 
      <span class="special">::</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">regex_constants</span><span class="special">::</span><span class="identifier">match_flag_type</span> <span class="identifier">f</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">regex_constants</span><span class="special">::</span><span class="identifier">match_default</span><span class="special">);</span>
</pre>
<p>
            <span class="bold"><strong>Effects</strong></span>: returns <code class="computeroutput"><span class="identifier">regex_token_iterator</span><span class="special">(</span><span class="identifier">s</span><span class="special">.</span><span class="identifier">GetString</span><span class="special">(),</span> <span class="identifier">s</span><span class="special">.</span><span class="identifier">GetString</span><span class="special">()</span> <span class="special">+</span> <span class="identifier">s</span><span class="special">.</span><span class="identifier">GetLength</span><span class="special">(),</span>
            <span class="identifier">e</span><span class="special">,</span>
            <span class="identifier">subs</span><span class="special">,</span>
            <span class="identifier">f</span><span class="special">);</span></code>
          </p>
<p>
            <span class="bold"><strong>Example</strong></span>:
          </p>
<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">enumerate_links2</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">CString</span><span class="special">&amp;</span> <span class="identifier">html</span><span class="special">)</span>
<span class="special">{</span>
   <span class="comment">// enumerate and print all the  links in some HTML text,
</span>   <span class="comment">// the expression used is by Andew Lee on www.regxlib.com:
</span>   <span class="identifier">boost</span><span class="special">::</span><span class="identifier">tregex</span> <span class="identifier">r</span><span class="special">(</span>
         <span class="identifier">__T</span><span class="special">(</span><span class="string">"href=[\"\']((http:\\/\\/|\\.\\/|\\/)?\\w+"</span>
             <span class="string">"(\\.\\w+)*(\\/\\w+(\\.\\w+)?)*"</span>
             <span class="string">"(\\/|\\?\\w*=\\w*(&amp;\\w*=\\w*)*)?)[\"\']"</span><span class="special">));</span>
   <span class="identifier">boost</span><span class="special">::</span><span class="identifier">tregex_token_iterator</span> <span class="identifier">i</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">make_regex_token_iterator</span><span class="special">(</span><span class="identifier">html</span><span class="special">,</span> <span class="identifier">r</span><span class="special">,</span> <span class="number">1</span><span class="special">)),</span> <span class="identifier">j</span><span class="special">;</span>
   <span class="keyword">while</span><span class="special">(</span><span class="identifier">i</span> <span class="special">!=</span> <span class="identifier">j</span><span class="special">)</span>
   <span class="special">{</span>
      <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="special">*</span><span class="identifier">i</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
      <span class="special">++</span><span class="identifier">i</span><span class="special">;</span>
   <span class="special">}</span>
<span class="special">}</span>      
</pre>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 1998 -2010 John Maddock<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        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>)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="mfc_algo.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../mfc_strings.html"><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="../../posix.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
