GnuCash  5.0
Files | Data Structures | Macros | Typedefs | Enumerations | Functions
Utility functions for the GnuCash GUI

Files

file  gnc-ui-util.h
 utility functions for the GnuCash UI
 

Data Structures

struct  GNCPrintAmountInfo
 

Macros

#define GNC_PREFS_GROUP_OPEN_SAVE   "dialogs.open-save"
 
#define GNC_PREFS_GROUP_EXPORT   "dialogs.export-accounts"
 
#define GNC_PREFS_GROUP_REPORT   "dialogs.report"
 
#define GNC_PREF_AUTO_DECIMAL_POINT   "auto-decimal-point"
 
#define GNC_PREF_AUTO_DECIMAL_PLACES   "auto-decimal-places"
 
#define WLINK   'w'
 
#define FLINK   'f'
 

Typedefs

typedef QofSession *(* QofSessionCB) (void)
 

Enumerations

enum  GNCEquityType { EQUITY_OPENING_BALANCE, EQUITY_RETAINED_EARNINGS, NUM_EQUITY_TYPES }
 

Functions

gchar * gnc_normalize_account_separator (const gchar *separator)
 
gboolean gnc_reverse_balance (const Account *account)
 
void gnc_set_use_equity_type_opening_balance_account (QofBook *book)
 
gboolean gnc_using_equity_type_opening_balance_account (QofBook *book)
 
gchar * gnc_get_default_directory (const gchar *section)
 
void gnc_set_default_directory (const gchar *section, const gchar *directory)
 
QofBook * gnc_get_current_book (void)
 
gboolean gnc_is_new_book (void)
 
void gnc_set_current_book_tax_name_type (gboolean name_changed, const gchar *tax_name, gboolean type_changed, const gchar *tax_type)
 
const gchar * gnc_get_current_book_tax_name (void)
 
const gchar * gnc_get_current_book_tax_type (void)
 
void gnc_book_option_num_field_source_change_cb (gboolean num_action)
 Calls gnc_book_option_num_field_source_change to initiate registered callbacks when num_field_source book option changes so that registers/reports can update themselves; sets feature flag.
 
Accountgnc_get_current_root_account (void)
 
gnc_commodity_table * gnc_get_current_commodities (void)
 
gchar * gnc_get_account_name_for_register (const Account *account)
 Get either the full name of the account or the simple name, depending on the configuration parameter general/register/show_leaf_account_names. More...
 
Accountgnc_account_lookup_for_register (const Account *base_account, const gchar *name)
 Retrieve the account matching the given name starting from the descendants of base_account. More...
 
gchar * gnc_get_account_name_for_split_register (const Account *account, gboolean show_leaf_accounts)
 Get either the full name of the account or the simple name, depending on the show_leaf_accounts. More...
 
const char * gnc_get_reconcile_str (char reconciled_flag)
 
const char * gnc_get_reconcile_valid_flags (void)
 
const char * gnc_get_reconcile_flag_order (void)
 
const char * gnc_get_doclink_valid_flags (void)
 Get a string containing documentation link valid flags. More...
 
const char * gnc_get_doclink_flag_order (void)
 Get a string containing document link flag order. More...
 
const char * gnc_get_doclink_str (char link_flag)
 Get a string representing the document link type. More...
 
Accountgnc_find_or_create_equity_account (Account *root, GNCEquityType equity_type, gnc_commodity *currency)
 
gboolean gnc_account_create_opening_balance (Account *account, gnc_numeric balance, time64 date, QofBook *book)
 
gnc_commodity * gnc_locale_default_currency_nodefault (void)
 Returns the default currency of the current locale, or NULL if no sensible currency could be identified from the locale. More...
 
gnc_commodity * gnc_locale_default_currency (void)
 Returns the default currency of the current locale. More...
 
gnc_commodity * gnc_default_currency (void)
 Return the default currency set by the user. More...
 
gnc_commodity * gnc_account_or_default_currency (const Account *account, gboolean *currency_from_account_found)
 Returns a gnc_commodity that is a currency, suitable for being a Transaction's currency. More...
 
gnc_commodity * gnc_default_report_currency (void)
 Return the default currency for use in reports, as set by the user. More...
 
GNCPrintAmountInfo gnc_default_print_info (gboolean use_symbol)
 
