Skip to content

Commit

Permalink
Help: moved a util function to the only file in which it is used
Browse files Browse the repository at this point in the history
  • Loading branch information
Vultraz authored and CelticMinstrel committed Oct 24, 2018
1 parent a638e8c commit 0a39473
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 49 deletions.
51 changes: 51 additions & 0 deletions src/help/topic_generators.cpp
Expand Up @@ -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;
Expand Down
47 changes: 0 additions & 47 deletions src/help/utils.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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()) {
Expand Down
2 changes: 0 additions & 2 deletions src/help/utils.hpp
Expand Up @@ -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
Expand Down

0 comments on commit 0a39473

Please sign in to comment.