Skip to content

Commit dffebfe

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

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/skk.cpp

+13-5
Original file line numberDiff line numberDiff line change
@@ -501,18 +501,26 @@ void SkkEngine::loadDictionary() {
501501
continue;
502502
}
503503
if (mode == 1) {
504-
if (stringutils::endsWith(path, ".cdb")) {
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,
510+
path.substr(len));
511+
}
512+
if (stringutils::endsWith(realpath, ".cdb")) {
505513
SkkCdbDict *dict =
506-
skk_cdb_dict_new(path.data(), encoding.data(), nullptr);
514+
skk_cdb_dict_new(realpath.data(), encoding.data(), nullptr);
507515
if (dict) {
508-
SKK_DEBUG() << "Adding cdb dict: " << path;
516+
SKK_DEBUG() << "Adding cdb dict: " << realpath;
509517
dictionaries_.emplace_back(SKK_DICT(dict));
510518
}
511519
} else {
512520
SkkFileDict *dict = skk_file_dict_new(
513-
path.data(), encoding.data(), nullptr);
521+
realpath.data(), encoding.data(), nullptr);
514522
if (dict) {
515-
SKK_DEBUG() << "Adding file dict: " << path;
523+
SKK_DEBUG() << "Adding file dict: " << realpath;
516524
dictionaries_.emplace_back(SKK_DICT(dict));
517525
}
518526
}

0 commit comments

Comments
 (0)