GNCPrintAmountInfo gnc_commodity_print_info (const gnc_commodity *commodity, gboolean use_symbol)
 
GNCPrintAmountInfo gnc_account_print_info (const Account *account, gboolean use_symbol)
 
GNCPrintAmountInfo gnc_split_amount_print_info (Split *split, gboolean use_symbol)
 
GNCPrintAmountInfo gnc_price_print_info (const gnc_commodity *curr, gboolean use_symbol)
 
GNCPrintAmountInfo gnc_share_print_info_places (int decplaces)
 
GNCPrintAmountInfo gnc_default_share_print_info (void)
 
GNCPrintAmountInfo gnc_default_price_print_info (const gnc_commodity *curr)
 
GNCPrintAmountInfo gnc_integral_print_info (void)
 
const char * xaccPrintAmount (gnc_numeric val, GNCPrintAmountInfo info)
 Make a string representation of a gnc_numeric. More...
 
int xaccSPrintAmount (char *buf, gnc_numeric val, GNCPrintAmountInfo info)
 Make a string representation of a gnc_numeric. More...
 
const gchar * printable_value (gdouble val, gint denom)
 
gchar * number_to_words (gdouble val, gint64 denom)
 
gchar * numeric_to_words (gnc_numeric val)
 
gboolean xaccParseAmount (const char *in_str, gboolean monetary, gnc_numeric *result, char **endstr)
 Parses in_str to obtain a numeric result. More...
 
gboolean xaccParseAmountExtended (const char *in_str, gboolean monetary, gunichar negative_sign, gunichar decimal_point, gunichar group_separator, const char *ignore_list, gnc_numeric *result, char **endstr)
 Converts a string to a gnc_numeric. More...
 
gboolean xaccParseAmountImport (const char *in_str, gboolean monetary, gnc_numeric *result, char **endstr, gboolean skip)
 Similar to xaccParseAmount, but with two differences. More...
 
gboolean xaccParseAmountExtImport (const char *in_str, gboolean monetary, gunichar negative_sign, gunichar decimal_point, gunichar group_separator, const char *ignore_list, gnc_numeric *result, char **endstr)
 Similar to xaccParseAmountExtended, but will not automatically set a decimal point, regardless of what the user has set for this option. More...
 
const char * gnc_print_amount_with_bidi_ltr_isolate (gnc_numeric val, GNCPrintAmountInfo info)
 Make a string representation of a gnc_numeric. More...
 
gchar * gnc_wrap_text_with_bidi_ltr_isolate (const char *text)
 This function helps with GTK's use of 'Unicode Bidirectional Text Algorithm'. More...
 
void gnc_ui_util_init (void)
 
void gnc_ui_util_remove_registered_prefs (void)
 
gchar * gnc_filter_text_for_control_chars (const gchar *incoming_text)
 Returns the incoming text removed of control characters. More...
 
void gnc_filter_text_set_cursor_position (const gchar *incoming_text, const gchar *symbol, gint *cursor_position)
 Updates cursor_position after removal of currency symbols. More...
 
gchar * gnc_filter_text_for_currency_symbol (const gchar *incoming_text, const gchar *symbol)
 Returns the incoming text removed of a currency symbol. More...
 
gchar * gnc_filter_text_for_currency_commodity (const gnc_commodity *comm, const gchar *incoming_text, const gchar **symbol)
 Returns the incoming text removed of currency symbol. More...
 

Detailed Description

Function Documentation

◆ gnc_account_lookup_for_register()

Account* gnc_account_lookup_for_register ( const Account base_account,
const gchar *  name 
)

Retrieve the account matching the given name starting from the descendants of base_account.

name is either considered to be the name of the leaf in the account tree or to be the full account path, depending on the configuration parameter general.register/show_leaf_account_names.

Parameters
base_accountThe account to start the search at.
nameThe name to search for.
Returns
A pointer to the account, or NULL if the account was not found.

◆ gnc_account_or_default_currency()

gnc_commodity* gnc_account_or_default_currency ( const Account account,
gboolean *  currency_from_account_found 
)

Returns a gnc_commodity that is a currency, suitable for being a Transaction's currency.

