mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Bug 798679 - Fullwidth characters cannot be pasted as-is in register fields
Control character check doesn't need normalization, the control character codepoints aren't graphic and so can't be composed nor have compatible equivalents.
This commit is contained in:
parent
993697be7f
commit
fd2761bd68
@ -2595,7 +2595,7 @@ unichar_is_cntrl (gunichar uc)
|
|||||||
gchar *
|
gchar *
|
||||||
gnc_filter_text_for_control_chars (const gchar *text)
|
gnc_filter_text_for_control_chars (const gchar *text)
|
||||||
{
|
{
|
||||||
gchar *normal_text, *nt;
|
const char *ch;
|
||||||
GString *filtered;
|
GString *filtered;
|
||||||
gboolean cntrl = FALSE;
|
gboolean cntrl = FALSE;
|
||||||
gboolean text_found = FALSE;
|
gboolean text_found = FALSE;
|
||||||
@ -2606,20 +2606,18 @@ gnc_filter_text_for_control_chars (const gchar *text)
|
|||||||
if (!g_utf8_validate (text, -1, NULL))
|
if (!g_utf8_validate (text, -1, NULL))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
normal_text = g_utf8_normalize (text, -1, G_NORMALIZE_ALL_COMPOSE);
|
filtered = g_string_sized_new (strlen (text) + 1);
|
||||||
|
|
||||||
filtered = g_string_sized_new (strlen (normal_text) + 1);
|
ch = text;
|
||||||
|
|
||||||
nt = normal_text;
|
while (*ch)
|
||||||
|
|
||||||
while (*nt)
|
|
||||||
{
|
{
|
||||||
gunichar uc = g_utf8_get_char (nt);
|
gunichar uc = g_utf8_get_char (ch);
|
||||||
|
|
||||||
// check for starting with control characters
|
// check for starting with control characters
|
||||||
if (unichar_is_cntrl (uc) && !text_found)
|
if (unichar_is_cntrl (uc) && !text_found)
|
||||||
{
|
{
|
||||||
nt = g_utf8_next_char (nt);
|
ch = g_utf8_next_char (ch);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// check for alpha, num and punctuation
|
// check for alpha, num and punctuation
|
||||||
@ -2632,18 +2630,17 @@ gnc_filter_text_for_control_chars (const gchar *text)
|
|||||||
if (unichar_is_cntrl (uc))
|
if (unichar_is_cntrl (uc))
|
||||||
cntrl = TRUE;
|
cntrl = TRUE;
|
||||||
|
|
||||||
nt = g_utf8_next_char (nt);
|
ch = g_utf8_next_char (ch);
|
||||||
|
|
||||||
if (cntrl) // if control characters in text replace with space
|
if (cntrl) // if control characters in text replace with space
|
||||||
{
|
{
|
||||||
gunichar uc2 = g_utf8_get_char (nt);
|
gunichar uc2 = g_utf8_get_char (ch);
|
||||||
|
|
||||||
if (!unichar_is_cntrl (uc2))
|
if (!unichar_is_cntrl (uc2))
|
||||||
filtered = g_string_append_unichar (filtered, ' ');
|
filtered = g_string_append_unichar (filtered, ' ');
|
||||||
}
|
}
|
||||||
cntrl = FALSE;
|
cntrl = FALSE;
|
||||||
}
|
}
|
||||||
g_free (normal_text);
|
|
||||||
return g_string_free (filtered, FALSE);
|
return g_string_free (filtered, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2684,6 +2681,7 @@ gnc_filter_text_for_currency_symbol (const gchar *incoming_text,
|
|||||||
const gchar *symbol)
|
const gchar *symbol)
|
||||||
{
|
{
|
||||||
gchar *ret_text = NULL;
|
gchar *ret_text = NULL;
|
||||||
|
gchar *normal_text, *normal_sym;
|
||||||
gchar **split;
|
gchar **split;
|
||||||
|
|
||||||
if (!incoming_text)
|
if (!incoming_text)
|
||||||
@ -2692,8 +2690,15 @@ gnc_filter_text_for_currency_symbol (const gchar *incoming_text,
|
|||||||
if (!symbol)
|
if (!symbol)
|
||||||
return g_strdup (incoming_text);
|
return g_strdup (incoming_text);
|
||||||
|
|
||||||
if (g_strrstr (incoming_text, symbol) == NULL)
|
normal_sym = g_utf8_normalize (symbol, -1, G_NORMALIZE_ALL_COMPOSE);
|
||||||
|
normal_text =
|
||||||
|
g_utf8_normalize (incoming_text, -1, G_NORMALIZE_ALL_COMPOSE);
|
||||||
|
if (g_strrstr (normal_text, normal_sym) == NULL)
|
||||||
|
{
|
||||||
|
g_free(normal_sym);
|
||||||
|
g_free(normal_text);
|
||||||
return g_strdup (incoming_text);
|
return g_strdup (incoming_text);
|
||||||
|
}
|
||||||
|
|
||||||
split = g_strsplit (incoming_text, symbol, -1);
|
split = g_strsplit (incoming_text, symbol, -1);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user