Skip to content

Commit

Permalink
String: Added a method for checking for words in a string
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Nov 14, 2016
1 parent a121b90 commit 909b101
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions doomsday/sdk/libcore/include/de/data/string.h
Expand Up @@ -217,6 +217,8 @@ class DENG2_PUBLIC String : public QString
/// Extracts everything but the extension from string.
String fileNameAndPathWithoutExtension(QChar dirChar = '/') const;

bool containsWord(String const &word) const;

/**
* Compare two strings (case sensitive).
*
Expand Down
3 changes: 1 addition & 2 deletions doomsday/sdk/libcore/src/data/record.cpp
Expand Up @@ -625,9 +625,8 @@ Variable &Record::appendUniqueWord(String const &name, String const &word, Strin
{
DENG2_GUARD(d);

QRegExp re(QString("\\b%1\\b").arg(word));
String const value = gets(name, "");
if (re.indexIn(value) < 0)
if (!value.containsWord(word))
{
appendWord(name, word, separator);
}
Expand Down
10 changes: 10 additions & 0 deletions doomsday/sdk/libcore/src/data/string.cpp
Expand Up @@ -24,6 +24,7 @@

#include <QDir>
#include <QTextStream>
#include <QRegularExpression>
#include <QUrl> // percent encoding
#include <cstdio>
#include <cstdarg>
Expand Down Expand Up @@ -412,6 +413,15 @@ String String::fileNameAndPathWithoutExtension(QChar dirChar) const
return fileNamePath(dirChar) / fileNameWithoutExtension();
}

bool String::containsWord(String const &word) const
{
if (word.isEmpty())
{
return false;
}
return QRegularExpression(QString("\\b%1\\b").arg(word)).match(*this).hasMatch();
}

dint String::compareWithCase(String const &str) const
{
return compare(str, Qt::CaseSensitive);
Expand Down

0 comments on commit 909b101

Please sign in to comment.