The gnc_commodity is taken either from the current account, or from the next parent account that has a gnc_commodity that is a currency, or from gnc_default_currency().

If the given account or any of its parent account have a commodity that is a currency, it is returned and the gboolean currency_from_account_found is set to TRUE (if non-NULL). If neither this account nor any of its parent accounts have such a commodity, gnc_default_currency() is returned and the gboolean currency_from_account_found is set to FALSE (if non-NULL). This can be used to show an appropriate warning message.

If account is NULL, gnc_default_currency() is returned and currency_from_account_found is set to FALSE.

Parameters
accountThe account where the currency should be looked up. May be NULL.
currency_from_account_foundA gboolean pointer that takes the output argument of whether the returned currency was found in the account. May be NULL.
Returns
A currency pointer (and never NULL).

Definition at line 810 of file gnc-ui-util.c.

811 {
812  gnc_commodity *currency;
813  if (!account)
814  {
815  if (currency_from_account_found)
816  *currency_from_account_found = FALSE;
817  return gnc_default_currency();
818  }
819 
820  currency = gnc_account_get_currency_or_parent(account);
821  if (currency)
822  {
823  if (currency_from_account_found)
824  *currency_from_account_found = TRUE;
825  }
826  else
827  {
828  if (currency_from_account_found)
829  *currency_from_account_found = FALSE;
830  currency = gnc_default_currency();
831  }
832  return currency;
833 }
gnc_commodity * gnc_default_currency(void)
Return the default currency set by the user.
Definition: gnc-ui-util.c:805
gnc_commodity * gnc_account_get_currency_or_parent(const Account *account)
Returns a gnc_commodity that is a currency, suitable for being a Transaction's currency.
Definition: Account.cpp:3394

◆ gnc_default_currency()

gnc_commodity* gnc_default_currency ( void  )

Return the default currency set by the user.

If the user's preference is invalid, then this routine will return the default currency for the user's locale.

Returns
A pointer to a currency.

Definition at line 805 of file gnc-ui-util.c.

806 {
807  return gnc_default_currency_common (user_default_currency, GNC_PREFS_GROUP_GENERAL);
808 }

◆ gnc_default_report_currency()

gnc_commodity* gnc_default_report_currency ( void  )

Return the default currency for use in reports, as set by the user.

If the user's preference is invalid, then this routine will return the default currency for the user's locale.

Returns
A pointer to a currency.

Definition at line 838 of file gnc-ui-util.c.

839 {
840  return gnc_default_currency_common (user_report_currency, GNC_PREFS_GROUP_GENERAL_REPORT);
841 }

◆ gnc_filter_text_for_control_chars()

gchar* gnc_filter_text_for_control_chars ( const gchar *  incoming_text)

Returns the incoming text removed of control characters.

Parameters
incoming_textThe text to filter
Returns
The incoming text filtered of control characters to be freed by the caller.

Definition at line 2212 of file gnc-ui-util.c.

2213 {
2214  const char *ch;
2215  GString *filtered;
2216  gboolean cntrl = FALSE;
2217  gboolean text_found = FALSE;
2218 
2219  if (!text)
2220  return NULL;
2221 
2222  if (!g_utf8_validate (text, -1, NULL))
2223  return NULL;
2224 
2225  filtered = g_string_sized_new (strlen (text) + 1);
2226 
2227  ch = text;
2228 
2229  while (*ch)
2230  {
2231  gunichar uc = g_utf8_get_char (ch);
2232 
2233  // check for starting with control characters
2234  if (unichar_is_cntrl (uc) && !text_found)
2235  {
2236  ch = g_utf8_next_char (ch);
2237  continue;
2238  }
2239  // check for alpha, num and punctuation
2240  if (!unichar_is_cntrl (uc))
2241  {
2242  filtered = g_string_append_unichar (filtered, uc);
2243  text_found = TRUE;
2244  }
2245  // check for control characters after text
2246  if (unichar_is_cntrl (uc))
2247  cntrl = TRUE;
2248 
2249  ch = g_utf8_next_char (ch);
2250 
2251  if (cntrl) // if control characters in text replace with space
2252  {
2253  gunichar uc2 = g_utf8_get_char (ch);
2254 
2255  if (!unichar_is_cntrl (uc2))
2256  filtered = g_string_append_unichar (filtered, ' ');
2257  }
2258  cntrl = FALSE;
2259  }
2260  return g_string_free (filtered, FALSE);
2261 }

