gnucash maint: [import matcher] Don't normalize text when appending descriptions or notes.
John Ralls
jralls at code.gnucash.org
Sat Dec 17 15:00:04 EST 2022
Updated via https://github.com/Gnucash/gnucash/commit/ccd328db (commit)
from https://github.com/Gnucash/gnucash/commit/65d3546f (commit)
commit ccd328db9ac34fd5972921643e4aff2d8bf6c16c
Author: John Ralls <jralls at ceridwen.us>
Date: Sat Dec 17 11:57:58 2022 -0800
[import matcher] Don't normalize text when appending descriptions or notes.
Another fix for Bug 798679. Normalized strings are still stored in
quickfills.
diff --git a/gnucash/import-export/import-backend.c b/gnucash/import-export/import-backend.c
index b74333a16..d147af396 100644
--- a/gnucash/import-export/import-backend.c
+++ b/gnucash/import-export/import-backend.c
@@ -859,6 +859,27 @@ notes_append (Transaction* selected_match_trans, gchar* new_notes)
g_free (tmp);
}
+static char*
+maybe_append_string (const char* match_string, const char* imp_string)
+{
+ char *norm_match_string, *norm_imp_string;
+
+ if (!(match_string && *match_string))
+ return g_strdup(imp_string);
+
+ if (!(imp_string && *imp_string))
+ return NULL;
+
+ norm_match_string = g_utf8_normalize (match_string, -1, G_NORMALIZE_ALL);
+ norm_imp_string = g_utf8_normalize (imp_string, -1, G_NORMALIZE_ALL);
+
+ if (g_utf8_strlen (norm_imp_string, -1) > g_utf8_strlen (norm_match_string, -1) ||
+ !strstr (norm_match_string, norm_imp_string))
+ return g_strconcat(match_string, "|", imp_string, NULL);
+
+ return NULL;
+}
+
/* Append or replace transaction description and notes
* depending on the Append checkbox
*/
@@ -868,52 +889,25 @@ update_desc_and_notes (const GNCImportTransInfo* trans_info)
GNCImportMatchInfo* selected_match =
gnc_import_TransInfo_get_selected_match (trans_info);
Transaction* imp_trans = gnc_import_TransInfo_get_trans (trans_info);
+ Transaction* match_trans = selected_match->trans;
if (trans_info->append_text)
{
- gchar *desc_imported, *desc_matched, *note_imported, *note_matched;
- const gchar* raw_str = xaccTransGetDescription (imp_trans);
-
- desc_imported =
- raw_str ? g_utf8_normalize (raw_str, -1, G_NORMALIZE_ALL) : NULL;
- raw_str = xaccTransGetDescription (selected_match->trans);
- desc_matched =
- raw_str ? g_utf8_normalize (raw_str, -1, G_NORMALIZE_ALL) : NULL;
- raw_str = xaccTransGetNotes (imp_trans);
- note_imported =
- raw_str ? g_utf8_normalize (raw_str, -1, G_NORMALIZE_ALL) : NULL;
- raw_str = xaccTransGetNotes (selected_match->trans);
- note_matched =
- raw_str ? g_utf8_normalize (raw_str, -1, G_NORMALIZE_ALL) : NULL;
-
- // Append if desc_imported not already in desc_matched
- if (desc_imported &&
- (!desc_matched ||
- g_utf8_strlen (desc_imported, -1) > g_utf8_strlen (desc_matched, -1) ||
- !strstr (desc_matched, desc_imported)))
- {
- if (desc_matched && *desc_matched)
- desc_append (selected_match->trans, desc_imported);
- else
- xaccTransSetDescription (selected_match->trans, desc_imported);
- }
-
- // Append if note_imported not already in note_matched
- if (note_imported &&
- (!note_matched ||
- g_utf8_strlen (note_imported, -1) > g_utf8_strlen (note_matched, -1) ||
- !strstr (note_matched, note_imported)))
- {
- if (note_matched && *note_matched)
- notes_append (selected_match->trans, note_imported);
- else
- xaccTransSetNotes (selected_match->trans, note_imported);
- }
-
- g_free(desc_imported);
- g_free(desc_matched);
- g_free(note_imported);
- g_free(note_matched);
+ gchar *repl_str;
+
+ repl_str =
+ maybe_append_string (xaccTransGetDescription(match_trans),
+ xaccTransGetDescription(imp_trans));
+ if (repl_str)
+ xaccTransSetDescription(match_trans, repl_str);
+ g_free (repl_str);
+
+ repl_str =
+ maybe_append_string (xaccTransGetNotes(match_trans),
+ xaccTransGetNotes(imp_trans));
+ if (repl_str)
+ xaccTransSetNotes (match_trans, repl_str);
+ g_free (repl_str);
}
else
{
Summary of changes:
gnucash/import-export/import-backend.c | 80 ++++++++++++++++------------------
1 file changed, 37 insertions(+), 43 deletions(-)
More information about the gnucash-changes
mailing list