Help: moved a util function to the only file in which it is used

This commit is contained in:
Charles Dang 2018-04-03 14:49:17 +11:00
parent bca6203bf4
commit 30455d52a2
3 changed files with 51 additions and 49 deletions

View file

@ -37,6 +37,57 @@ static lg::log_domain log_help("help");
namespace help
{
namespace
{
std::string make_unit_link(const std::string& type_id)
{
std::string link;
const unit_type* type = unit_types.find(type_id, unit_type::HELP_INDEXED);
if(!type) {
std::cerr << "Unknown unit type : " << type_id << "\n";
// Don't return a hyperlink (no page). Instead show the id (as hint)
link = type_id;
} else if(!type->hide_help()) {
std::string name = type->type_name();
std::string ref_id;
if(description_type(*type) == FULL_DESCRIPTION) {
const std::string section_prefix = type->show_variations_in_help() ? ".." : "";
ref_id = section_prefix + unit_prefix + type->id();
} else {
ref_id = unknown_unit_topic;
name += " (?)";
}
link = make_link(name, ref_id);
} // if hide_help then link is an empty string
return link;
}
std::vector<std::string> make_unit_links_list(const std::vector<std::string>& type_id_list, bool ordered)
{
std::vector<std::string> links_list;
for(const std::string& type_id : type_id_list) {
std::string unit_link = make_unit_link(type_id);
if(!unit_link.empty()) {
links_list.push_back(std::move(unit_link));
}
}
if(ordered) {
std::sort(links_list.begin(), links_list.end());
}
return links_list;
}
} // end anon namespace
topic_list generate_ability_topics(const bool sort_generated)
{
topic_list topics;

View file

@ -34,34 +34,6 @@ namespace help
/** Implementation helpers. */
namespace
{
std::string make_unit_link(const std::string& type_id)
{
std::string link;
const unit_type* type = unit_types.find(type_id, unit_type::HELP_INDEXED);
if(!type) {
std::cerr << "Unknown unit type : " << type_id << "\n";
// Don't return a hyperlink (no page). Instead show the id (as hint)
link = type_id;
} else if(!type->hide_help()) {
std::string name = type->type_name();
std::string ref_id;
if(description_type(*type) == FULL_DESCRIPTION) {
const std::string section_prefix = type->show_variations_in_help() ? ".." : "";
ref_id = section_prefix + unit_prefix + type->id();
} else {
ref_id = unknown_unit_topic;
name += " (?)";
}
link = make_link(name, ref_id);
} // if hide_help then link is an empty string
return link;
}
} // end anon namespace
bool string_less::operator()(const std::string& s1, const std::string& s2) const
@ -124,25 +96,6 @@ std::string escape(const std::string& s)
return utils::escape(s, "'\\");
}
std::vector<std::string> make_unit_links_list(const std::vector<std::string>& type_id_list, bool ordered)
{
std::vector<std::string> links_list;
for(const std::string& type_id : type_id_list) {
std::string unit_link = make_unit_link(type_id);
if(!unit_link.empty()) {
links_list.push_back(std::move(unit_link));
}
}
if(ordered) {
std::sort(links_list.begin(), links_list.end());
}
return links_list;
}
ter_data_cache load_terrain_types_data()
{
if(display* d = display::get_singleton()) {

View file

@ -76,8 +76,6 @@ inline std::string jump(const unsigned amount)
return formatter() << "<jump>amount=" << amount << "</jump>";
}
std::vector<std::string> make_unit_links_list(const std::vector<std::string>& type_id_list, bool ordered);
using ter_data_cache = std::shared_ptr<terrain_type_data>;
/// Load the appropriate terrain types data to use