◆ gnc_filter_text_for_currency_commodity()

gchar* gnc_filter_text_for_currency_commodity ( const gnc_commodity *  comm,
const gchar *  incoming_text,
const gchar **  symbol 
)

Returns the incoming text removed of currency symbol.

Parameters
commcommodity of entry if known
incoming_textThe text to filter
symbolreturn the symbol used
Returns
The incoming text with symbol removed to be freed by the caller

Definition at line 2320 of file gnc-ui-util.c.

2323 {
2324  if (!incoming_text)
2325  {
2326  *symbol = NULL;
2327  return NULL;
2328  }
2329 
2330  if (!gnc_commodity_is_currency (comm))
2331  {
2332  *symbol = NULL;
2333  return g_strdup (incoming_text);
2334  }
2335 
2336  if (comm)
2337  *symbol = gnc_commodity_get_nice_symbol (comm);
2338  else
2340 
2341  return gnc_filter_text_for_currency_symbol (incoming_text, *symbol);
2342 }
gboolean gnc_commodity_is_currency(const gnc_commodity *cm)
Checks to see if the specified commodity is an ISO 4217 recognized currency or a legacy currency...
gnc_commodity * gnc_default_currency(void)
Return the default currency set by the user.
Definition: gnc-ui-util.c:805
const char * gnc_commodity_get_nice_symbol(const gnc_commodity *cm)
Retrieve a symbol for the specified commodity, suitable for display to the user.
gchar * gnc_filter_text_for_currency_symbol(const gchar *incoming_text, const gchar *symbol)
Returns the incoming text removed of a currency symbol.
Definition: gnc-ui-util.c:2296

◆ gnc_filter_text_for_currency_symbol()

gchar* gnc_filter_text_for_currency_symbol ( const gchar *  incoming_text,
const gchar *  symbol 
)

Returns the incoming text removed of a currency symbol.

Parameters
incoming_textThe text to filter
symbolto remove
cursor_positionthe position of cursor in the incoming text
Returns
The incoming text with symbol removed to be freed by the caller

Definition at line 2296 of file gnc-ui-util.c.

2298 {
2299  gchar *ret_text = NULL;
2300  gchar **split;
2301 
2302  if (!incoming_text)
2303  return NULL;
2304 
2305  if (!symbol)
2306  return g_strdup (incoming_text);
2307 
2308  if (g_strrstr (incoming_text, symbol) == NULL)
2309  return g_strdup (incoming_text);
2310 
2311  split = g_strsplit (incoming_text, symbol, -1);
2312 
2313  ret_text = g_strjoinv (NULL, split);
2314 
2315  g_strfreev (split);
2316  return ret_text;
2317 }

◆ gnc_filter_text_set_cursor_position()

void gnc_filter_text_set_cursor_position ( const gchar *  incoming_text,
const gchar *  symbol,
gint *  cursor_position 
)

Updates cursor_position after removal of currency symbols.

Parameters
incoming_textThe text to filter
symbolto remove
cursor_positionthe position of cursor in the incoming text
Returns
nothing

Definition at line 2264 of file gnc-ui-util.c.

2267 {
2268  gint text_len;
2269  gint num = 0;
2270 
2271  if (*cursor_position == 0)
2272  return;
2273 
2274  if (!incoming_text || !symbol)
2275  return;
2276 
2277  if (g_strrstr (incoming_text, symbol) == NULL)
2278  return;
2279 
2280  text_len = g_utf8_strlen (incoming_text, -1);
2281 
2282  for (gint x = 0; x < text_len; x++)
2283  {
2284  gchar *temp = g_utf8_offset_to_pointer (incoming_text, x);
2285 
2286  if (g_str_has_prefix (temp, symbol))
2287  num++;
2288 
2289  if (g_strrstr (temp, symbol) == NULL)
2290  break;
2291  }
2292  *cursor_position = *cursor_position - (num * g_utf8_strlen (symbol, -1));
2293 }

◆ gnc_get_account_name_for_register()

gchar* gnc_get_account_name_for_register ( const Account account)

Get either the full name of the account or the simple name, depending on the configuration parameter general/register/show_leaf_account_names.

