Карта сайта Kansoftware
НОВОСТИУСЛУГИРЕШЕНИЯКОНТАКТЫ
Разработка программного обеспечения

Iterating Over the Matches Within An MFC String

Boost , Boost.Regex 5.1.2 , Using Boost Regex With MFC Strings

Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

PrevUpHomeNext

Для облегчения преобразования строки MFC/ATL в<regex_iterator>или<regex_token_iterator>предоставляются следующие вспомогательные функции:

regex_iterator creation helper
template <class charT>
regex_iterator<charT const*>
   make_regex_iterator(
      const ATL::CSimpleStringT<charT>& s,
      const basic_regex<charT>& e,
      ::boost::regex_constants::match_flag_type f = boost::regex_constants::match_default);

Эффекты: возвращение<regex_iterator(s.GetString(),s.GetString()+s.GetLength(), e, f);>

Пример:

void enumerate_links(const CString& html)
{
   // enumerate and print all the  links in some HTML text,
   // the expression used is by Andew Lee on www.regxlib.com:
   boost::tregex r(
      __T("href=[\"\']((http:\\/\\/|\\.\\/|\\/)?\\w+"
          "(\\.\\w+)*(\\/\\w+(\\.\\w+)?)*"
          "(\\/|\\?\\w*=\\w*(&\\w*=\\w*)*)?)[\"\']"));
   boost::tregex_iterator i(boost::make_regex_iterator(html, r)), j;
   while(i != j)
   {
      std::cout << (*i)[1] << std::endl;
      ++i;
   }
}
regex_token_iterator creation helpers
template <class charT>
regex_token_iterator<charT const*>
   make_regex_token_iterator(
      const ATL::CSimpleStringT<charT>& s,
      const basic_regex<charT>& e,
      int sub = 0,
      ::boost::regex_constants::match_flag_type f = boost::regex_constants::match_default);

Эффекты: возвращение<regex_token_iterator(s.GetString(),s.GetString()+s.GetLength(), e, sub, f);>

template <class charT>
regex_token_iterator<charT const*>
   make_regex_token_iterator(
      const ATL::CSimpleStringT<charT>& s,
      const basic_regex<charT>& e,
      const std::vector<int>& subs,
      ::boost::regex_constants::match_flag_type f = boost::regex_constants::match_default);

Эффекты: возврат<regex_token_iterator(s.GetString(),s.GetString()+s.GetLength(), e, subs, f);>

template <class charT, std::size_t N>
regex_token_iterator<charT const*>
   make_regex_token_iterator(
      const ATL::CSimpleStringT<charT>& s,
      const basic_regex<charT>& e,
      const int (& subs)[N],
      ::boost::regex_constants::match_flag_type f = boost::regex_constants::match_default);

Эффекты: возврат<regex_token_iterator(s.GetString(),s.GetString()+s.GetLength(), e, subs, f);>

Пример:

void enumerate_links2(const CString& html)
{
   // enumerate and print all the  links in some HTML text,
   // the expression used is by Andew Lee on www.regxlib.com:
   boost::tregex r(
         __T("href=[\"\']((http:\\/\\/|\\.\\/|\\/)?\\w+"
             "(\\.\\w+)*(\\/\\w+(\\.\\w+)?)*"
             "(\\/|\\?\\w*=\\w*(&\\w*=\\w*)*)?)[\"\']"));
   boost::tregex_token_iterator i(boost::make_regex_token_iterator(html, r, 1)), j;
   while(i != j)
   {
      std::cout << *i << std::endl;
      ++i;
   }
}

PrevUpHomeNext

Статья Iterating Over the Matches Within An MFC String раздела Boost.Regex 5.1.2 Using Boost Regex With MFC Strings может быть полезна для разработчиков на c++ и boost.




Материалы статей собраны из открытых источников, владелец сайта не претендует на авторство. Там где авторство установить не удалось, материал подаётся без имени автора. В случае если Вы считаете, что Ваши права нарушены, пожалуйста, свяжитесь с владельцем сайта.



:: Главная :: Using Boost Regex With MFC Strings ::


реклама


©KANSoftWare (разработка программного обеспечения, создание программ, создание интерактивных сайтов), 2007
Top.Mail.Ru

Время компиляции файла: 2024-08-30 11:47:00
2025-05-19 18:36:24/0.0083010196685791/1