本文整理汇总了C++中Language::get_modifier方法的典型用法代码示例。如果您正苦于以下问题:C++ Language::get_modifier方法的具体用法?C++ Language::get_modifier怎么用?C++ Language::get_modifier使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Language
的用法示例。
在下文中一共展示了Language::get_modifier方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
int
Language::match(const Language& lhs, const Language& rhs)
{
if (lhs.get_language() != rhs.get_language())
{
return 0;
}
else
{
static int match_tbl[3][3] = {
// modifier match, wildchard, miss
{ 9, 8, 5 }, // country match
{ 7, 6, 3 }, // country wildcard
{ 4, 2, 1 }, // country miss
};
int c;
if (lhs.get_country() == rhs.get_country())
c = 0;
else if (lhs.get_country().empty() || rhs.get_country().empty())
c = 1;
else
c = 2;
int m;
if (lhs.get_modifier() == rhs.get_modifier())
m = 0;
else if (lhs.get_modifier().empty() || rhs.get_modifier().empty())
m = 1;
else
m = 2;
return match_tbl[c][m];
}
}
示例2: main
int main(int argc, char** argv)
{
try
{
if (argc == 3 && strcmp(argv[1], "language-dir") == 0)
{
DictionaryManager dictionary_manager;
dictionary_manager.add_directory(argv[2]);
const std::set<Language>& languages = dictionary_manager.get_languages();
std::cout << "Number of languages: " << languages.size() << std::endl;
for (std::set<Language>::const_iterator i = languages.begin(); i != languages.end(); ++i)
{
const Language& language = *i;
std::cout << "Env: " << language.str() << std::endl
<< "Name: " << language.get_name() << std::endl
<< "Language: " << language.get_language() << std::endl
<< "Country: " << language.get_country() << std::endl
<< "Modifier: " << language.get_modifier() << std::endl
<< std::endl;
}
}
else if (argc == 3 && strcmp(argv[1], "language") == 0)
{
const char* language_cstr = argv[2];
Language language = Language::from_name(language_cstr);
if (language)
std::cout << "Env: " << language.str() << std::endl
<< "Name: " << language.get_name() << std::endl
<< "Language: " << language.get_language() << std::endl
<< "Country: " << language.get_country() << std::endl
<< "Modifier: " << language.get_modifier() << std::endl;
else
std::cout << "not found" << std::endl;
}
else if (argc == 4 && strcmp(argv[1], "translate") == 0)
{
const char* filename = argv[2];
const char* message = argv[3];
Dictionary dict;
read_dictionary(filename, dict);
std::cout << "TRANSLATION: \"\"\"" << dict.translate(message) << "\"\"\""<< std::endl;
}
else if (argc == 5 && strcmp(argv[1], "translate") == 0)
{
const char* filename = argv[2];
const char* context = argv[3];
const char* message = argv[4];
Dictionary dict;
read_dictionary(filename, dict);
std::cout << dict.translate_ctxt(context, message) << std::endl;
}
else if (argc == 6 && strcmp(argv[1], "translate") == 0)
{
const char* filename = argv[2];
const char* message_singular = argv[3];
const char* message_plural = argv[4];
int num = atoi(argv[5]);
Dictionary dict;
read_dictionary(filename, dict);
std::cout << dict.translate_plural(message_singular, message_plural, num) << std::endl;
}
else if (argc == 7 && strcmp(argv[1], "translate") == 0)
{
const char* filename = argv[2];
const char* context = argv[3];
const char* message_singular = argv[4];
const char* message_plural = argv[5];
int num = atoi(argv[6]);
Dictionary dict;
read_dictionary(filename, dict);
std::cout << dict.translate_ctxt_plural(context, message_singular, message_plural, num) << std::endl;
}
else if ((argc == 4 || argc == 5) && strcmp(argv[1], "directory") == 0)
{
const char* directory = argv[2];
const char* message = argv[3];
const char* language = (argc == 5) ? argv[4] : NULL;
DictionaryManager manager;
manager.add_directory(directory);
if (language)
{
Language lang = Language::from_name(language);
if (lang)
{
manager.set_language(lang);
}
else
{
std::cout << "Unknown language: " << language << std::endl;
exit(EXIT_FAILURE);
}
}
//.........这里部分代码省略.........