Parameters
accountThe account to retrieve the name for.
Returns
A newly allocated string.

Definition at line 446 of file gnc-ui-util.c.

447 {
448  gboolean show_leaf_accounts;
449  show_leaf_accounts = gnc_prefs_get_bool(GNC_PREFS_GROUP_GENERAL_REGISTER,
450  GNC_PREF_SHOW_LEAF_ACCT_NAMES);
451 
452  return gnc_get_account_name_for_split_register(account, show_leaf_accounts);
453 }
gchar * gnc_get_account_name_for_split_register(const Account *account, gboolean show_leaf_accounts)
Get either the full name of the account or the simple name, depending on the show_leaf_accounts.
Definition: gnc-ui-util.c:437
gboolean gnc_prefs_get_bool(const gchar *group, const gchar *pref_name)
Get a boolean value from the preferences backend.

◆ gnc_get_account_name_for_split_register()

gchar* gnc_get_account_name_for_split_register ( const Account account,
gboolean  show_leaf_accounts 
)

Get either the full name of the account or the simple name, depending on the show_leaf_accounts.

Parameters
accountThe account to retrieve the name for.
show_leaf_accountsWhether the full name will be returned.
Returns
A newly allocated string.

Definition at line 437 of file gnc-ui-util.c.

438 {
439  if (show_leaf_accounts)
440  return g_strdup (xaccAccountGetName (account));
441  else
442  return gnc_account_get_full_name (account);
443 }
gchar * gnc_account_get_full_name(const Account *account)
The gnc_account_get_full_name routine returns the fully qualified name of the account using the given...
Definition: Account.cpp:3253
const char * xaccAccountGetName(const Account *acc)
Get the account&#39;s name.
Definition: Account.cpp:3246

◆ gnc_get_doclink_flag_order()

const char* gnc_get_doclink_flag_order ( void  )

Get a string containing document link flag order.

Returns
a string containing the document link flag change order

Definition at line 548 of file gnc-ui-util.c.

549 {
550  static const char flags[] = { FLINK, WLINK, ' ', 0 };
551  return flags;
552 }

◆ gnc_get_doclink_str()

const char* gnc_get_doclink_str ( char  link_flag)

Get a string representing the document link type.

Parameters
link_flagThe flag to convert into a string
Returns
the i18n'd doclink string

Definition at line 524 of file gnc-ui-util.c.

525 {
526  switch (link_flag)
527  {
528  case WLINK:
529  return C_("Document Link flag for 'web'", "w");
530  case FLINK:
531  return C_("Document Link flag for 'file'", "f");
532  case ' ':
533  return " ";
534  default:
535  PERR("Bad link flag");
536  return NULL;
537  }
538 }
#define PERR(format, args...)
Log a serious error.
Definition: qoflog.h:244

◆ gnc_get_doclink_valid_flags()

const char* gnc_get_doclink_valid_flags ( void  )

Get a string containing documentation link valid flags.

Returns
a string containing the list of valid link_flags

Definition at line 541 of file gnc-ui-util.c.

542 {
543  static const char flags[] = { FLINK, WLINK, ' ', 0 };
544  return flags;
545 }

◆ gnc_locale_default_currency()

gnc_commodity* gnc_locale_default_currency ( void  )

Returns the default currency of the current locale.

WATCH OUT: If no currency could be identified from the locale, this one returns "USD", but this will have nothing to do with the actual locale.

Definition at line 759 of file gnc-ui-util.c.

760 {
761  gnc_commodity * currency = gnc_locale_default_currency_nodefault ();
762 
763  return (currency ? currency :
764  gnc_commodity_table_lookup (gnc_get_current_commodities (),
765  GNC_COMMODITY_NS_CURRENCY, "USD"));
766 }
gnc_commodity * gnc_locale_default_currency_nodefault(void)
Returns the default currency of the current locale, or NULL if no sensible currency could be identifi...
Definition: gnc-ui-util.c:744

◆ gnc_locale_default_currency_nodefault()

gnc_commodity* gnc_locale_default_currency_nodefault ( void  )

Returns the default currency of the current locale, or NULL if no sensible currency could be identified from the locale.

Definition at line 744 of file gnc-ui-util.c.

