mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
[account.cpp] refactor gnc_account_lookup_by_code
This commit is contained in:
parent
09e2e7613c
commit
5698b67bf5
@ -2985,37 +2985,17 @@ gnc_account_lookup_by_name (const Account *parent, const char * name)
|
|||||||
return (Account*)gnc_account_foreach_descendant_until (parent, is_acct_name, (char*)name);
|
return (Account*)gnc_account_foreach_descendant_until (parent, is_acct_name, (char*)name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gpointer
|
||||||
|
is_acct_code (Account *account, gpointer user_data)
|
||||||
|
{
|
||||||
|
auto name {static_cast<gchar*>(user_data)};
|
||||||
|
return (g_strcmp0 (name, xaccAccountGetCode (account)) ? nullptr : account);
|
||||||
|
}
|
||||||
|
|
||||||
Account *
|
Account *
|
||||||
gnc_account_lookup_by_code (const Account *parent, const char * code)
|
gnc_account_lookup_by_code (const Account *parent, const char * code)
|
||||||
{
|
{
|
||||||
AccountPrivate *cpriv, *ppriv;
|
return (Account*)gnc_account_foreach_descendant_until (parent, is_acct_code, (char*)code);
|
||||||
Account *child, *result;
|
|
||||||
GList *node;
|
|
||||||
|
|
||||||
g_return_val_if_fail(GNC_IS_ACCOUNT(parent), NULL);
|
|
||||||
g_return_val_if_fail(code, 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->accountCode, code) == 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_code (child, code);
|
|
||||||
if (result)
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gpointer
|
static gpointer
|
||||||
|
Loading…
Reference in New Issue
Block a user