45 return g_utf8_collate(da, db);
60 #define UTF8_COMPUTE(Char, Mask, Len) \
66 else if ((Char & 0xe0) == 0xc0) \
71 else if ((Char & 0xf0) == 0xe0) \
76 else if ((Char & 0xf8) == 0xf0) \
81 else if ((Char & 0xfc) == 0xf8) \
86 else if ((Char & 0xfe) == 0xfc) \
94 #define UTF8_LENGTH(Char) \
95 ((Char) < 0x80 ? 1 : \
96 ((Char) < 0x800 ? 2 : \
97 ((Char) < 0x10000 ? 3 : \
98 ((Char) < 0x200000 ? 4 : \
99 ((Char) < 0x4000000 ? 5 : 6)))))
102 #define UTF8_GET(Result, Chars, Count, Mask, Len) \
103 (Result) = (Chars)[0] & (Mask); \
104 for ((Count) = 1; (Count) < (Len); ++(Count)) \
106 if (((Chars)[(Count)] & 0xc0) != 0x80) \
112 (Result) |= ((Chars)[(Count)] & 0x3f); \
115 #define UNICODE_VALID(Char) \
116 ((Char) < 0x110000 && \
117 (((Char) & 0xFFFFF800) != 0xD800) && \
118 ((Char) < 0xFDD0 || (Char) > 0xFDEF) && \
119 ((Char) >= 0x20 || (Char) == 0x09 || (Char) == 0x0A || (Char) == 0x0D) && \
120 ((Char) & 0xFFFE) != 0xFFFE)
130 g_return_val_if_fail (str != NULL, FALSE);
137 while ((max_len < 0 || (p - str) < max_len) && *p)
139 int i, mask = 0, len;
141 unsigned char c = (
unsigned char) * p;
143 UTF8_COMPUTE (c, mask, len);
150 ((max_len - (p - str)) < len))
153 UTF8_GET (result, p, i, mask, len);
155 if (UTF8_LENGTH (result) != len)
158 if (result == (gunichar) - 1)
161 if (!UNICODE_VALID (result))
174 p != (str + max_len))
176 else if (max_len < 0 &&
189 g_return_if_fail(str);
194 g_warning(
"Invalid utf8 string: %s", str);
198 memmove(end, end + 1, len);
206 gchar *result = g_strdup (str);
215 gsize bytes_written = 0;
219 locale_str = g_locale_from_utf8(str, -1, NULL, &bytes_written, &err);
222 g_warning(
"g_locale_from_utf8 failed: %s", err->message);
233 gsize bytes_written = 0;
237 utf8_str = g_locale_to_utf8(str, -1, NULL, &bytes_written, &err);
240 g_warning(
"g_locale_to_utf8 failed: %s", err->message);
251 for (; list != NULL; list = list->next)
253 rtn = g_list_append(rtn, (*fn)(list->data, user_data));
261 if (list == NULL || *list == NULL)
265 if (cut_point->prev == NULL)
271 cut_point->prev->next = NULL;
272 cut_point->prev = NULL;
276 gnc_scm_log_warn(
const gchar *msg)
278 g_log(
"gnc.scm", G_LOG_LEVEL_WARNING,
"%s", msg);
282 gnc_scm_log_error(
const gchar *msg)
284 g_log(
"gnc.scm", G_LOG_LEVEL_CRITICAL,
"%s", msg);
288 gnc_scm_log_msg(
const gchar *msg)
290 g_log(
"gnc.scm", G_LOG_LEVEL_MESSAGE,
"%s", msg);
294 gnc_scm_log_debug(
const gchar *msg)
296 g_log(
"gnc.scm", G_LOG_LEVEL_DEBUG,
"%s", msg);
302 if (!TerminateProcess((HANDLE) pid, 0))
304 gchar *msg = g_win32_error_message(GetLastError());
305 g_warning(
"Could not kill child process: %s", msg ? msg :
"(null)");
309 if (kill(pid, SIGKILL))
311 g_warning(
"Could not kill child process: %s", g_strerror(errno));
GList * gnc_g_list_map(GList *list, GncGMapFunc fn, gpointer user_data)
int safe_utf8_collate(const char *da, const char *db)
gchar * gnc_locale_from_utf8(const gchar *str)
Converts a string from UTF-8 to the encoding used for strings in the current locale.
gboolean gnc_utf8_validate(const gchar *str, gssize max_len, const gchar **end)
Validates UTF-8 encoded text for use in GnuCash.
void gnc_g_list_cut(GList **list, GList *cut_point)
void gnc_utf8_strip_invalid(gchar *str)
gchar * gnc_locale_to_utf8(const gchar *str)
Converts a string to UTF-8 from the encoding used for strings in the current locale.
void gnc_gpid_kill(GPid pid)
gchar * gnc_utf8_strip_invalid_strdup(const gchar *str)