745 {
746  gnc_commodity * currency;
747  gnc_commodity_table *table;
748  const char *code;
749 
750  table = gnc_get_current_commodities ();
751  code = gnc_locale_default_iso_currency_code ();
752 
753  currency = gnc_commodity_table_lookup (table, GNC_COMMODITY_NS_CURRENCY, code);
754 
755  return (currency ? currency : NULL);
756 }

◆ gnc_print_amount_with_bidi_ltr_isolate()

const char* gnc_print_amount_with_bidi_ltr_isolate ( gnc_numeric  val,
GNCPrintAmountInfo  info 
)

Make a string representation of a gnc_numeric.

Warning, the gnc_numeric is not checked for validity and the returned char* may point to random garbage.

This is the same as xaccPrintAmount but wraps the output with BiDi left to right isolate if a symbol is displayed.

Definition at line 1481 of file gnc-ui-util.c.

1482 {
1483  /* hack alert -- this is not thread safe ... */
1484  static char buf[BUFLEN];
1485  static const char ltr_isolate[] = { 0xe2, 0x81, 0xa6 };
1486  static const char ltr_pop_isolate[] = { 0xe2, 0x81, 0xa9 };
1487  size_t offset = info.use_symbol ? 3 : 0;
1488 
1489  if (!gnc_commodity_is_currency (info.commodity))
1490  offset = 0;
1491 
1492  memset (buf, 0, BUFLEN);
1493  if (!xaccSPrintAmount (buf + offset, val, info))
1494  {
1495  buf[0] = '\0';
1496  return buf;
1497  };
1498 
1499  if (offset == 0)
1500  return buf;
1501 
1502  memcpy (buf, ltr_isolate, 3);
1503 
1504  if (buf[BUFLEN - 4] == '\0')
1505  {
1506  size_t length = strlen (buf);
1507  memcpy (buf + length, ltr_pop_isolate, 3);
1508  }
1509  else
1510  {
1511  buf[BUFLEN - 1] = '\0';
1512  memcpy (buf + BUFLEN - 4, ltr_pop_isolate, 3);
1513 
1514  PWARN("buffer length %d exceeded, string truncated was %s", BUFLEN, buf);
1515  }
1516  /* its OK to return buf, since we declared it static
1517  and is immediately g_strdup'd */
1518  return buf;
1519 }
gboolean gnc_commodity_is_currency(const gnc_commodity *cm)
Checks to see if the specified commodity is an ISO 4217 recognized currency or a legacy currency...
#define PWARN(format, args...)
Log a warning.
Definition: qoflog.h:250
int xaccSPrintAmount(char *bufp, gnc_numeric val, GNCPrintAmountInfo info)
Make a string representation of a gnc_numeric.
Definition: gnc-ui-util.c:1337

◆ gnc_wrap_text_with_bidi_ltr_isolate()

gchar* gnc_wrap_text_with_bidi_ltr_isolate ( const char *  text)

This function helps with GTK's use of 'Unicode Bidirectional Text Algorithm'.

To keep the format of the text, this function wraps the text with a BiDi isolate charatcter and a BiDi closing character.

This helps with monetary values in RTL languages that display the currency symbol.

◆ xaccParseAmount()

gboolean xaccParseAmount ( const char *  in_str,
gboolean  monetary,
gnc_numeric *  result,
char **  endstr 
)

Parses in_str to obtain a numeric result.

The routine will parse as much of in_str as it can to obtain a single number. The number is parsed using the current locale information and the 'monetary' flag. The routine will return TRUE if it successfully parsed a number and FALSE otherwise. If TRUE is returned and result is non-NULL, the value of the parsed number is stored in *result. If FALSE is returned, *result is unchanged. If TRUE is returned and endstr is non-NULL, the location of the first character in in_str not used by the parser will be returned in *endstr. If FALSE is returned and endstr is non-NULL, *endstr will point to in_str.

Definition at line 2060 of file gnc-ui-util.c.

2062 {
2063  return xaccParseAmountBasicInternal (in_str, monetary, auto_decimal_enabled,
2064  result, endstr, FALSE);
2065 }

◆ xaccParseAmountExtended()

gboolean xaccParseAmountExtended ( const char *  in_str,
gboolean  monetary,
gunichar  negative_sign,
gunichar  decimal_point,
gunichar  group_separator,
const char *  ignore_list,
gnc_numeric *  result,
char **  endstr 
)

Converts a string to a gnc_numeric.

The caller must provide all the locale-specific information.

ignore_list is a list of characters that are completely ignored while processing the input string. If ignore_list is NULL, nothing is ignored.

Definition at line 2078 of file gnc-ui-util.c.

2082 {
2083  return xaccParseAmountInternal (in_str, monetary, negative_sign,
2084  decimal_point, group_separator,
2085  ignore_list, auto_decimal_enabled,
2086  result, endstr);
2087 }

◆ xaccParseAmountExtImport()

gboolean xaccParseAmountExtImport ( const char *  in_str,
gboolean  monetary,
gunichar  negative_sign,
gunichar  decimal_point,
gunichar  group_separator,
const char *  ignore_list,
gnc_numeric *  result,
char **  endstr 
)

Similar to xaccParseAmountExtended, but will not automatically set a decimal point, regardless of what the user has set for this option.

Primarily meant for cases where numbers are coming into gnucash that are not typed in by the user (like via csv import).

Definition at line 2090 of file gnc-ui-util.c.

2094 {
2095  return xaccParseAmountInternal (in_str, monetary, negative_sign,
2096  decimal_point, group_separator,
2097  ignore_list, FALSE,
2098  result, endstr);
2099 }

◆ xaccParseAmountImport()

gboolean xaccParseAmountImport ( const char *  in_str,
gboolean  monetary,
gnc_numeric *  result,
char **  endstr,
gboolean  skip 
)

Similar to xaccParseAmount, but with two differences.

  • it exposes a flag to indicate whether the locale's positive sign (or in absence the '+') character is ignored. Setting skip to TRUE will cause the function to ignore any positive sign. Setting it to FALSE, and positive signs will be treated as unrecognized characters. xaccParseAmount will run as if skip is FALSE for compatibility reasons (gnc-expression-parser depends on this behaviour).
  • The other important difference with xaccParseAmount is that this function will never apply automatic decimal point logc, whereas xaccParseAmount will follow the automatic decimal point preference as set by the user.

Definition at line 2068 of file gnc-ui-util.c.

2071 {
2072  return xaccParseAmountBasicInternal (in_str, monetary, FALSE,
2073  result, endstr, skip);
2074 }

◆ xaccPrintAmount()

const char* xaccPrintAmount ( gnc_numeric  val,
GNCPrintAmountInfo  info 
)

Make a string representation of a gnc_numeric.

Warning, the gnc_numeric is not checked for validity and the returned char* may point to random garbage.

Definition at line 1468 of file gnc-ui-util.c.

1469 {
1470  /* hack alert -- this is not thread safe ... */
1471  static char buf[BUFLEN];
1472 
1473  if (!xaccSPrintAmount (buf, val, info))
1474  buf[0] = '\0';
1475 
1476  /* its OK to return buf, since we declared it static */
1477  return buf;
1478 }
int xaccSPrintAmount(char *bufp, gnc_numeric val, GNCPrintAmountInfo info)
Make a string representation of a gnc_numeric.
Definition: gnc-ui-util.c:1337

◆ xaccSPrintAmount()

int xaccSPrintAmount ( char *  bufp,
gnc_numeric  val,
GNCPrintAmountInfo  info 
)

Make a string representation of a gnc_numeric.

Warning, the gnc_numeric is not checked for validity and the contents of the buffer will be unchanged. It is up to the calling function to ensure that buf is large enough for the results.

Parameters
bufpShould be at least 64 chars.

Definition at line 1337 of file gnc-ui-util.c.

