Skip to content

Commit c63db36

Browse files
committed
Rename string_equal_charptr to operator==(const std::string&, const char*)
Much prettier and more idiomatic as well as being a lot less typing.
1 parent 0106176 commit c63db36

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

libgnucash/app-utils/gnc-optiondb.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ auto constexpr stream_max = std::numeric_limits<std::streamsize>::max();
3333
GncOptionDB::GncOptionDB() : m_default_section{std::nullopt} {}
3434

3535
GncOptionDB::GncOptionDB(QofBook* book) : GncOptionDB() {}
36+
static bool
37+
operator==(const std::string& str, const char* cstr)
38+
{
39+
return strcmp(str.c_str(), cstr) == 0;
40+
}
3641

3742
void
3843
GncOptionDB::save_to_book(QofBook* book, bool do_clear) const
@@ -377,23 +382,14 @@ unquote_scheme_string(const std::string& str)
377382
return str;
378383
}
379384

380-
static inline bool
381-
string_equal_charptr(const std::string& str, const char* chars)
382-
{
383-
if (!chars || str.empty() || strlen(chars) != str.size())
384-
return false;
385-
return strcmp(str.c_str(), chars) == 0;
386-
}
387-
388385
static std::optional<std::reference_wrapper<const SchemeId>>
389386
find_form(const SchemeId& toplevel, IdentType type, const char* name)
390387
{
391-
if (toplevel.m_type == type &&
392-
string_equal_charptr(toplevel.m_name.c_str(), name))
388+
if (toplevel.m_type == type && toplevel.m_name == name)
393389
return std::ref(toplevel);
394390
for (const auto& id : toplevel.m_ids)
395391
{
396-
if (id.m_type == type && string_equal_charptr(id.m_name.c_str(), name))
392+
if (id.m_type == type && id.m_name == name)
397393
return std::ref(id);
398394
auto child{find_form(id, type, name)};
399395
if (child)

0 commit comments

Comments
 (0)