mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
[account.cpp] refactor gnc_account_lookup_by_name
This commit is contained in:
parent
bebc366e88
commit
09e2e7613c
@ -2972,37 +2972,17 @@ gnc_account_get_descendants_sorted (const Account *account)
|
||||
return g_list_reverse (list);
|
||||
}
|
||||
|
||||
static gpointer
|
||||
is_acct_name (Account *account, gpointer user_data)
|
||||
{
|
||||
auto name {static_cast<gchar*>(user_data)};
|
||||
return (g_strcmp0 (name, xaccAccountGetName (account)) ? nullptr : account);
|
||||
}
|
||||
|
||||
Account *
|
||||
gnc_account_lookup_by_name (const Account *parent, const char * name)
|
||||
{
|
||||
AccountPrivate *cpriv, *ppriv;
|
||||
Account *child, *result;
|
||||
GList *node;
|
||||
|
||||
g_return_val_if_fail(GNC_IS_ACCOUNT(parent), NULL);
|
||||
g_return_val_if_fail(name, NULL);
|
||||
|
||||
/* first, look for accounts hanging off the current node */
|
||||
ppriv = GET_PRIVATE(parent);
|
||||
for (node = ppriv->children; node; node = node->next)
|
||||
{
|
||||
child = static_cast<Account*>(node->data);
|
||||
cpriv = GET_PRIVATE(child);
|
||||
if (g_strcmp0(cpriv->accountName, name) == 0)
|
||||
return child;
|
||||
}
|
||||
|
||||
/* if we are still here, then we haven't found the account yet.
|
||||
* Recursively search each of the child accounts next */
|
||||
for (node = ppriv->children; node; node = node->next)
|
||||
{
|
||||
child = static_cast<Account*>(node->data);
|
||||
result = gnc_account_lookup_by_name (child, name);
|
||||
if (result)
|
||||
return result;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return (Account*)gnc_account_foreach_descendant_until (parent, is_acct_name, (char*)name);
|
||||
}
|
||||
|
||||
Account *
|
||||
|
Loading…
Reference in New Issue
Block a user