GnuCash
5.6-150-g038405b370+
|
The API in this file is designed to provide support functions that wrap the base glib functions and make them easier to use. More...
Files | |
file | gnc-glib-utils.h |
GLib helper routines. | |
Functions | |
gchar * | gnc_g_list_stringjoin (GList *list_of_strings, const gchar *sep) |
Return a string joining a GList whose elements are gchar* strings. More... | |
gchar * | gnc_g_list_stringjoin_nodups (GList *list_of_strings, const gchar *sep) |
Like stringjoin but ensures that the string to be added isn't already part of the return string. More... | |
gint | gnc_list_length_cmp (const GList *list, size_t len) |
Scans the GList elements the minimum number of iterations required to test it against a specified size. More... | |
Character Sets | |
int | safe_utf8_collate (const char *str1, const char *str2) |
Collate two UTF-8 strings. More... | |
gboolean | gnc_utf8_validate (const gchar *str, gssize max_len, const gchar **end) |
Validates UTF-8 encoded text for use in GnuCash. More... | |
void | gnc_utf8_strip_invalid (gchar *str) |
Strip any non-UTF-8 characters from a string. More... | |
gchar * | gnc_utf8_strip_invalid_strdup (const gchar *str) |
Returns a newly allocated copy of the given string but with any non-UTF-8 character stripped from it. More... | |
void | gnc_utf8_strip_invalid_and_controls (gchar *str) |
Strip any non-utf8 characters and any control characters (everything < 0x20, , , , , , and ) from a string. More... | |
gchar * | gnc_locale_from_utf8 (const gchar *str) |
Converts a string from UTF-8 to the encoding used for strings in the current locale. More... | |
gchar * | gnc_locale_to_utf8 (const gchar *str) |
Converts a string to UTF-8 from the encoding used for strings in the current locale. More... | |
GList Manipulation | |
typedef gpointer(* | GncGMapFunc) (gpointer data, gpointer user_data) |
GList * | gnc_g_list_map (GList *list, GncGMapFunc fn, gpointer user_data) |
void | gnc_g_list_cut (GList **list, GList *cut_point) |
Cut a GList into two parts; the cut_point is the beginning of the new list; list may need to be modified, but will be the list before the cut_point. | |
The API in this file is designed to provide support functions that wrap the base glib functions and make them easier to use.
GList* gnc_g_list_map | ( | GList * | list, |
GncGMapFunc | fn, | ||
gpointer | user_data | ||
) |
Definition at line 264 of file gnc-glib-utils.c.
gchar* gnc_g_list_stringjoin | ( | GList * | list_of_strings, |
const gchar * | sep | ||
) |
Return a string joining a GList whose elements are gchar* strings.
Returns NULL if an empty GList* is passed through. The optional sep string will be used as separator. Must be g_freed when not needed anymore.
list_of_strings | A GList of chars* |
sep | a separator or NULL |
Definition at line 345 of file gnc-glib-utils.c.
gchar* gnc_g_list_stringjoin_nodups | ( | GList * | list_of_strings, |
const gchar * | sep | ||
) |
Like stringjoin but ensures that the string to be added isn't already part of the return string.
list_of_strings | A GList of chars* |
sep | a separator or NULL |
Definition at line 351 of file gnc-glib-utils.c.
gint gnc_list_length_cmp | ( | const GList * | list, |
size_t | len | ||
) |
Scans the GList elements the minimum number of iterations required to test it against a specified size.
Returns -1, 0 or 1 depending on whether the GList length has less, same, or more elements than the size specified.
lst | A GList |
len | the comparator length to compare the GList length with |
Definition at line 357 of file gnc-glib-utils.c.
gchar* gnc_locale_from_utf8 | ( | const gchar * | str | ) |
Converts a string from UTF-8 to the encoding used for strings in the current locale.
This essentially is a wrapper for g_locale_from_utf8 that can be swigified for use with Scheme to avoid adding a dependency for guile-glib.
str | A pointer to a UTF-8 encoded string to be converted. |
Definition at line 228 of file gnc-glib-utils.c.
gchar* gnc_locale_to_utf8 | ( | const gchar * | str | ) |
Converts a string to UTF-8 from the encoding used for strings in the current locale.
This essentially is a wrapper for g_locale_to_utf8 that can be swigified for use with Scheme to avoid adding a dependency for guile-glib.
str | A pointer to a string encoded according to locale. |
Definition at line 246 of file gnc-glib-utils.c.
void gnc_utf8_strip_invalid | ( | gchar * | str | ) |
Strip any non-UTF-8 characters from a string.
This function rewrites the string "in place" instead of allocating and returning a new string. This allows it to operate on strings that are defined as character arrays in a larger data structure. Note that it also removes some subset of invalid XML characters, too. See https://www.w3.org/TR/REC-xml/#NT-Char linked from bug #346535
str | A pointer to the string to strip of invalid characters. |
Definition at line 185 of file gnc-glib-utils.c.
void gnc_utf8_strip_invalid_and_controls | ( | gchar * | str | ) |
Strip any non-utf8 characters and any control characters (everything < 0x20, , ,
, , , and ) from a string.
Rewrites the string in-place.
str | Pointer to the string to clean up. |
Definition at line 213 of file gnc-glib-utils.c.
gchar* gnc_utf8_strip_invalid_strdup | ( | const gchar * | str | ) |
Returns a newly allocated copy of the given string but with any non-UTF-8 character stripped from it.
Note that it also removes some subset of invalid XML characters, too. See https://www.w3.org/TR/REC-xml/#NT-Char linked from bug #346535
str | A pointer to the string to be copied and stripped of non-UTF-8 characters. |
Definition at line 205 of file gnc-glib-utils.c.
gboolean gnc_utf8_validate | ( | const gchar * | str, |
gssize | max_len, | ||
const gchar ** | end | ||
) |
Validates UTF-8 encoded text for use in GnuCash.
Validates the strict subset of UTF-8 that is valid XML text, as detailed in https://www.w3.org/TR/REC-xml/#NT-Char linked from bug #346535.
Copied from g_utf8_validate():
Validates UTF-8 encoded text, where str is the text to validate; if str is nul-terminated, then max_len can be -1, otherwise max_len should be the number of bytes to validate. If end is non-NULL, then the end of the valid range will be stored there (i.e. the start of the first invalid character if some bytes were invalid, or the end of the text being validated otherwise).
Returns TRUE if all of str was valid. Many GLib and GTK+ routines require valid UTF-8 as input; so data read from a file or the network should be checked with g_utf8_validate() before doing anything else with it.
str | a pointer to character data |
max_len | max bytes to validate, or -1 to go until NUL |
end | return location for end of valid data |
Definition at line 124 of file gnc-glib-utils.c.
int safe_utf8_collate | ( | const char * | str1, |
const char * | str2 | ||
) |
Collate two UTF-8 strings.
This function performs basic argument checking before calling g_utf8_collate.
str1 | The first string. |
str2 | The first string. |
Definition at line 38 of file gnc-glib-utils.c.