c++ - Boost.regex with icu support using named capture groups -


below test program uses named captures support in boost-regex extract year, month , day fields date (just illustrate use of named captures):

#include <boost/regex.hpp> #include <boost/regex/icu.hpp>  #include <string> #include <iostream>  int main(int argc, const char** argv) {    std::string   str = "2013-08-15";    boost::regex  rex("(?<year>[0-9]{4}).*(?<month>[0-9]{2}).*(?<day>[0-9]{2})");    boost::smatch res;     std::string::const_iterator begin = str.begin();    std::string::const_iterator end   = str.end();     if (boost::regex_search(begin, end, res, rex))    {       std::cout << "day:   " << res ["day"] << std::endl                 << "month: " << res ["month"] << std::endl                 << "year:  " << res ["year"] << std::endl;     } } 

compiled with

g++ regex.cpp -lboost_regex -lboost_locale -licuuc 

this little program produce following output expected:

$ ./a.out  day:   15 month: 08 year:  2013 

next replace ordinary regex parts u32regex counterparts:

#include <boost/regex.hpp> #include <boost/regex/icu.hpp>  #include <string> #include <iostream>  int main(int argc, const char** argv) {    std::string   str = "2013-08-15";    boost::u32regex  rex = boost::make_u32regex("(?<year>[0-9]{4}).*(?<month>[0-9]{2}).*(?<day>[0-9]{2})", boost::regex_constants::perl);    boost::smatch res;     std::string::const_iterator begin = str.begin();    std::string::const_iterator end   = str.end();     if (boost::u32regex_search(begin, end, res, rex))    {       std::cout << "day:   " << res ["day"] << std::endl                 << "month: " << res ["month"] << std::endl                 << "year:  " << res ["year"] << std::endl;     } } 

building running program results in run-time exception suggesting uninitialized shared_ptr:

$ ./a.out  a.out: /usr/include/boost/smart_ptr/shared_ptr.hpp:648: typename boost::detail::sp_member_access<t>::type boost::shared_ptr<t>::operator->() const [with t = boost::re_detail::named_subexpressions; typename boost::detail::sp_member_access<t>::type = boost::re_detail::named_subexpressions*]: assertion `px != 0' failed. 

i'm not using shared pointers directly though.

this boost 1.58.1 , gcc 5.3.1.

how can u32regex version of program running correctly ?


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -