Boost logo

Boost-Commit :

From: hughwimberly_at_[hidden]
Date: 2007-07-15 03:24:41


Author: hughwimberly
Date: 2007-07-15 03:24:40 EDT (Sun, 15 Jul 2007)
New Revision: 7434
URL: http://svn.boost.org/trac/boost/changeset/7434

Log:
Support for named captures, including retrieval and backreferences. Will not work for ICU, and untested on wide characters. (last two files)

Text files modified:
   sandbox/SOC/2007/regex/named-captures/boost/regex/v4/basic_regex.hpp | 13 ++++++-------
   sandbox/SOC/2007/regex/named-captures/boost/regex/v4/match_results.hpp | 19 +++++++++++++++++--
   2 files changed, 23 insertions(+), 9 deletions(-)

Modified: sandbox/SOC/2007/regex/named-captures/boost/regex/v4/basic_regex.hpp
==============================================================================
--- sandbox/SOC/2007/regex/named-captures/boost/regex/v4/basic_regex.hpp (original)
+++ sandbox/SOC/2007/regex/named-captures/boost/regex/v4/basic_regex.hpp 2007-07-15 03:24:40 EDT (Sun, 15 Jul 2007)
@@ -45,7 +45,8 @@
 struct regex_data
 {
    typedef regex_constants::syntax_option_type flag_type;
- typedef std::size_t size_type;
+ typedef std::size_t size_type;
+ typedef std::basic_string<charT> name_type;
 
    regex_data(const ::boost::shared_ptr<
       ::boost::regex_traits_wrapper<traits> >& t)
@@ -67,6 +68,7 @@
    unsigned int m_can_be_null; // whether we can match a null string
    re_detail::raw_storage m_data; // the buffer in which our states are constructed
    typename traits::char_class_type m_word_mask; // mask used to determine if a character is a word character
+ shared_ptr<std::map<name_type, int> > p_name_map; // map to correlate named captures with the index of the capture
 };
 //
 // class basic_regex_implementation
@@ -91,7 +93,7 @@
                           const charT* arg_last,
                           flag_type f)
    {
- p_capture_names.reset(new std::map<const charT*, int>());
+ p_name_map.reset(new std::map<name_type, int>);
       regex_data<charT, traits>* pdat = this;
       basic_regex_parser<charT, traits> parser(pdat);
       parser.parse(arg_first, arg_last, f);
@@ -167,8 +169,6 @@
       basic_regex_implementation<charT, traits> const* p = this;
       return *static_cast<const regex_data<charT, traits>*>(p);
    }
-private:
- shared_ptr<std::map<const charT*, int> > p_capture_names;
 };
 
 } // namespace re_detail
@@ -499,10 +499,9 @@
       BOOST_ASSERT(0 != m_pimpl.get());
       return m_pimpl->get_data();
    }
- const shared_ptr<std::map<const charT*, int> > get_capture_names_ptr()const
+ const shared_ptr<std::map<std::basic_string<charT>, int> > get_name_map() const
    {
- BOOST_ASSERT(0 != m_pimpl.get());
- return m_pimpl->p_capture_names;
+ return m_pimpl->p_name_map;
    }
 
 private:

Modified: sandbox/SOC/2007/regex/named-captures/boost/regex/v4/match_results.hpp
==============================================================================
--- sandbox/SOC/2007/regex/named-captures/boost/regex/v4/match_results.hpp (original)
+++ sandbox/SOC/2007/regex/named-captures/boost/regex/v4/match_results.hpp 2007-07-15 03:24:40 EDT (Sun, 15 Jul 2007)
@@ -125,6 +125,17 @@
       return m_null;
    }
 
+ const_reference operator[](const string_type& ref_name) const
+ {
+ std::map<string_type, int>::iterator ref = p_name_map->find(ref_name);
+ if (ref != p_name_map->end())
+ {
+ int sub = ref->second + 2;
+ return m_subs[sub];
+ }
+ return m_null;
+ }
+
    const_reference prefix() const
    {
       return (*this)[-1];
@@ -286,13 +297,17 @@
          set_first(i);
    }
    void BOOST_REGEX_CALL maybe_assign(const match_results<BidiIterator, Allocator>& m);
-
+public:
+ void set_name_map(const shared_ptr<std::map<string_type, int> > p_names)
+ {
+ p_name_map = p_names;
+ }
 
 private:
    vector_type m_subs; // subexpressions
    BidiIterator m_base; // where the search started from
    sub_match<BidiIterator> m_null; // a null match
- shared_ptr<std::map<const char_type*, int> > p_capture_names;
+ shared_ptr<std::map<string_type, int> > p_name_map; //map from names to integer index
 };
 
 template <class BidiIterator, class Allocator>


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