Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions cmake/FindIsoCodes.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,7 @@ if(NOT DEFINED ISOCODES_ISO639_JSON)
)
endif()

if(NOT DEFINED ISOCODES_ISO3166_JSON)
find_file(ISOCODES_ISO3166_JSON iso_3166-1.json
HINTS "${PC_ISOCODES_PREFIX}/share/iso-codes/json/"
)
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(IsoCodes DEFAULT_MSG ISOCODES_ISO639_JSON ISOCODES_ISO3166_JSON)
find_package_handle_standard_args(IsoCodes DEFAULT_MSG ISOCODES_ISO639_JSON)

mark_as_advanced(ISOCODES_ISO639_JSON ISOCODES_ISO3166_JSON)
mark_as_advanced(ISOCODES_ISO639_JSON)
1 change: 0 additions & 1 deletion config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#define FCITX_VERSION_STRING "@FCITX_VERSION@"

#define ISOCODES_ISO639_JSON "@ISOCODES_ISO639_JSON@"
#define ISOCODES_ISO3166_JSON "@ISOCODES_ISO3166_JSON@"
#define XKEYBOARDCONFIG_XKBBASE "@XKEYBOARDCONFIG_XKBBASE@"
#define DEFAULT_XKB_RULES "@DEFAULT_XKB_RULES@"
#define NO_PREEDIT_APPS "@NO_PREEDIT_APPS@"
Expand Down
34 changes: 1 addition & 33 deletions src/im/keyboard/isocodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,40 +99,8 @@ class IsoCodes639Parser
IsoCodes *that_;
};

class IsoCodes3166Parser
: public IsoCodesJsonParser<fcitxMakeMetaString("3166-1")> {
public:
IsoCodes3166Parser(IsoCodes *that) : that_(that) {}

void handle(json_object *entry) override {
json_object *alpha2 = json_object_object_get(entry, "alpha_2");
json_object *nameObj = json_object_object_get(entry, "name");
if (!nameObj || json_object_get_type(nameObj) != json_type_string) {
return;
}
// there must be alpha3
if (!alpha2 || json_object_get_type(alpha2) != json_type_string) {
return;
}
std::string alpha_2_code;
std::string name;
name.assign(json_object_get_string(nameObj),
json_object_get_string_len(nameObj));
alpha_2_code.assign(json_object_get_string(alpha2),
json_object_get_string_len(alpha2));
if (!name.empty() && !alpha_2_code.empty()) {
that_->iso3166.emplace(alpha_2_code, name);
}
}

private:
IsoCodes *that_;
};

void IsoCodes::read(const std::string &iso639, const std::string &iso3166) {
void IsoCodes::read(const std::string &iso639) {
IsoCodes639Parser parser639(this);
parser639.parse(iso639);
IsoCodes3166Parser parser3166(this);
parser3166.parse(iso3166);
}
} // namespace fcitx
5 changes: 1 addition & 4 deletions src/im/keyboard/isocodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ struct IsoCodes639Entry {

class IsoCodes {
friend class IsoCodes639Parser;
friend class IsoCodes3166Parser;

public:
void read(const std::string &iso639, const std::string &iso3166);
void read(const std::string &iso639);

const IsoCodes639Entry *entry(const std::string &name) const {
const auto *entry = findValue(iso6392B, name);
Expand All @@ -43,8 +42,6 @@ class IsoCodes {
std::vector<IsoCodes639Entry> iso639entires;
std::unordered_map<std::string, int> iso6392B;
std::unordered_map<std::string, int> iso6392T;

std::unordered_map<std::string, std::string> iso3166;
};
} // namespace fcitx

Expand Down
2 changes: 1 addition & 1 deletion src/im/keyboard/keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ KeyboardEngine::~KeyboardEngine() {}

std::vector<InputMethodEntry> KeyboardEngine::listInputMethods() {
IsoCodes isoCodes;
isoCodes.read(ISOCODES_ISO639_JSON, ISOCODES_ISO3166_JSON);
isoCodes.read(ISOCODES_ISO639_JSON);

std::vector<InputMethodEntry> result;
bool usExists = false;
Expand Down
2 changes: 1 addition & 1 deletion test/testisocodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ using namespace fcitx;

int main() {
IsoCodes isocodes;
isocodes.read(ISOCODES_ISO639_JSON, ISOCODES_ISO3166_JSON);
isocodes.read(ISOCODES_ISO639_JSON);
const auto *entry = isocodes.entry("eng");
FCITX_ASSERT(entry);
FCITX_ASSERT(entry->iso_639_1_code == "en");
Expand Down
Loading