1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>Iterating Over the Matches Within An MFC String</title> 5<link rel="stylesheet" href="../../../../../../../../doc/src/boostbook.css" type="text/css"> 6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> 7<link rel="home" href="../../../../index.html" title="Boost.Regex 5.1.4"> 8<link rel="up" href="../mfc_strings.html" title="Using Boost Regex With MFC Strings"> 9<link rel="prev" href="mfc_algo.html" title="Overloaded Algorithms For MFC String Types"> 10<link rel="next" href="../../posix.html" title="POSIX Compatible C API's"> 11</head> 12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> 13<table cellpadding="2" width="100%"><tr> 14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../../boost.png"></td> 15<td align="center"><a href="../../../../../../../../index.html">Home</a></td> 16<td align="center"><a href="../../../../../../../../libs/libraries.htm">Libraries</a></td> 17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> 18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> 19<td align="center"><a href="../../../../../../../../more/index.htm">More</a></td> 20</tr></table> 21<hr> 22<div class="spirit-nav"> 23<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> 24</div> 25<div class="section"> 26<div class="titlepage"><div><div><h5 class="title"> 27<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 28 Over the Matches Within An MFC String</a> 29</h5></div></div></div> 30<p> 31 The following helper functions are provided to ease the conversion from 32 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>: 33 </p> 34<h5> 35<a name="boost_regex.ref.non_std_strings.mfc_strings.mfc_iter.h0"></a> 36 <span class="phrase"><a name="boost_regex.ref.non_std_strings.mfc_strings.mfc_iter.regex_iterator_creation_helper"></a></span><a class="link" href="mfc_iter.html#boost_regex.ref.non_std_strings.mfc_strings.mfc_iter.regex_iterator_creation_helper">regex_iterator 37 creation helper</a> 38 </h5> 39<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">charT</span><span class="special">></span> 40<span class="identifier">regex_iterator</span><span class="special"><</span><span class="identifier">charT</span> <span class="keyword">const</span><span class="special">*></span> 41 <span class="identifier">make_regex_iterator</span><span class="special">(</span> 42 <span class="keyword">const</span> <span class="identifier">ATL</span><span class="special">::</span><span class="identifier">CSimpleStringT</span><span class="special"><</span><span class="identifier">charT</span><span class="special">>&</span> <span class="identifier">s</span><span class="special">,</span> 43 <span class="keyword">const</span> <span class="identifier">basic_regex</span><span class="special"><</span><span class="identifier">charT</span><span class="special">>&</span> <span class="identifier">e</span><span class="special">,</span> 44 <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> 45</pre> 46<p> 47 <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> 48 <span class="identifier">e</span><span class="special">,</span> 49 <span class="identifier">f</span><span class="special">);</span></code> 50 </p> 51<p> 52 <span class="bold"><strong>Example</strong></span>: 53 </p> 54<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">&</span> <span class="identifier">html</span><span class="special">)</span> 55<span class="special">{</span> 56 <span class="comment">// enumerate and print all the links in some HTML text,</span> 57 <span class="comment">// the expression used is by Andew Lee on www.regxlib.com:</span> 58 <span class="identifier">boost</span><span class="special">::</span><span class="identifier">tregex</span> <span class="identifier">r</span><span class="special">(</span> 59 <span class="identifier">__T</span><span class="special">(</span><span class="string">"href=[\"\']((http:\\/\\/|\\.\\/|\\/)?\\w+"</span> 60 <span class="string">"(\\.\\w+)*(\\/\\w+(\\.\\w+)?)*"</span> 61 <span class="string">"(\\/|\\?\\w*=\\w*(&\\w*=\\w*)*)?)[\"\']"</span><span class="special">));</span> 62 <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> 63 <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> 64 <span class="special">{</span> 65 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</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"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 66 <span class="special">++</span><span class="identifier">i</span><span class="special">;</span> 67 <span class="special">}</span> 68<span class="special">}</span> 69</pre> 70<h5> 71<a name="boost_regex.ref.non_std_strings.mfc_strings.mfc_iter.h1"></a> 72 <span class="phrase"><a name="boost_regex.ref.non_std_strings.mfc_strings.mfc_iter.regex_token_iterator_creation_he"></a></span><a class="link" href="mfc_iter.html#boost_regex.ref.non_std_strings.mfc_strings.mfc_iter.regex_token_iterator_creation_he">regex_token_iterator 73 creation helpers</a> 74 </h5> 75<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">charT</span><span class="special">></span> 76<span class="identifier">regex_token_iterator</span><span class="special"><</span><span class="identifier">charT</span> <span class="keyword">const</span><span class="special">*></span> 77 <span class="identifier">make_regex_token_iterator</span><span class="special">(</span> 78 <span class="keyword">const</span> <span class="identifier">ATL</span><span class="special">::</span><span class="identifier">CSimpleStringT</span><span class="special"><</span><span class="identifier">charT</span><span class="special">>&</span> <span class="identifier">s</span><span class="special">,</span> 79 <span class="keyword">const</span> <span class="identifier">basic_regex</span><span class="special"><</span><span class="identifier">charT</span><span class="special">>&</span> <span class="identifier">e</span><span class="special">,</span> 80 <span class="keyword">int</span> <span class="identifier">sub</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span> 81 <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> 82</pre> 83<p> 84 <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> 85 <span class="identifier">e</span><span class="special">,</span> 86 <span class="identifier">sub</span><span class="special">,</span> 87 <span class="identifier">f</span><span class="special">);</span></code> 88 </p> 89<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">charT</span><span class="special">></span> 90<span class="identifier">regex_token_iterator</span><span class="special"><</span><span class="identifier">charT</span> <span class="keyword">const</span><span class="special">*></span> 91 <span class="identifier">make_regex_token_iterator</span><span class="special">(</span> 92 <span class="keyword">const</span> <span class="identifier">ATL</span><span class="special">::</span><span class="identifier">CSimpleStringT</span><span class="special"><</span><span class="identifier">charT</span><span class="special">>&</span> <span class="identifier">s</span><span class="special">,</span> 93 <span class="keyword">const</span> <span class="identifier">basic_regex</span><span class="special"><</span><span class="identifier">charT</span><span class="special">>&</span> <span class="identifier">e</span><span class="special">,</span> 94 <span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span><span class="keyword">int</span><span class="special">>&</span> <span class="identifier">subs</span><span class="special">,</span> 95 <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> 96</pre> 97<p> 98 <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> 99 <span class="identifier">e</span><span class="special">,</span> 100 <span class="identifier">subs</span><span class="special">,</span> 101 <span class="identifier">f</span><span class="special">);</span></code> 102 </p> 103<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</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">></span> 104<span class="identifier">regex_token_iterator</span><span class="special"><</span><span class="identifier">charT</span> <span class="keyword">const</span><span class="special">*></span> 105 <span class="identifier">make_regex_token_iterator</span><span class="special">(</span> 106 <span class="keyword">const</span> <span class="identifier">ATL</span><span class="special">::</span><span class="identifier">CSimpleStringT</span><span class="special"><</span><span class="identifier">charT</span><span class="special">>&</span> <span class="identifier">s</span><span class="special">,</span> 107 <span class="keyword">const</span> <span class="identifier">basic_regex</span><span class="special"><</span><span class="identifier">charT</span><span class="special">>&</span> <span class="identifier">e</span><span class="special">,</span> 108 <span class="keyword">const</span> <span class="keyword">int</span> <span class="special">(&</span> <span class="identifier">subs</span><span class="special">)[</span><span class="identifier">N</span><span class="special">],</span> 109 <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> 110</pre> 111<p> 112 <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> 113 <span class="identifier">e</span><span class="special">,</span> 114 <span class="identifier">subs</span><span class="special">,</span> 115 <span class="identifier">f</span><span class="special">);</span></code> 116 </p> 117<p> 118 <span class="bold"><strong>Example</strong></span>: 119 </p> 120<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">&</span> <span class="identifier">html</span><span class="special">)</span> 121<span class="special">{</span> 122 <span class="comment">// enumerate and print all the links in some HTML text,</span> 123 <span class="comment">// the expression used is by Andew Lee on www.regxlib.com:</span> 124 <span class="identifier">boost</span><span class="special">::</span><span class="identifier">tregex</span> <span class="identifier">r</span><span class="special">(</span> 125 <span class="identifier">__T</span><span class="special">(</span><span class="string">"href=[\"\']((http:\\/\\/|\\.\\/|\\/)?\\w+"</span> 126 <span class="string">"(\\.\\w+)*(\\/\\w+(\\.\\w+)?)*"</span> 127 <span class="string">"(\\/|\\?\\w*=\\w*(&\\w*=\\w*)*)?)[\"\']"</span><span class="special">));</span> 128 <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> 129 <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> 130 <span class="special">{</span> 131 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="special">*</span><span class="identifier">i</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> 132 <span class="special">++</span><span class="identifier">i</span><span class="special">;</span> 133 <span class="special">}</span> 134<span class="special">}</span> 135</pre> 136</div> 137<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 138<td align="left"></td> 139<td align="right"><div class="copyright-footer">Copyright © 1998-2013 John Maddock<p> 140 Distributed under the Boost Software License, Version 1.0. (See accompanying 141 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>) 142 </p> 143</div></td> 144</tr></table> 145<hr> 146<div class="spirit-nav"> 147<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> 148</div> 149</body> 150</html> 151