Boost logo

Boost-Commit :

From: eric_at_[hidden]
Date: 2007-10-11 17:29:58


Author: eric_niebler
Date: 2007-10-11 17:29:57 EDT (Thu, 11 Oct 2007)
New Revision: 39947
URL: http://svn.boost.org/trac/boost/changeset/39947

Log:
document use of let() with regex_(token_)iterator
Text files modified:
   trunk/libs/xpressive/doc/actions.qbk | 41 ++++++++++++++++++++++++++++++++++++++++
   1 files changed, 41 insertions(+), 0 deletions(-)

Modified: trunk/libs/xpressive/doc/actions.qbk
==============================================================================
--- trunk/libs/xpressive/doc/actions.qbk (original)
+++ trunk/libs/xpressive/doc/actions.qbk 2007-10-11 17:29:57 EDT (Thu, 11 Oct 2007)
@@ -349,6 +349,47 @@
 during any of the regex algorithms, so they are safe to use in multiple
 threads.]
 
+The syntax for late-bound action arguments is a little different if you are
+using _regex_iterator_ or _regex_token_iterator_. The regex iterators accept
+an extra constructor parameter for specifying the argument bindings. There is
+a `let()` function that you can use to bind variables to their placeholders.
+The following code demonstrates how.
+
+ // Define a placeholder for a map object:
+ placeholder<std::map<std::string, int> > _map;
+
+ // Match a word and an integer, separated by =>,
+ // and then stuff the result into a std::map<>
+ sregex pair = ( (s1= +_w) >> "=>" >> (s2= +_d) )
+ [ _map[s1] = as<int>(s2) ];
+
+ // The string to parse
+ std::string str("aaa=>1 bbb=>23 ccc=>456");
+
+ // Here is the actual map to fill in:
+ std::map<std::string, int> result;
+
+ // Create a regex_iterator to find all the matches
+ sregex_iterator it(str.begin(), str.end(), pair, let(_map=result));
+ sregex_iterator end;
+
+ // step through all the matches, and fill in
+ // the result map
+ while(it != end)
+ ++it;
+
+ std::cout << result["aaa"] << '\n';
+ std::cout << result["bbb"] << '\n';
+ std::cout << result["ccc"] << '\n';
+
+This program displays:
+
+[pre
+1
+23
+456
+]
+
 [h2 User-Defined Assertions]
 
 You are probably already familiar with regular expression /assertions/. In


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk