Skip to content

Commit 53cf371

Browse files
eagleoflqjwengxt
andauthored
interpret dictionary path starting with $XDG_DATA_DIRS/ (#17)
Co-authored-by: Weng Xuetian <[email protected]>
1 parent 0bdb0df commit 53cf371

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

.github/workflows/check.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,14 @@ jobs:
4747
uses: actions/cache@v4
4848
with:
4949
path: 'fcitx5/**/*.tar.*'
50-
key: ${{ runner.os }}-${{ hashFiles('fcitx5/src/modules/spell/CMakeLists.txt')
51-
}}
50+
key: ${{ runner.os }}-${{ hashFiles('fcitx5/src/modules/spell/CMakeLists.txt') }}
5251
- name: Build and Install fcitx5
5352
uses: fcitx/github-actions@cmake
5453
with:
5554
path: fcitx5
5655
cmake-option: >-
5756
-DENABLE_KEYBOARD=Off -DENABLE_X11=Off -DENABLE_WAYLAND=Off -DENABLE_ENCHANT=Off
58-
-DENABLE_DBUS=Off -DENABLE_SERVER=Off -DENABLE_EMOJI=Off -DUSE_SYSTEMD=Off
57+
-DENABLE_DBUS=Off -DENABLE_SERVER=Off -DENABLE_EMOJI=Off -DUSE_SYSTEMD=Off -DENABLE_TEST=Off
5958
- uses: actions/checkout@v4
6059
with:
6160
repository: fcitx/fcitx5-qt

src/skk.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,12 @@ void SkkEngine::loadDictionary() {
534534
continue;
535535
}
536536
if (mode == 1) {
537+
std::string_view partialpath = path;
538+
if (stringutils::consumePrefix(partialpath,
539+
"$XDG_DATA_DIRS/")) {
540+
path = StandardPath::global().locate(
541+
StandardPath::Type::Data, std::string(partialpath));
542+
}
537543
if (stringutils::endsWith(path, ".cdb")) {
538544
SkkCdbDict *dict =
539545
skk_cdb_dict_new(path.data(), encoding.data(), nullptr);
@@ -550,19 +556,18 @@ void SkkEngine::loadDictionary() {
550556
}
551557
}
552558
} else {
553-
constexpr char configDir[] = "$FCITX_CONFIG_DIR/";
554-
constexpr auto len = sizeof(configDir) - 1;
555-
std::string realpath = path;
556-
if (stringutils::startsWith(path, configDir)) {
557-
realpath = stringutils::joinPath(
559+
std::string_view partialpath = path;
560+
if (stringutils::consumePrefix(partialpath,
561+
"$FCITX_CONFIG_DIR/")) {
562+
path = stringutils::joinPath(
558563
StandardPath::global().userDirectory(
559564
StandardPath::Type::PkgData),
560-
path.substr(len));
565+
partialpath);
561566
}
562-
SkkUserDict *userdict = skk_user_dict_new(
563-
realpath.data(), encoding.data(), nullptr);
567+
SkkUserDict *userdict =
568+
skk_user_dict_new(path.data(), encoding.data(), nullptr);
564569
if (userdict) {
565-
SKK_DEBUG() << "Adding user dict: " << realpath;
570+
SKK_DEBUG() << "Adding user dict: " << path;
566571
dictionaries_.emplace_back(SKK_DICT(userdict));
567572
}
568573
}

0 commit comments

Comments
 (0)