Skip to content

Commit

Permalink
Get rid of fcitx::getline usage
Browse files Browse the repository at this point in the history
  • Loading branch information
wengxt committed Feb 7, 2025
1 parent 808d5ab commit 51fe587
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.6)
# The Project Name
project(fcitx5-kkc VERSION 5.1.6)

set(REQUIRED_FCITX_VERSION 5.1.12)
set(REQUIRED_FCITX_VERSION 5.1.13)
find_package(ECM REQUIRED 1.0.0)
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
include(FeatureSummary)
Expand Down
18 changes: 8 additions & 10 deletions src/kkc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <cstring>
#include <fcitx-config/iniparser.h>
#include <fcitx-utils/capabilityflags.h>
#include <fcitx-utils/fdstreambuf.h>
#include <fcitx-utils/fs.h>
#include <fcitx-utils/i18n.h>
#include <fcitx-utils/key.h>
Expand All @@ -39,6 +40,7 @@
#include <fcntl.h>
#include <glib-object.h>
#include <glib.h>
#include <istream>
#include <libkkc/libkkc.h>
#include <memory>
#include <stdexcept>
Expand Down Expand Up @@ -590,20 +592,16 @@ void KkcEngine::loadDictionary() {
kkc_dictionary_list_clear(dictionaries_.get());
auto file = StandardPath::global().open(StandardPath::Type::PkgData,
"kkc/dictionary_list", O_RDONLY);
if (file.fd() < 0) {
if (!file.isValid()) {
return;
}
UniqueFilePtr fp(fdopen(file.fd(), "r"));
if (!fp) {
return;
}
file.release();

UniqueCPtr<char> buf;
size_t len = 0;
IFDStreamBuf buf(file.fd());
std::istream in(&buf);
std::string line;

while (getline(buf, &len, fp.get()) != -1) {
auto tokens = stringutils::split(stringutils::trim(buf.get()), ",");
while (std::getline(in, line)) {
auto tokens = stringutils::split(stringutils::trimView(line), ",");

if (tokens.size() < 3) {
continue;
Expand Down

0 comments on commit 51fe587

Please sign in to comment.