File indexing completed on 2024-04-28 05:38:44
0001 #include <QtCore/QRegularExpression> 0002 #include <QtCore/QString> 0003 0004 void test() 0005 { 0006 if (QString("abc").contains(QRegularExpression("[a-z]"))) { // Warn 0007 } 0008 0009 QString h = "hello"; 0010 auto c = h.indexOf(QRegularExpression("[hel]"), 0); // Warn 0011 0012 QRegularExpression e("[a-z]"); 0013 auto r = h.indexOf(e); // Warn 0014 0015 static const QRegularExpression staticRegex("[a-z]"); 0016 auto nr = h.indexOf(staticRegex); // Ok 0017 0018 bool empty = QString().isEmpty(); 0019 0020 h.lastIndexOf(QRegularExpression("[hel]")); // Warn 0021 h.lastIndexOf(e); // Warn 0022 h.lastIndexOf(staticRegex); // Ok 0023 0024 h.count(QRegularExpression("[hel]")); // Warn 0025 h.count(e); // Warn 0026 h.count(staticRegex); // Ok 0027 0028 h.replace(QRegularExpression("[hel]"), QString()); // Warn 0029 h.replace(e, QString()); // Warn 0030 h.replace(staticRegex, QString()); // Ok 0031 0032 h.remove(QRegularExpression("[hel]")); // Warn 0033 h.remove(e); // Warn 0034 h.remove(staticRegex); // Ok 0035 0036 h.section(QRegularExpression("[hel]"), 0); // Warn 0037 h.section(e, 0); // Warn 0038 h.section(staticRegex, 0); // Ok 0039 0040 h.split(QRegularExpression("[hel]")); // Warn 0041 h.split(e); // Warn 0042 h.split(staticRegex); // Ok 0043 0044 QStringList strList; 0045 0046 strList.indexOf(e); // Warn 0047 strList.indexOf(staticRegex); // Ok 0048 0049 strList.lastIndexOf(e); // Warn 0050 strList.lastIndexOf(staticRegex); // Ok 0051 0052 QString regexStr = "[abc]"; 0053 h.contains(QRegularExpression(regexStr)); // Warn 0054 0055 { 0056 QRegularExpression reg(regexStr); 0057 h.contains(reg); // Warn 0058 } 0059 { 0060 static const QRegularExpression reg(regexStr); 0061 h.contains(reg); // Ok 0062 } 0063 } 0064 0065 void test1(const QString ®ex, QString toCheck) 0066 { 0067 QRegularExpression re(regex); 0068 toCheck.contains(re); // Ok 0069 } 0070 0071 void test2(const QStringList ®exes, QString toCheck) 0072 { 0073 for (const auto ®ix : regexes) { 0074 toCheck.contains(QRegularExpression(regix)); // Ok, no warn 0075 } 0076 } 0077 0078 void test_nocrash() 0079 { 0080 QRegularExpression re; 0081 QString s; 0082 s.contains(re); 0083 } 0084 0085 #include <QtCore/QVariant> 0086 void test_qregexmatch(QString selectedText) 0087 { 0088 QRegularExpression weekRE("(?<week>"); 0089 auto match1 = weekRE.match(selectedText); 0090 auto match2 = weekRE.globalMatch(selectedText); 0091 0092 auto m1 = QRegularExpression("[123]").match(selectedText); 0093 auto m2 = QRegularExpression("[123]").globalMatch(selectedText); 0094 0095 QVariant v; 0096 v.toRegularExpression().match(selectedText); // No Warn 0097 } 0098 0099 extern QString someText(); 0100 void test_qregexmatch_rvalueString(QString s) 0101 { 0102 // XValue + RValue arg 0103 QString text; 0104 QRegularExpression(someText()).match(text); // Ok 0105 0106 // LValue + RValue arg 0107 QRegularExpression re(someText()); 0108 re.match(text); 0109 0110 QRegularExpression re1("^" + someText()); 0111 re1.match(text); 0112 0113 QRegularExpression re2("^" + s); 0114 re2.match(text); 0115 0116 QRegularExpression re3((QString(s))); 0117 re3.match(text); 0118 } 0119 0120 void testArgs() 0121 { 0122 { 0123 QString("bla").contains(QRegularExpression(QString("test%1").arg("123"))); // OK 0124 } 0125 { 0126 QRegularExpression reg(QString("test%1").arg("123")); 0127 QString().contains(reg); // OK 0128 } 0129 { 0130 QString pattern = QString("test%1").arg("123"); 0131 QRegularExpression reg(pattern); 0132 QString().contains(reg); // OK 0133 } 0134 { 0135 QString pattern = QString("someteststring").mid(1, 2); 0136 QRegularExpression reg(pattern); 0137 QString().contains(reg); // OK 0138 } 0139 }