C++ (Qt)template <class T = char>class tex_string_iterator : public std::iterator<std::bidirectional_iterator_tag, T, ptrdiff_t, const T*, const T&>
C++ (Qt)boost::regex expr("([#\\\\][^\\n]*)"); std::string buffer = "Te#st\nyy\\yy "; tex_string_iterator<char> iter(buffer.begin(), buffer.end(), expr); tex_string_iterator<char> end(buffer.end(), buffer.end(), expr); for (; iter != end; ++iter) { std::cout << *iter; }
BashTeyy
C++ (Qt) boost::sregex_iterator it(buffer.begin(), buffer.end(), boost::regex("\\\\cite[\\s\\t]*\\{([^}]*)\\}")); boost::sregex_iterator end; for (; it != end; ++it) { std::string str(it->str(1)); boost::tokenizer<boost::char_separator<char>> tok(str, boost::char_separator<char>(",")); for (auto it = tok.begin(); it != tok.end(); ++it) { std::string arg = boost::algorithm::trim_copy(*it); if (std::find_if(args_list.begin(), args_list.end(), std::bind(std::equal_to<std::string>(), _1, arg)) == args_list.end()) args_list.push_back(arg); } }
C++ (Qt) tex_string_iterator<char> ibegin(buffer.begin(), buffer.end(), boost::regex("(%[^\\n]*)")); tex_string_iterator<char> iend(buffer.end(), buffer.end(), boost::regex("(%[^\\n]*)")); boost::regex_iterator<tex_string_iterator<char>> it(ibegin, iend, boost::regex("\\\\cite[\\s\\t]*\\{([^}]*)\\}")); boost::regex_iterator<tex_string_iterator<char>> end; for (; it != end; ++it) { std::string str(it->str(1)); boost::tokenizer<boost::char_separator<char>> tok(str, boost::char_separator<char>(",")); for (auto it = tok.begin(); it != tok.end(); ++it) { std::string arg = boost::algorithm::trim_copy(*it); if (std::find_if(args_list.begin(), args_list.end(), std::bind(std::equal_to<std::string>(), _1, arg)) == args_list.end()) args_list.push_back(arg); } }