1338 {
1339  struct lconv *lc;
1340 
1341  char *orig_bufp = bufp;
1342  const char *currency_symbol;
1343  const char *sign;
1344 
1345  char cs_precedes;
1346  char sep_by_space;
1347  char sign_posn;
1348 
1349  gboolean print_sign = TRUE;
1350  gboolean print_absolute = FALSE;
1351 
1352  if (!bufp)
1353  return 0;
1354 
1355  lc = gnc_localeconv();
1356  if (info.use_locale)
1357  if (gnc_numeric_negative_p (val))
1358  {
1359  cs_precedes = lc->n_cs_precedes;
1360  sep_by_space = lc->n_sep_by_space;
1361  }
1362  else
1363  {
1364  cs_precedes = lc->p_cs_precedes;
1365  sep_by_space = lc->p_sep_by_space;
1366  }
1367  else
1368  {
1369  cs_precedes = TRUE;
1370  sep_by_space = TRUE;
1371  }
1372 
1373  if (info.commodity && info.use_symbol)
1374  {
1375  currency_symbol = gnc_commodity_get_nice_symbol (info.commodity);
1376  if (!gnc_commodity_is_iso (info.commodity))
1377  {
1378  cs_precedes = FALSE;
1379  sep_by_space = TRUE;
1380  }
1381  }
1382  else /* !info.use_symbol || !info.commodity */
1383  currency_symbol = "";
1384 
1385  if (gnc_numeric_negative_p (val))
1386  {
1387  sign = lc->negative_sign;
1388  sign_posn = lc->n_sign_posn;
1389  }
1390  else
1391  {
1392  sign = lc->positive_sign;
1393  sign_posn = lc->p_sign_posn;
1394  }
1395 
1396  if (gnc_numeric_zero_p (val) || (sign == NULL) || (sign[0] == 0))
1397  print_sign = FALSE;
1398 
1399  /* See if we print sign now */
1400  if (print_sign && (sign_posn == 1))
1401  bufp = g_stpcpy(bufp, sign);
1402 
1403  /* Now see if we print currency */
1404  if (cs_precedes)
1405  {
1406  /* See if we print sign now */
1407  if (print_sign && (sign_posn == 3))
1408  bufp = g_stpcpy(bufp, sign);
1409 
1410  if (info.use_symbol)
1411  {
1412  bufp = g_stpcpy(bufp, currency_symbol);
1413  if (sep_by_space)
1414  bufp = g_stpcpy(bufp, " ");
1415  }
1416 
1417  /* See if we print sign now */
1418  if (print_sign && (sign_posn == 4))
1419  bufp = g_stpcpy(bufp, sign);
1420  }
1421 
1422  /* Now see if we print parentheses */
1423  if (print_sign && (sign_posn == 0))
1424  {
1425  bufp = g_stpcpy(bufp, "(");
1426  print_absolute = TRUE;
1427  }
1428 
1429  /* Now print the value */
1430  bufp += PrintAmountInternal(bufp,
1431  print_absolute ? gnc_numeric_abs(val) : val,
1432  &info);
1433 
1434  /* Now see if we print parentheses */
1435  if (print_sign && (sign_posn == 0))
1436  bufp = g_stpcpy(bufp, ")");
1437 
1438  /* Now see if we print currency */
1439  if (!cs_precedes)
1440  {
1441  /* See if we print sign now */
1442  if (print_sign && (sign_posn == 3))
1443  bufp = g_stpcpy(bufp, sign);
1444 
1445  if (info.use_symbol)
1446  {
1447  if (sep_by_space)
1448  bufp = g_stpcpy(bufp, " ");
1449  bufp = g_stpcpy(bufp, currency_symbol);
1450  }
1451 
1452  /* See if we print sign now */
1453  if (print_sign && (sign_posn == 4))
1454  bufp = g_stpcpy(bufp, sign);
1455  }
1456 
1457  /* See if we print sign now */
1458  if (print_sign && (sign_posn == 2))
1459  bufp = g_stpcpy(bufp, sign);
1460 
1461  /* return length of printed string */
1462  return (bufp - orig_bufp);
1463 }
gboolean gnc_numeric_zero_p(gnc_numeric a)
Returns 1 if the given gnc_numeric is 0 (zero), else returns 0.
gboolean gnc_numeric_negative_p(gnc_numeric a)
Returns 1 if a < 0, otherwise returns 0.
const char * gnc_commodity_get_nice_symbol(const gnc_commodity *cm)
Retrieve a symbol for the specified commodity, suitable for display to the user.
gnc_numeric gnc_numeric_abs(gnc_numeric a)
Returns a newly created gnc_numeric that is the absolute value of the given gnc_numeric value...
gboolean gnc_commodity_is_iso(const gnc_commodity *cm)
Checks to see if the specified commodity is an ISO 4217 recognized currency.