$ show fcitx/fcitx5-chinese-addons
This repository provides Chinese input method addons for the Fcitx5 input method framework. It implements Pinyin (including Shuangpin, fuzzy pinyin, stroke filtering, cloud pinyin, prediction) and table-based input methods (Wubi, Cangjie, Erbi, etc.) as Fcitx5 modules. The architecture follows a plugin/addon pattern, with engines handling key events, candidate generation, and text commit. Supporting modules handle punctuation, fullwidth characters, simplified/traditional Chinese conversion (via OpenCC), cloud pinyin (with pluggable backends like Google and Baidu), and pinyin helper (stroke lookup). GUI tools for custom phrase editing and dictionary management are included. The codebase is well-structured, uses modern C++17, and integrates tightly with Fcitx5's event and configuration systems. External dependencies include libime, Qt6 (for GUI), OpenCC, curl, nlohmann_json, and optionally Lua. The project is actively maintained with a comprehensive test suite.
The LLM identified 2 files worth highlighting for reuse:
A generic, thread-safe LRU cache implemented as a C++ template class. It uses a combination of a hash map and a doubly-linked list (via std::list) to provide O(1) get and put operations. The cache is parameterized by key and value types, with a configurable maximum size. It includes mutex-based thread safety and is header-only with no dependencies on Fcitx5 internals, making it easily extractable for use in other projects requiring a simple caching mechanism.
Defines a pure virtual interface for cloud pinyin backends, with methods for sending HTTP requests and parsing JSON responses. Concrete implementations (GoogleBackend, BaiduBackend) are provided in backend.cpp. The interface is clean and minimal, allowing easy addition of new backends. This pattern is reusable for any project needing pluggable network-based data sources, though it depends on curl and nlohmann_json for actual HTTP and JSON handling.