mirror of
https://github.com/Dushistov/sdcv.git
synced 2025-12-18 02:31:56 +00:00
fix portability issue in PR #20 , plus simplify code
This commit is contained in:
@@ -811,7 +811,8 @@ namespace {
|
||||
}
|
||||
}
|
||||
|
||||
bool SynFile::load(const std::string& url, gulong wc) {
|
||||
bool SynFile::load(const std::string &url, gulong wc)
|
||||
{
|
||||
struct stat stat_buf;
|
||||
if (!stat(url.c_str(), &stat_buf)) {
|
||||
MapFile syn;
|
||||
@@ -822,12 +823,10 @@ bool SynFile::load(const std::string& url, gulong wc) {
|
||||
// each entry in a syn-file is:
|
||||
// - 0-terminated string
|
||||
// 4-byte index into .dict file in network byte order
|
||||
gchar *lower_string = g_utf8_casefold(current, -1);
|
||||
std::string synonym(lower_string);
|
||||
g_free(lower_string);
|
||||
glib::CharStr lower_string{g_utf8_casefold(current, -1)};
|
||||
std::string synonym{get_impl(lower_string)};
|
||||
current += synonym.length() + 1;
|
||||
unsigned int idx = * reinterpret_cast<const unsigned int*>(current);
|
||||
idx = g_ntohl(idx);
|
||||
const guint32 idx = g_ntohl(get_uint32(current));
|
||||
current += sizeof(idx);
|
||||
synonyms[synonym] = idx;
|
||||
}
|
||||
@@ -837,23 +836,19 @@ bool SynFile::load(const std::string& url, gulong wc) {
|
||||
}
|
||||
}
|
||||
|
||||
bool SynFile::lookup(const char *str, glong &idx) {
|
||||
gchar *lower_string = g_utf8_casefold(str, -1);
|
||||
auto it = synonyms.find(lower_string);
|
||||
bool SynFile::lookup(const char *str, glong &idx)
|
||||
{
|
||||
glib::CharStr lower_string{g_utf8_casefold(str, -1)};
|
||||
auto it = synonyms.find(get_impl(lower_string));
|
||||
if (it != synonyms.end()) {
|
||||
g_free(lower_string);
|
||||
idx = it->second;
|
||||
return true;
|
||||
}
|
||||
g_free(lower_string);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Dict::Lookup(const char *str, glong &idx) {
|
||||
if(syn_file->lookup(str, idx)) {
|
||||
return true;
|
||||
}
|
||||
return idx_file->lookup(str, idx);
|
||||
return syn_file->lookup(str, idx) || idx_file->lookup(str, idx);
|
||||
}
|
||||
|
||||
bool Dict::load(const std::string& ifofilename)
|
||||
|
||||
Reference in New Issue
Block a user