Hello,
1) Is there any QString function equivalent to
std::string::find_first_of(const std::string & str, 0);
std::string::find_first_of(const std::string & str, 0);
To copy to clipboard, switch view to plain text mode
?
I want only 'true' or 'false' return value. I don't want position.
2) Yes, I know there are QRegExp, but I want fastest solution.
3) This is my code:
{
//return true if text not contains any of char in chars
QString::const_iterator it
= text.
constBegin();
QString::const_iterator end
= text.
constEnd();
while(it != end)
{
if(chars.contains(*it) == false)
return true;
++it;
}
return false;
}
bool find_first_not_of(const QString & chars, const QString & text)
{
//return true if text not contains any of char in chars
QString::const_iterator it = text.constBegin();
QString::const_iterator end = text.constEnd();
while(it != end)
{
if(chars.contains(*it) == false)
return true;
++it;
}
return false;
}
To copy to clipboard, switch view to plain text mode
This is code with QRegExp:
bool reg_find_first_not_of
(const QString & chars,
const QString & text
) {
return !r.exactMatch(text);
}
bool reg_find_first_not_of(const QString & chars, const QString & text)
{
const QRegExp r("[" + QRegExp::escape(chars) + "]+");
return !r.exactMatch(text);
}
To copy to clipboard, switch view to plain text mode
Which code is faster?
Bookmarks