Skip to content

Commit

Permalink
interpret dictionary path starting with $XDG_DATA_DIRS/
Browse files Browse the repository at this point in the history
  • Loading branch information
eagleoflqj committed Nov 28, 2024
1 parent 1c18d99 commit dffebfe
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/skk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,18 +501,26 @@ void SkkEngine::loadDictionary() {
continue;
}
if (mode == 1) {
if (stringutils::endsWith(path, ".cdb")) {
constexpr char xdgDataDirs[] = "$XDG_DATA_DIRS/";
constexpr auto len = sizeof(xdgDataDirs) - 1;
std::string realpath = path;
if (stringutils::startsWith(path, xdgDataDirs)) {
realpath = StandardPath::global().locate(
StandardPath::Type::Data,
path.substr(len));
}
if (stringutils::endsWith(realpath, ".cdb")) {
SkkCdbDict *dict =
skk_cdb_dict_new(path.data(), encoding.data(), nullptr);
skk_cdb_dict_new(realpath.data(), encoding.data(), nullptr);
if (dict) {
SKK_DEBUG() << "Adding cdb dict: " << path;
SKK_DEBUG() << "Adding cdb dict: " << realpath;
dictionaries_.emplace_back(SKK_DICT(dict));
}
} else {
SkkFileDict *dict = skk_file_dict_new(
path.data(), encoding.data(), nullptr);
realpath.data(), encoding.data(), nullptr);
if (dict) {
SKK_DEBUG() << "Adding file dict: " << path;
SKK_DEBUG() << "Adding file dict: " << realpath;
dictionaries_.emplace_back(SKK_DICT(dict));
}
}
Expand Down

0 comments on commit dffebfe

Please sign in to comment.