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