Changeset View
Changeset View
Standalone View
Standalone View
source/third_party/tinygettext/src/dictionary_manager.cpp
Show First 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
DictionaryManager::DictionaryManager(const std::string& charset_) : | DictionaryManager::DictionaryManager(const std::string& charset_) : | ||||
dictionaries(), | dictionaries(), | ||||
search_path(), | search_path(), | ||||
charset(charset_), | charset(charset_), | ||||
use_fuzzy(true), | use_fuzzy(true), | ||||
current_language(), | current_language(), | ||||
current_dict(0), | current_dict(nullptr), | ||||
empty_dict(), | empty_dict(), | ||||
filesystem(new UnixFileSystem) | filesystem(new UnixFileSystem) | ||||
{ | { | ||||
} | } | ||||
DictionaryManager::~DictionaryManager() | DictionaryManager::~DictionaryManager() | ||||
{ | { | ||||
for(Dictionaries::iterator i = dictionaries.begin(); i != dictionaries.end(); ++i) | for(Dictionaries::iterator i = dictionaries.begin(); i != dictionaries.end(); ++i) | ||||
{ | { | ||||
delete i->second; | delete i->second; | ||||
} | } | ||||
} | } | ||||
void | void | ||||
DictionaryManager::clear_cache() | DictionaryManager::clear_cache() | ||||
{ | { | ||||
for(Dictionaries::iterator i = dictionaries.begin(); i != dictionaries.end(); ++i) | for(Dictionaries::iterator i = dictionaries.begin(); i != dictionaries.end(); ++i) | ||||
{ | { | ||||
delete i->second; | delete i->second; | ||||
} | } | ||||
dictionaries.clear(); | dictionaries.clear(); | ||||
current_dict = 0; | current_dict = nullptr; | ||||
} | } | ||||
Dictionary& | Dictionary& | ||||
DictionaryManager::get_dictionary() | DictionaryManager::get_dictionary() | ||||
{ | { | ||||
if (current_dict) | if (current_dict) | ||||
{ | { | ||||
return *current_dict; | return *current_dict; | ||||
▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | for (SearchPath::reverse_iterator p = search_path.rbegin(); p != search_path.rend(); ++p) | ||||
} | } | ||||
if (!best_filename.empty()) | if (!best_filename.empty()) | ||||
{ | { | ||||
std::string pofile = *p + "/" + best_filename; | std::string pofile = *p + "/" + best_filename; | ||||
try | try | ||||
{ | { | ||||
std::unique_ptr<std::istream> in = filesystem->open_file(pofile); | std::unique_ptr<std::istream> in = filesystem->open_file(pofile); | ||||
if (!in.get()) | if (!in) | ||||
{ | { | ||||
log_error << "error: failure opening: " << pofile << std::endl; | log_error << "error: failure opening: " << pofile << std::endl; | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
POParser::parse(pofile, *in, *dict); | POParser::parse(pofile, *in, *dict); | ||||
} | } | ||||
} | } | ||||
Show All 35 Lines | |||||
} | } | ||||
void | void | ||||
DictionaryManager::set_language(const Language& language) | DictionaryManager::set_language(const Language& language) | ||||
{ | { | ||||
if (current_language != language) | if (current_language != language) | ||||
{ | { | ||||
current_language = language; | current_language = language; | ||||
current_dict = 0; | current_dict = nullptr; | ||||
} | } | ||||
} | } | ||||
Language | Language | ||||
DictionaryManager::get_language() const | DictionaryManager::get_language() const | ||||
{ | { | ||||
return current_language; | return current_language; | ||||
} | } | ||||
Show All 14 Lines | |||||
bool | bool | ||||
DictionaryManager::get_use_fuzzy() const | DictionaryManager::get_use_fuzzy() const | ||||
{ | { | ||||
return use_fuzzy; | return use_fuzzy; | ||||
} | } | ||||
void | void | ||||
DictionaryManager::add_directory(const std::string& pathname) | DictionaryManager::add_directory(const std::string& pathname, bool precedence /* = false */) | ||||
{ | { | ||||
clear_cache(); // adding directories invalidates cache | clear_cache(); // adding directories invalidates cache | ||||
if (precedence) | |||||
search_path.push_front(pathname); | |||||
else | |||||
search_path.push_back(pathname); | search_path.push_back(pathname); | ||||
} | } | ||||
void | void | ||||
DictionaryManager::remove_directory(const std::string& pathname) | |||||
{ | |||||
SearchPath::iterator it = std::find(search_path.begin(), search_path.end(), pathname); | |||||
if (it != search_path.end()) | |||||
{ | |||||
clear_cache(); // removing directories invalidates cache | |||||
search_path.erase(it); | |||||
} | |||||
} | |||||
void | |||||
DictionaryManager::set_filesystem(std::unique_ptr<FileSystem> filesystem_) | DictionaryManager::set_filesystem(std::unique_ptr<FileSystem> filesystem_) | ||||
{ | { | ||||
filesystem = std::move(filesystem_); | filesystem = std::move(filesystem_); | ||||
} | } | ||||
// ---------------------------------------------------------------------------- | // ---------------------------------------------------------------------------- | ||||
/** This function converts a .po filename (e.g. zh_TW.po) into a language | /** This function converts a .po filename (e.g. zh_TW.po) into a language | ||||
* specification (zh_TW). On case insensitive file systems (think windows) | * specification (zh_TW). On case insensitive file systems (think windows) | ||||
* the filename and therefore the country specification is lower case | * the filename and therefore the country specification is lower case | ||||
Show All 36 Lines |
Wildfire Games · Phabricator