mirror of
https://github.com/clementine-player/Clementine
synced 2024-12-18 12:28:31 +01:00
Tidy unicode length detection & add Cyrillic FTS test.
This commit is contained in:
parent
f544e28051
commit
b91a61c260
@ -129,15 +129,17 @@ int Database::FTSOpen(
|
||||
for (int i = 0; i < str.length(); ++i) {
|
||||
QChar c = data[i];
|
||||
ushort unicode = c.unicode();
|
||||
if (unicode >= 0x00 && unicode <= 0x007f) {
|
||||
if (unicode <= 0x007f) {
|
||||
offset += 1;
|
||||
} else if (unicode >= 0x0080 && unicode <= 0x07ff) {
|
||||
offset += 2;
|
||||
} else if (unicode >= 0x0800 && unicode <= 0xffff) {
|
||||
} else if (unicode >= 0x0800) {
|
||||
offset += 3;
|
||||
} else if (unicode >= 0x010000 && unicode <= 0x10ffff) {
|
||||
offset += 4;
|
||||
}
|
||||
// Unicode astral planes unsupported in Qt?
|
||||
/*else if (unicode >= 0x010000 && unicode <= 0x10ffff) {
|
||||
offset += 4;
|
||||
}*/
|
||||
|
||||
if (!data[i].isLetterOrNumber()) {
|
||||
// Token finished.
|
||||
|
@ -78,6 +78,7 @@ class Database : public QObject {
|
||||
FRIEND_TEST(DatabaseTest, FTSOpenParsesUTF8Input);
|
||||
FRIEND_TEST(DatabaseTest, FTSOpenParsesMultipleTokens);
|
||||
FRIEND_TEST(DatabaseTest, FTSCursorWorks);
|
||||
FRIEND_TEST(DatabaseTest, FTSOpenLeavesCyrillicQueries);
|
||||
|
||||
// Do static initialisation like loading sqlite functions.
|
||||
static void StaticInit();
|
||||
|
@ -181,6 +181,22 @@ TEST_F(DatabaseTest, FTSOpenParsesMultipleTokens) {
|
||||
EXPECT_EQ(13, tokens[1].end_offset);
|
||||
}
|
||||
|
||||
TEST_F(DatabaseTest, FTSOpenLeavesCyrillicQueries) {
|
||||
sqlite3_tokenizer_cursor* cursor = NULL;
|
||||
const char* query = "Снег";
|
||||
Database::FTSOpen(NULL, query, strlen(query), &cursor);
|
||||
ASSERT_TRUE(cursor);
|
||||
Database::UnicodeTokenizerCursor* real_cursor = reinterpret_cast<Database::UnicodeTokenizerCursor*>(cursor);
|
||||
QList<Database::Token> tokens = real_cursor->tokens;
|
||||
ASSERT_EQ(1, tokens.length());
|
||||
EXPECT_EQ(0, real_cursor->position);
|
||||
EXPECT_TRUE(real_cursor->current_utf8.isEmpty());
|
||||
|
||||
EXPECT_EQ(QString::fromUtf8("снег"), tokens[0].token);
|
||||
EXPECT_EQ(0, tokens[0].start_offset);
|
||||
EXPECT_EQ(strlen(query), tokens[0].end_offset);
|
||||
}
|
||||
|
||||
TEST_F(DatabaseTest, FTSCursorWorks) {
|
||||
sqlite3_tokenizer_cursor* cursor = NULL;
|
||||
Database::FTSOpen(NULL, "Röyksopp foo", 13, &cursor);
|
||||
|
Loading…
Reference in New Issue
Block a user