mirror of
https://github.com/clementine-player/Clementine
synced 2025-01-31 03:27:40 +01:00
parent
9e81f5e72b
commit
82b728528e
@ -105,7 +105,15 @@ bool Database::Like(const char* needle, const char* haystack) {
|
||||
query_cache_ = QString::fromUtf8(needle).section('%', 1, 1).split(' ');
|
||||
query_hash_ = hash;
|
||||
}
|
||||
|
||||
// In place decompose string as it's faster :-)
|
||||
QString b = QString::fromUtf8(haystack);
|
||||
QChar* data = b.data();
|
||||
for (int i = 0; i < b.length(); ++i) {
|
||||
if (data[i].decompositionTag() != QChar::NoDecomposition) {
|
||||
data[i] = data[i].decomposition()[0];
|
||||
}
|
||||
}
|
||||
foreach (const QString& query, query_cache_) {
|
||||
if (!b.contains(query, Qt::CaseInsensitive)) {
|
||||
return false;
|
||||
|
@ -65,6 +65,7 @@ class Database : public QObject {
|
||||
FRIEND_TEST(DatabaseTest, LikePerformance);
|
||||
FRIEND_TEST(DatabaseTest, LikeCacheInvalidated);
|
||||
FRIEND_TEST(DatabaseTest, LikeQuerySplit);
|
||||
FRIEND_TEST(DatabaseTest, LikeDecomposes);
|
||||
|
||||
// Do static initialisation like loading sqlite functions.
|
||||
static void StaticInit();
|
||||
|
@ -124,3 +124,10 @@ TEST_F(DatabaseTest, LikeQuerySplit) {
|
||||
EXPECT_FALSE(database_->Like("%foo bar%", "foobaz"));
|
||||
EXPECT_FALSE(database_->Like("%foo bar%", "baz"));
|
||||
}
|
||||
|
||||
TEST_F(DatabaseTest, LikeDecomposes) {
|
||||
EXPECT_TRUE(database_->Like("%Royksopp%", "Röyksopp"));
|
||||
EXPECT_FALSE(database_->Like("%Ryksopp%", "Röyksopp"));
|
||||
EXPECT_TRUE(database_->Like("%tiesto%", "DJ Tiësto"));
|
||||
EXPECT_FALSE(database_->Like("%tisto%", "DJ Tiësto"));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user