bool SearchBlacklist::ok(const QString &exp, Argument type) { const QList<QString> &l = (type == NAME)? list[NAME] : list[TTH]; foreach (const QString &str, l) { QRegExp reg_exp(str, Qt::CaseInsensitive, QRegExp::Wildcard); if (reg_exp.exactMatch(exp)) return false; }
QString getType(const QXmlAttributes & attributes) { const int type_idx(indexOf(attributes, "type")); const int named_type_idx(indexOf(attributes, "named-type")); QCString type; if (named_type_idx >= 0) { type = attributes.value(named_type_idx).utf8(); if (type.left(2)!="::") { type = getCurrentScope(attributes.value(named_type_idx).utf8()); } else { type = type.mid(2); } if (m_namedTypeMap.contains(type)) { if (type_idx >= 0) { const QCString dbus_type(attributes.value(type_idx).utf8()); if (dbus_type != m_namedTypeMap[type]) { DOC_ERROR(QString("Type \"%1\" does not match up with " "previous definition of named type \"%2\" (which was \"%3\"."). arg(dbus_type). arg(type). arg(m_namedTypeMap[type])); } } return type; } DOC_ERROR(QString("Undefined named type \"%1\" used.").arg(type)); } if (type_idx >= 0) { type = attributes.value(type_idx).utf8(); QRegExp reg_exp(QCString("(a?[ybnqiuxdtsogv]|a[{]sv[}])")); if (reg_exp.match(type.data())) { return type; } DOC_ERROR(QString("Unnamed complex D-Bus type \"%1\" found.").arg(type)); } return QString(); }
void RegExpTest::test3() { // std::vector<std::string> tokens = {"CR", "LF", "Prepend", "L", "V", "LV", "LVT", "T", "Control", "Extend", "SpacingMark"}; std::vector<std::string> tokens = { "Other", "CR", "LF", "Control", "Extend", "Prepend", "SpacingMark", "L", "V", "T", "LV", "LVT" }; /* ( CR LF ) | ( Prepend* ( L+ | (L* ( ( V | LV ) V* | LVT ) T*) | T+ | [^ Control CR LF ] ) ( Extend | SpacingMark )* ) | . */ std::string s = "(CR.LF)" \ "|(Prepend*." \ "(L+|(L*.((V|LV).(V*)|LVT).T*)|T+|(Other|SpacingMark|Prepend|Extend|LVT|LV|L|V|T))" \ ".(Extend|SpacingMark)*" \ ")" "|(Other|SpacingMark|Prepend|Control|Extend|LVT|CR|LF|LV|L|V|T)" ; // std::string s = "(V|LV).(V*)|LVT"; // std::string s = "L+|(L*.((V|LV).V*|LVT).T*)"; RegExpWithTokens<char> reg_exp(tokens, 'a'); //reg_exp.evaluate(exp.str()); reg_exp.evaluate(s); }
void RegExpTest::word_segmentation_test() { std::vector<std::string> tokens = { "Other", "CR", "LF", "Newline", "Extend", "Format", "Katakana", "ALetter", "MidLetter", "MidNum", "MidNumLet", "Numeric", "ExtendNumLet" }; // begin regular exp std::string Other_EF = "(Other.(Extend|Format)*)"; std::string ALetter_EF = "(ALetter.(Extend|Format)*)"; std::string Numeric_EF = "(Numeric.(Extend|Format)*)"; std::string Katakana_EF = "(Katakana.(Extend|Format)*)"; std::string ExtendNumLet_EF = "(ExtendNumLet.(Extend|Format)*)"; std::string MidLetter_EF = "(MidLetter.(Extend|Format)*)"; std::string MidNumLet_EF = "(MidNumLet.(Extend|Format)*)"; std::string MidNum_EF = "(MidNum.(Extend|Format)*)"; std::string MidLetter_MidNumLet_EF = "((MidLetter|MidNumLet).(Extend|Format)*)"; std::string MidNum_MidNumLet_EF = "((MidNum|MidNumLet).(Extend|Format)*)"; // std::string ALetter = "(" + ALetter_EF + "+|(" + ALetter_EF + "+." + MidLetter_MidNumLet_EF + "." + ALetter_EF + "+))"; std::string ALetter = "((" + ALetter_EF + "|(" + ALetter_EF + "." + MidLetter_MidNumLet_EF + "." + ALetter_EF + "))+)"; std::string Numeric = "((" + Numeric_EF + "|(" + Numeric_EF + "+." + MidNum_MidNumLet_EF + "." + Numeric_EF + "+))+)"; // std::string Numeric = "(" + Numeric_EF + "+|(" + Numeric_EF + "+." + MidNum_MidNumLet_EF + "." + Numeric_EF + "+))"; std::string ALetter_Numeric = "((" + ALetter + "|" + Numeric + ")+)"; //std::string Katakana = "((" + Katakana_EF + "+|" + ExtendNumLet_EF + "*)*)"; //std::string Katakana = "(" + Katakana_EF + "+)"; std::string Katakana_ExtendNumLet = "((" + Katakana_EF + "+|" + Katakana_EF + "+." + ExtendNumLet_EF + "+|" + ExtendNumLet_EF + "+." + Katakana_EF + "+)+)"; std::string ALetter_Numeric_ExtendNumLet = "((" + ALetter_Numeric + "+|" + ALetter_Numeric + "+." + ExtendNumLet_EF + "+|" + ExtendNumLet_EF + "+." + ALetter_Numeric + "+)+)"; std::string ExtendNumLet = "(" + ExtendNumLet_EF + "+)"; std::string ALetter_Numeric_Katakana_1 = "(" + ALetter_Numeric + "+." + ExtendNumLet_EF + "+." + Katakana_ExtendNumLet + "+)"; std::string ALetter_Numeric_Katakana_2 = "(" + Katakana_ExtendNumLet + "+." + ExtendNumLet_EF + "+." + ALetter_Numeric + "+)"; std::stringstream ss; // ss << "("+ Other_EF + "|CR|LF|Newline|Extend|Format|Katakana|ALetter|" + MidLetter_EF + "|MidNum|" + MidNumLet_EF + "|Numeric|ExtendNumLet)"; ss << "((Other|Extend|Format|Katakana|ALetter|MidLetter|MidNum|MidNumLet|Numeric|ExtendNumLet).(Extend|Format)*)"; ss << "|(CR|LF|Newline)"; ss << "|(CR.LF)"; ss << "|((Extend|Format)*)"; ss << "|" << ALetter_Numeric; ss << "|" << ALetter_Numeric_ExtendNumLet ; ss << "|" << Katakana_ExtendNumLet; ss << "|" << ALetter_Numeric_Katakana_1; ss << "|" << ALetter_Numeric_Katakana_2; ss << "|" << ExtendNumLet; ss << "|" << ALetter; // end regular exp RegExpWithTokens<char> reg_exp(tokens, 'a'); reg_exp.evaluate(ss.str()); to_str(std::cout, reg_exp.dfa(), tokens, 'a'); to_cpp(std::cout, reg_exp.dfa(), "word_states"); std::string s0 = {}; std::string s1 = {(char)PV::ALetter}; std::string s2 = {(char)PV::ALetter, (char)PV::ALetter}; std::string s3 = {(char)PV::ALetter, (char)PV::ALetter, (char)PV::ALetter}; std::string s4 = {(char)PV::ALetter, (char)PV::Extend, (char)PV::ALetter, (char)PV::Numeric}; std::string s5 = {(char)PV::Katakana}; std::string s6 = {(char)PV::Katakana, (char)PV::Katakana}; std::string s7 = {(char)PV::Katakana, (char)PV::Katakana, (char)PV::Katakana}; std::string s8 = {(char)PV::Katakana, (char)PV::ExtendNumLet}; std::string s9 = {(char)PV::Katakana, (char)PV::ExtendNumLet, (char)PV::ExtendNumLet, (char)PV::Katakana}; std::string s10 = {(char)PV::Katakana, (char)PV::ExtendNumLet, (char)PV::Katakana, (char)PV::ExtendNumLet, (char)PV::Katakana}; std::string s11 = {(char)PV::ExtendNumLet, (char)PV::Katakana, (char)PV::ExtendNumLet, (char)PV::Katakana}; std::string s12 = {(char)PV::ALetter, (char)PV::Numeric, (char)PV::ALetter}; std::string s13 = {(char)PV::ExtendNumLet}; std::string s14 = {(char)PV::ExtendNumLet, (char)PV::ExtendNumLet}; std::string s15 = {(char)PV::Katakana, (char)PV::ALetter}; std::string s16 = {(char)PV::ALetter, (char)PV::Katakana}; std::string s17 = {(char)PV::Katakana, (char)PV::Numeric}; std::string s18 = {(char)PV::Numeric, (char)PV::Katakana}; std::string s19 = {(char)PV::Other, (char)PV::Extend}; std::string s20 = {(char)PV::MidNumLet, (char)PV::Format}; std::string s21 = {(char)PV::ALetter, (char)PV::MidLetter, (char)PV::ALetter}; // assert (check_aux(reg_exp.dfa(), s0, 'a')==false); assert (check_aux(reg_exp.dfa(), s1, 'a')==true); assert (check_aux(reg_exp.dfa(), s2, 'a')==true); assert (check_aux(reg_exp.dfa(), s3, 'a')==true); assert (check_aux(reg_exp.dfa(), s4, 'a')==true); assert (check_aux(reg_exp.dfa(), s5, 'a')==true); assert (check_aux(reg_exp.dfa(), s6, 'a')==true); assert (check_aux(reg_exp.dfa(), s7, 'a')==true); assert (check_aux(reg_exp.dfa(), s8, 'a')==true); assert (check_aux(reg_exp.dfa(), s9, 'a')==true); assert (check_aux(reg_exp.dfa(), s10, 'a')==true); assert (check_aux(reg_exp.dfa(), s11, 'a')==true); assert (check_aux(reg_exp.dfa(), s12, 'a')==true); assert (check_aux(reg_exp.dfa(), s13, 'a')==true); assert (check_aux(reg_exp.dfa(), s14, 'a')==true); assert (check_aux(reg_exp.dfa(), s15, 'a')==false); assert (check_aux(reg_exp.dfa(), s16, 'a')==false); assert (check_aux(reg_exp.dfa(), s17, 'a')==false); assert (check_aux(reg_exp.dfa(), s18, 'a')==false); assert (check_aux(reg_exp.dfa(), s19, 'a')==true); assert (check_aux(reg_exp.dfa(), s20, 'a')==true); assert (check_aux(reg_exp.dfa(), s21, 'a')==true); /* check_aux(reg_exp.dfa(), , true}; check_aux(reg_exp.dfa(), , true}, check_aux(reg_exp.dfa(), std::string({(char)PV::ALetter, (char)PV::Extend, (char)PV::ALetter, (char)PV::Numeric}, true} */ // std::string target = {(char)PV::ALetter, (char)PV::Extend, }; std::string target = {(char)PV::ALetter, (char)PV::Extend, (char)PV::ALetter, (char)PV::Numeric}; // std::string target = {(char)PV::ALetter, (char)PV::Numeric}; // CHECK(reg_exp.dfa(), target, true); std::cout << "end test5 " << std::endl; }