* Given a name of setting, return a setting description from the table. * @param name Name of the setting to return a setting description of. * @param settings Table to look in for the setting. * @return Pointer to the setting description of setting \a name if it can be found, * \c nullptr indicates failure to obtain the description. */
| 1638 | * \c nullptr indicates failure to obtain the description. |
| 1639 | */ |
| 1640 | static const SettingDesc *GetSettingFromName(std::string_view name, const SettingTable &settings) |
| 1641 | { |
| 1642 | /* First check all full names */ |
| 1643 | for (auto &desc : settings) { |
| 1644 | const SettingDesc *sd = GetSettingDesc(desc); |
| 1645 | if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue; |
| 1646 | if (sd->GetName() == name) return sd; |
| 1647 | } |
| 1648 | |
| 1649 | /* Then check the shortcut variant of the name. */ |
| 1650 | std::string short_name_suffix = std::string{ "." }.append(name); |
| 1651 | for (auto &desc : settings) { |
| 1652 | const SettingDesc *sd = GetSettingDesc(desc); |
| 1653 | if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue; |
| 1654 | if (sd->GetName().ends_with(short_name_suffix)) return sd; |
| 1655 | } |
| 1656 | |
| 1657 | return nullptr; |
| 1658 | } |
| 1659 | |
| 1660 | /** |
| 1661 | * Get the SaveLoad for all settings in the settings table. |
no test coverage detected