diff --git a/libgnucash/app-utils/gnc-option.hpp b/libgnucash/app-utils/gnc-option.hpp index a722686881..03a2dfe61f 100644 --- a/libgnucash/app-utils/gnc-option.hpp +++ b/libgnucash/app-utils/gnc-option.hpp @@ -119,6 +119,9 @@ enum GncOptionUIType static const char* commodity_scm_intro{"'(commodity-scm "}; +size_t constexpr classifier_size_max{50}; +size_t constexpr sort_tag_size_max{10}; + struct OptionClassifier { std::string m_section; diff --git a/libgnucash/app-utils/gnc-optiondb.cpp b/libgnucash/app-utils/gnc-optiondb.cpp index c4c7fe4d4e..7c66f05c60 100644 --- a/libgnucash/app-utils/gnc-optiondb.cpp +++ b/libgnucash/app-utils/gnc-optiondb.cpp @@ -124,13 +124,13 @@ GncOptionDB::set_option_from_ui(const char* section, const char* name, std::optional> -GncOptionDB::find_section(const char* section) +GncOptionDB::find_section(const std::string& section) { auto db_section = std::find_if( m_sections.begin(), m_sections.end(), - [section](GncOptionSection sect) -> bool + [§ion](GncOptionSection sect) -> bool { - return sect.first == std::string{section}; + return section.compare(0, classifier_size_max, sect.first) == 0; }); if (db_section == m_sections.end()) return std::nullopt; @@ -138,16 +138,17 @@ GncOptionDB::find_section(const char* section) } std::optional> -GncOptionDB::find_option(const char* section, const char* name) const +GncOptionDB::find_option(const std::string& section, const std::string& name) const { auto db_section = const_cast(this)->find_section(section); if (!db_section) return std::nullopt; auto db_opt = std::find_if( db_section->get().second.begin(), db_section->get().second.end(), - [name](GncOption& option) -> bool + [&name](GncOption& option) -> bool { - return option.get_name() == std::string{name}; + return name.compare(0, classifier_size_max - 1, + option.get_name()) == 0; }); if (db_opt == db_section->get().second.end()) return std::nullopt; diff --git a/libgnucash/app-utils/gnc-optiondb.hpp b/libgnucash/app-utils/gnc-optiondb.hpp index b8c515133d..8d6187400b 100644 --- a/libgnucash/app-utils/gnc-optiondb.hpp +++ b/libgnucash/app-utils/gnc-optiondb.hpp @@ -83,13 +83,13 @@ public: // void set_selectable(const char* section, const char* name); void make_internal(const char* section, const char* name); void commit(); - std::optional> find_section(const char* section); - std::optional> find_option(const char* section, const char* name) { + std::optional> find_section(const std::string& section); + std::optional> find_option(const std::string& section, const std::string& name) { return static_cast(*this).find_option(section, name); } - std::optional> find_option(const char* section, const char* name) const; private: std::ostream& serialize_option_scheme(std::ostream& oss, + std::optional> find_option(const std::string& section, const std::string& name) const; const char* option_prolog, const char* section, const char* name) const noexcept; std::ostream& serialize_option_key_value(std::ostream& oss,