C++ (Qt)#include <boost/spirit/include/qi.hpp>#include <boost/fusion/include/io.hpp>#include <boost/spirit/include/phoenix.hpp> #include <iostream>#include <string> namespace qi = boost::spirit::qi;namespace phx = boost::phoenix;namespace sw = boost::spirit::standard_wide; int main(){ std::string str = "Zombie : Hip "; std::string out; if(qi::phrase_parse(str.begin(), str.end(), qi::lexeme[+qi::alnum] >> qi::omit[qi::char_("_:") >> +qi::char_], sw::space, out)) std::cout << out << std::endl; return 0;}
C++ (Qt) if(qi::phrase_parse(str.begin(), str.end(), qi::lexeme[+qi::alnum] >> qi::omit[qi::char_("_:") >> +qi::char_], sw::space, out))
C++ (Qt)std::string GetPrefix(const std::vector<std::string> & vec){ std::string s = vec[0]; auto result = std::find_if(s.begin(), s.end(), [] (char ch) { return !(std::isalpha(ch) || std::isdigit(ch)); }); if (result == s.end()) return std::string(); // prefix not found or prefix at end: "Zombie_" auto distance = std::distance(s.begin(), result); if (distance == 0) return std::string(); // prefix in beginning: "_Zombie" std::string prefix = s.substr(0, distance + 1); if (std::all_of(vec.begin(), vec.end(), [prefix] (std::string s) { return s.find(prefix) == 0; })) return prefix; // prefix everywhere return std::string(); // prefix partly}