From dfaec6654b14591b40b8e1b90d7ae3e41dacd04a Mon Sep 17 00:00:00 2001 From: Christian Stimming Date: Tue, 15 Aug 2006 20:00:14 +0000 Subject: [PATCH] Add gnc_utf8_strip_invalid_strdup() that returns a stripped copy instead of working in-place. BP git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@14679 57a11ea4-9604-0410-9ed3-97b8803252fd --- ChangeLog | 4 ++++ src/core-utils/gnc-glib-utils.c | 8 ++++++++ src/core-utils/gnc-glib-utils.h | 14 ++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/ChangeLog b/ChangeLog index 5af23ef0f4..2d193daabc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2006-08-15 Christian Stimming + * src/core-utils/gnc-glib-utils.[hc]: Add + gnc_utf8_strip_invalid_strdup() that returns a stripped copy + instead of working in-place. + * src/import-export/hbci/dialog-hbcitrans.c (blz_changed_cb): Ensure the encoding of the ktoblzcheck library is used correctly. Their encoding is still always ISO-8859-1, but in diff --git a/src/core-utils/gnc-glib-utils.c b/src/core-utils/gnc-glib-utils.c index 5d5c9f6f1b..3acaaf1955 100644 --- a/src/core-utils/gnc-glib-utils.c +++ b/src/core-utils/gnc-glib-utils.c @@ -214,3 +214,11 @@ gnc_utf8_strip_invalid (gchar *str) memmove(end, end+1, len); /* shuffle the remainder one byte */ } while (!gnc_utf8_validate(str, -1, (const gchar **)&end)); } + +gchar * +gnc_utf8_strip_invalid_strdup(const gchar* str) +{ + gchar *result = g_strdup (str); + gnc_utf8_strip_invalid (result); + return result; +} diff --git a/src/core-utils/gnc-glib-utils.h b/src/core-utils/gnc-glib-utils.h index e1f03b0bbf..c848dfca6b 100644 --- a/src/core-utils/gnc-glib-utils.h +++ b/src/core-utils/gnc-glib-utils.h @@ -67,6 +67,20 @@ int safe_utf8_collate (const char *str1, const char *str2); * characters. */ void gnc_utf8_strip_invalid (gchar *str); +/** Returns a newly allocated copy of the given string but with any + * non-utf8 character stripped from it. + * + * Note that it also removes some subset of invalid XML characters, + * too. See http://www.w3.org/TR/REC-xml/#NT-Char linked from bug + * #346535 + * + * @param str A pointer to the string to be copied and stripped of + * non-utf8 characters. + * + * @return A newly allocated string that has to be g_free'd by the + * caller. */ +gchar *gnc_utf8_strip_invalid_strdup (const gchar* str); + /** @} */