<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <meta http-equiv="X-UA-Compatible" content="IE=9"/> <title>edelib: Regex Class Reference</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <link href="doxygen.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="top"><!-- do not remove this div! --> <div id="titlearea"> <table cellspacing="0" cellpadding="0"> <tbody> <tr style="height: 56px;"> <td style="padding-left: 0.5em;"> <div id="projectname">edelib  <span id="projectnumber">2.0.0</span> </div> </td> </tr> </tbody> </table> </div> <!-- Generated by Doxygen 1.7.6.1 --> <div id="navrow1" class="tabs"> <ul class="tablist"> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="pages.html"><span>Related Pages</span></a></li> <li><a href="modules.html"><span>Modules</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li class="current"><a href="annotated.html"><span>Classes</span></a></li> <li><a href="files.html"><span>Files</span></a></li> </ul> </div> <div id="navrow2" class="tabs2"> <ul class="tablist"> <li><a href="annotated.html"><span>Class List</span></a></li> <li><a href="hierarchy.html"><span>Class Hierarchy</span></a></li> <li><a href="functions.html"><span>Class Members</span></a></li> </ul> </div> <div id="nav-path" class="navpath"> <ul> <li class="navelem"><a class="el" href="namespaceedelib.html">edelib</a> </li> <li class="navelem"><a class="el" href="classedelib_1_1Regex.html">Regex</a> </li> </ul> </div> </div> <div class="header"> <div class="summary"> <a href="#pub-types">Public Types</a> | <a href="#pub-methods">Public Member Functions</a> </div> <div class="headertitle"> <div class="title">Regex Class Reference</div> </div> </div><!--header--> <div class="contents"> <!-- doxytag: class="edelib::Regex" --> <p><a class="el" href="classedelib_1_1Regex.html" title="Regex class.">Regex</a> class. <a href="classedelib_1_1Regex.html#details">More...</a></p> <p><code>#include <<a class="el" href="Regex_8h_source.html">edelib/Regex.h</a>></code></p> <p><a href="classedelib_1_1Regex-members.html">List of all members.</a></p> <table class="memberdecls"> <tr><td colspan="2"><h2><a name="pub-types"></a> Public Types</h2></td></tr> <tr><td class="memItemLeft" align="right" valign="top">typedef <a class="el" href="classedelib_1_1list.html">list</a>< <a class="el" href="structedelib_1_1RegexMatch.html">RegexMatch</a> > </td><td class="memItemRight" valign="bottom"><a class="el" href="classedelib_1_1Regex.html#aaad5356475ff482c089dc62dbede09af">MatchVec</a></td></tr> <tr><td colspan="2"><h2><a name="pub-methods"></a> Public Member Functions</h2></td></tr> <tr><td class="memItemLeft" align="right" valign="top"> </td><td class="memItemRight" valign="bottom"><a class="el" href="classedelib_1_1Regex.html#afb96823e7236956368790b42e977b37d">Regex</a> ()</td></tr> <tr><td class="memItemLeft" align="right" valign="top"> </td><td class="memItemRight" valign="bottom"><a class="el" href="classedelib_1_1Regex.html#ae324e7e66f845f08af7b982e2cf46966">~Regex</a> ()</td></tr> <tr><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><a class="el" href="classedelib_1_1Regex.html#ad9c90a2b127c5328aa1c65b940b03c27">compile</a> (const char *pattern, int m=0)</td></tr> <tr><td class="memItemLeft" align="right" valign="top"> </td><td class="memItemRight" valign="bottom"><a class="el" href="classedelib_1_1Regex.html#a4e78e3cd062c82439dffc9cddbdd8a20">operator bool</a> (void) const </td></tr> <tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="classedelib_1_1Regex.html#a0453540a4c2ac2a2495704bd2382be20">match</a> (const char *str, int match_mode, int start, int len, <a class="el" href="classedelib_1_1Regex.html#aaad5356475ff482c089dc62dbede09af">MatchVec</a> *matches)</td></tr> <tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="classedelib_1_1Regex.html#a88a1d9ad1c840752ca82578167cc692b">match</a> (const char *str, int match_mode=0, <a class="el" href="classedelib_1_1Regex.html#aaad5356475ff482c089dc62dbede09af">MatchVec</a> *matches=0)</td></tr> <tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="classedelib_1_1Regex.html#af2b9f0807c03a298b618b925d101c6f8">split</a> (const char *str, <a class="el" href="classedelib_1_1list.html">list</a>< <a class="el" href="classedelib_1_1String.html">String</a> > &ls, int match_mode=0)</td></tr> <tr><td class="memItemLeft" align="right" valign="top">const char * </td><td class="memItemRight" valign="bottom"><a class="el" href="classedelib_1_1Regex.html#a16e8dd0059122769f0b36d957091ad99">strerror</a> (void) const </td></tr> </table> <hr/><a name="details" id="details"></a><h2>Detailed Description</h2> <div class="textblock"><p><a class="el" href="classedelib_1_1Regex.html" title="Regex class.">Regex</a> class. </p> <p><a class="el" href="classedelib_1_1Regex.html" title="Regex class.">Regex</a> is pattern matching (aka. regular expression) class used to search certain substrings inside line or text. This class use Perl compatible expressions thanks to PCRE backend.</p> <p>Before doing some matching, you must compile pattern first buy using <a class="el" href="classedelib_1_1Regex.html#ad9c90a2b127c5328aa1c65b940b03c27">compile()</a> member.</p> <p>Matching is done via <a class="el" href="classedelib_1_1Regex.html#a0453540a4c2ac2a2495704bd2382be20">match()</a> member. It will return the number of matched substrings and (if given) set <a class="el" href="structedelib_1_1RegexMatch.html" title="RegexMatch class.">RegexMatch</a> list with offsets. If fails, -1 will be returned. Here is the sample: that explains it: </p> <div class="fragment"><pre class="fragment"> <a class="code" href="classedelib_1_1Regex.html#afb96823e7236956368790b42e977b37d">Regex</a> r; <a class="code" href="classedelib_1_1Regex.html#aaad5356475ff482c089dc62dbede09af">Regex::MatchVec</a> mv; r.compile(<span class="stringliteral">"(de|br)mo"</span>); r.match(<span class="stringliteral">"some demo string"</span>, 0, &mv); </pre></div><p>Here, <a class="el" href="classedelib_1_1Regex.html#a0453540a4c2ac2a2495704bd2382be20">match()</a> will return 2 and MatchVec list will have (5,4) and (5,2) values (where the first value is offset and the second substring length). This explains one important property inherited from PCRE: when grouped patterns are involved and they are found in string, MatchVec first element will be full matched string and substrings will follow. </p> </div><hr/><h2>Member Typedef Documentation</h2> <a class="anchor" id="aaad5356475ff482c089dc62dbede09af"></a><!-- doxytag: member="edelib::Regex::MatchVec" ref="aaad5356475ff482c089dc62dbede09af" args="" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">typedef <a class="el" href="classedelib_1_1list.html">list</a><<a class="el" href="structedelib_1_1RegexMatch.html">RegexMatch</a>> <a class="el" href="classedelib_1_1Regex.html#aaad5356475ff482c089dc62dbede09af">MatchVec</a></td> </tr> </table> </div> <div class="memdoc"> <p>Shortcut for the list of <a class="el" href="structedelib_1_1RegexMatch.html" title="RegexMatch class.">RegexMatch</a> </p> </div> </div> <hr/><h2>Constructor & Destructor Documentation</h2> <a class="anchor" id="afb96823e7236956368790b42e977b37d"></a><!-- doxytag: member="edelib::Regex::Regex" ref="afb96823e7236956368790b42e977b37d" args="()" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname"><a class="el" href="classedelib_1_1Regex.html">Regex</a> </td> <td>(</td> <td class="paramname"></td><td>)</td> <td></td> </tr> </table> </div> <div class="memdoc"> <p>Empty constructor </p> </div> </div> <a class="anchor" id="ae324e7e66f845f08af7b982e2cf46966"></a><!-- doxytag: member="edelib::Regex::~Regex" ref="ae324e7e66f845f08af7b982e2cf46966" args="()" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">~<a class="el" href="classedelib_1_1Regex.html">Regex</a> </td> <td>(</td> <td class="paramname"></td><td>)</td> <td></td> </tr> </table> </div> <div class="memdoc"> <p>Clears all internal data </p> </div> </div> <hr/><h2>Member Function Documentation</h2> <a class="anchor" id="ad9c90a2b127c5328aa1c65b940b03c27"></a><!-- doxytag: member="edelib::Regex::compile" ref="ad9c90a2b127c5328aa1c65b940b03c27" args="(const char *pattern, int m=0)" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">bool <a class="el" href="classedelib_1_1Regex.html#ad9c90a2b127c5328aa1c65b940b03c27">compile</a> </td> <td>(</td> <td class="paramtype">const char * </td> <td class="paramname"><em>pattern</em>, </td> </tr> <tr> <td class="paramkey"></td> <td></td> <td class="paramtype">int </td> <td class="paramname"><em>m</em> = <code>0</code> </td> </tr> <tr> <td></td> <td>)</td> <td></td><td></td> </tr> </table> </div> <div class="memdoc"> <p>Compile pattern for matching. This <b>must</b> be called before match/search functions.</p> <dl class="return"><dt><b>Returns:</b></dt><dd>true if pattern compiled successfully, or false if not. </dd></dl> <dl class="params"><dt><b>Parameters:</b></dt><dd> <table class="params"> <tr><td class="paramname">pattern</td><td>is matching pattern </td></tr> <tr><td class="paramname">m</td><td>is RegexMode type </td></tr> </table> </dd> </dl> </div> </div> <a class="anchor" id="a0453540a4c2ac2a2495704bd2382be20"></a><!-- doxytag: member="edelib::Regex::match" ref="a0453540a4c2ac2a2495704bd2382be20" args="(const char *str, int match_mode, int start, int len, MatchVec *matches)" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">int <a class="el" href="classedelib_1_1Regex.html#a0453540a4c2ac2a2495704bd2382be20">match</a> </td> <td>(</td> <td class="paramtype">const char * </td> <td class="paramname"><em>str</em>, </td> </tr> <tr> <td class="paramkey"></td> <td></td> <td class="paramtype">int </td> <td class="paramname"><em>match_mode</em>, </td> </tr> <tr> <td class="paramkey"></td> <td></td> <td class="paramtype">int </td> <td class="paramname"><em>start</em>, </td> </tr> <tr> <td class="paramkey"></td> <td></td> <td class="paramtype">int </td> <td class="paramname"><em>len</em>, </td> </tr> <tr> <td class="paramkey"></td> <td></td> <td class="paramtype"><a class="el" href="classedelib_1_1Regex.html#aaad5356475ff482c089dc62dbede09af">MatchVec</a> * </td> <td class="paramname"><em>matches</em> </td> </tr> <tr> <td></td> <td>)</td> <td></td><td></td> </tr> </table> </div> <div class="memdoc"> <p>Search compiled pattern in str and return number of grouped matches. If pattern wasn't found or some error occured during search, returned value (depending on error) will be less than 0 (see PCRE documentation about returned values).</p> <dl class="return"><dt><b>Returns:</b></dt><dd>the number of grouped matches or value less than 0 in case of error </dd></dl> <dl class="params"><dt><b>Parameters:</b></dt><dd> <table class="params"> <tr><td class="paramname">str</td><td>is target string where compiled pattern is searched </td></tr> <tr><td class="paramname">match_mode</td><td>is OR-ed RegexMatchMode value </td></tr> <tr><td class="paramname">start</td><td>is starting position on string </td></tr> <tr><td class="paramname">len</td><td>is desired length where matching will occur; if given -1, full length will be searched </td></tr> <tr><td class="paramname">matches</td><td>is list of matching objects </td></tr> </table> </dd> </dl> </div> </div> <a class="anchor" id="a88a1d9ad1c840752ca82578167cc692b"></a><!-- doxytag: member="edelib::Regex::match" ref="a88a1d9ad1c840752ca82578167cc692b" args="(const char *str, int match_mode=0, MatchVec *matches=0)" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">int <a class="el" href="classedelib_1_1Regex.html#a0453540a4c2ac2a2495704bd2382be20">match</a> </td> <td>(</td> <td class="paramtype">const char * </td> <td class="paramname"><em>str</em>, </td> </tr> <tr> <td class="paramkey"></td> <td></td> <td class="paramtype">int </td> <td class="paramname"><em>match_mode</em> = <code>0</code>, </td> </tr> <tr> <td class="paramkey"></td> <td></td> <td class="paramtype"><a class="el" href="classedelib_1_1Regex.html#aaad5356475ff482c089dc62dbede09af">MatchVec</a> * </td> <td class="paramname"><em>matches</em> = <code>0</code> </td> </tr> <tr> <td></td> <td>)</td> <td></td><td><code> [inline]</code></td> </tr> </table> </div> <div class="memdoc"> <p>The same as above <a class="el" href="classedelib_1_1Regex.html#a0453540a4c2ac2a2495704bd2382be20">match()</a>, but matching will start from the beginning and full string length will be used </p> <p>References <a class="el" href="classedelib_1_1Regex.html#a88a1d9ad1c840752ca82578167cc692b">Regex::match()</a>.</p> <p>Referenced by <a class="el" href="classedelib_1_1Regex.html#a88a1d9ad1c840752ca82578167cc692b">Regex::match()</a>.</p> </div> </div> <a class="anchor" id="a4e78e3cd062c82439dffc9cddbdd8a20"></a><!-- doxytag: member="edelib::Regex::operator bool" ref="a4e78e3cd062c82439dffc9cddbdd8a20" args="(void) const " --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">operator bool </td> <td>(</td> <td class="paramtype">void </td> <td class="paramname"></td><td>)</td> <td> const</td> </tr> </table> </div> <div class="memdoc"> <p>Validate if <a class="el" href="classedelib_1_1Regex.html#ad9c90a2b127c5328aa1c65b940b03c27">compile()</a> was successfull. This is short way for checking <a class="el" href="classedelib_1_1Regex.html#ad9c90a2b127c5328aa1c65b940b03c27">compile()</a> returned value, like: </p> <div class="fragment"><pre class="fragment"> <a class="code" href="classedelib_1_1Regex.html#afb96823e7236956368790b42e977b37d">Regex</a> r; r.compile(...); <span class="keywordflow">if</span>(!r) <span class="comment">// die</span> </pre></div> </div> </div> <a class="anchor" id="af2b9f0807c03a298b618b925d101c6f8"></a><!-- doxytag: member="edelib::Regex::split" ref="af2b9f0807c03a298b618b925d101c6f8" args="(const char *str, list< String > &ls, int match_mode=0)" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">int <a class="el" href="classedelib_1_1Regex.html#af2b9f0807c03a298b618b925d101c6f8">split</a> </td> <td>(</td> <td class="paramtype">const char * </td> <td class="paramname"><em>str</em>, </td> </tr> <tr> <td class="paramkey"></td> <td></td> <td class="paramtype"><a class="el" href="classedelib_1_1list.html">list</a>< <a class="el" href="classedelib_1_1String.html">String</a> > & </td> <td class="paramname"><em>ls</em>, </td> </tr> <tr> <td class="paramkey"></td> <td></td> <td class="paramtype">int </td> <td class="paramname"><em>match_mode</em> = <code>0</code> </td> </tr> <tr> <td></td> <td>)</td> <td></td><td></td> </tr> </table> </div> <div class="memdoc"> <p>Split given str and put each of splitted items in list.</p> <dl class="return"><dt><b>Returns:</b></dt><dd>0 if pattern didn't find or size of the list </dd></dl> <dl class="params"><dt><b>Parameters:</b></dt><dd> <table class="params"> <tr><td class="paramname">str</td><td>is data to be splitted </td></tr> <tr><td class="paramname">ls</td><td>is list where to put data </td></tr> <tr><td class="paramname">match_mode</td><td>is OR-ed RegexMatchMode value </td></tr> </table> </dd> </dl> </div> </div> <a class="anchor" id="a16e8dd0059122769f0b36d957091ad99"></a><!-- doxytag: member="edelib::Regex::strerror" ref="a16e8dd0059122769f0b36d957091ad99" args="(void) const " --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">const char* <a class="el" href="classedelib_1_1Regex.html#a16e8dd0059122769f0b36d957091ad99">strerror</a> </td> <td>(</td> <td class="paramtype">void </td> <td class="paramname"></td><td>)</td> <td> const</td> </tr> </table> </div> <div class="memdoc"> <p>Return error in string form. Returned value points to static data and <b>must not</b> be modified or cleared </p> </div> </div> <hr/>The documentation for this class was generated from the following file:<ul> <li>edelib/<a class="el" href="Regex_8h_source.html">Regex.h</a></li> </ul> </div><!-- contents --> <hr class="footer"/><address class="footer"><small> Generated on Tue Jun 5 2012 17:49:03 for edelib by  <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/> </a> 1.7.6.1 </small></address> </body> </html>