Skip to content

Commit df1c487

Browse files
committed
interpret dictionary path starting with $XDG_DATA_DIRS/
1 parent 1c18d99 commit df1c487

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/skk.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -501,18 +501,25 @@ void SkkEngine::loadDictionary() {
501501
continue;
502502
}
503503
if (mode == 1) {
504-
if (stringutils::endsWith(path, ".cdb")) {
505-
SkkCdbDict *dict =
506-
skk_cdb_dict_new(path.data(), encoding.data(), nullptr);
504+
constexpr char xdgDataDirs[] = "$XDG_DATA_DIRS/";
505+
constexpr auto len = sizeof(xdgDataDirs) - 1;
506+
std::string realpath = path;
507+
if (stringutils::startsWith(path, xdgDataDirs)) {
508+
realpath = StandardPath::global().locate(
509+
StandardPath::Type::Data, path.substr(len));
510+
}
511+
if (stringutils::endsWith(realpath, ".cdb")) {
512+
SkkCdbDict *dict = skk_cdb_dict_new(
513+
realpath.data(), encoding.data(), nullptr);
507514
if (dict) {
508-
SKK_DEBUG() << "Adding cdb dict: " << path;
515+
SKK_DEBUG() << "Adding cdb dict: " << realpath;
509516
dictionaries_.emplace_back(SKK_DICT(dict));
510517
}
511518
} else {
512519
SkkFileDict *dict = skk_file_dict_new(
513-
path.data(), encoding.data(), nullptr);
520+
realpath.data(), encoding.data(), nullptr);
514521
if (dict) {
515-
SKK_DEBUG() << "Adding file dict: " << path;
522+
SKK_DEBUG() << "Adding file dict: " << realpath;
516523
dictionaries_.emplace_back(SKK_DICT(dict));
517524
}
518525
}

0 commit comments

Comments
 (0)