Improved regexps for CSV files with quotes - quotes are allowed but not required on all fields.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@21262 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Geert Janssens 2011-09-17 16:50:30 +00:00
parent 298aa3787d
commit 661ea3fb4f
2 changed files with 3 additions and 3 deletions

View File

@ -114,7 +114,7 @@ gnc_bi_import_read_file (const gchar * filename, const gchar * parser_regexp,
// compile the regular expression and check for errors
err = NULL;
regexpat =
g_regex_new (parser_regexp, G_REGEX_EXTENDED | G_REGEX_OPTIMIZE, 0, &err);
g_regex_new (parser_regexp, G_REGEX_EXTENDED | G_REGEX_OPTIMIZE | G_REGEX_DUPNAMES, 0, &err);
if (err != NULL)
{
GtkWidget *dialog;

View File

@ -309,7 +309,7 @@ void gnc_bi_import_gui_option3_cb (GtkWidget *widget, gpointer data)
BillImportGui *gui = data;
if (!gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(widget) ))
return;
g_string_assign (gui->regexp, "^\"(?<id>[^!#+^\"]*)\";\"(?<date_opened>[^\"]*)\";\"(?<owner_id>[^\"]*)\";\"(?<billing_id>[^\"]*)\";\"?(?<notes>[^\"]*)\";\"?(?<date>[^\"]*)\";\"?(?<desc>[^\"]*)\";\"?(?<action>[^\"]*)\";\"?(?<account>[^\"]*)\";\"?(?<quantity>[^\"]*)\";\"?(?<price>[^\"]*)\";\"?(?<disc_type>[^\"]*)\";\"?(?<disc_how>[^\"]*)\";\"?(?<discount>[^\"]*)\";\"?(?<taxable>[^\"]*)\";\"?(?<taxincluded>[^\"]*)\";\"?(?<tax_table>[^\"]*)\";\"(?<date_posted>[^\"]*)\";\"(?<due_date>[^\"]*)\";\"(?<account_posted>[^\"]*)\";\"(?<memo_posted>[^\"]*)\";\"(?<accu_splits>[^\"]*)\"");
g_string_assign (gui->regexp, "^((?<id>[^\";]*)|\"(?<id>[^\"]*)\");((?<date_opened>[^\";]*)|\"(?<date_opened>[^\"]*)\");((?<owner_id>[^\";]*)|\"(?<owner_id>[^\"]*)\");((?<billing_id>[^\";]*)|\"(?<billing_id>[^\"]*)\");((?<notes>[^\";]*)|\"(?<notes>[^\"]*)\");((?<date>[^\";]*)|\"(?<date>[^\"]*)\");((?<desc>[^\";]*)|\"(?<desc>[^\"]*)\");((?<action>[^\";]*)|\"(?<action>[^\"]*)\");((?<account>[^\";]*)|\"(?<account>[^\"]*)\");((?<quantity>[^\";]*)|\"(?<quantity>[^\"]*)\");((?<price>[^\";]*)|\"(?<price>[^\"]*)\");((?<disc_type>[^\";]*)|\"(?<disc_type>[^\"]*)\");((?<disc_how>[^\";]*)|\"(?<disc_how>[^\"]*)\");((?<discount>[^\";]*)|\"(?<discount>[^\"]*)\");((?<taxable>[^\";]*)|\"(?<taxable>[^\"]*)\");((?<taxincluded>[^\";]*)|\"(?<taxincluded>[^\"]*)\");((?<tax_table>[^\";]*)|\"(?<tax_table>[^\"]*)\");((?<date_posted>[^\";]*)|\"(?<date_posted>[^\"]*)\");((?<due_date>[^\";]*)|\"(?<due_date>[^\"]*)\");((?<account_posted>[^\";]*)|\"(?<account_posted>[^\"]*)\");((?<memo_posted>[^\";]*)|\"(?<memo_posted>[^\"]*)\");((?<accu_splits>[^\";]*)|\"(?<accu_splits>[^\"]*)\")$");
gnc_bi_import_gui_filenameChanged_cb (gui->entryFilename, gui);
}
void gnc_bi_import_gui_option4_cb (GtkWidget *widget, gpointer data)
@ -317,7 +317,7 @@ void gnc_bi_import_gui_option4_cb (GtkWidget *widget, gpointer data)
BillImportGui *gui = data;
if (!gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(widget) ))
return;
g_string_assign (gui->regexp, "^\"(?<id>[^!#+^\"]*)\",\"(?<date_opened>[^\"]*)\",\"(?<owner_id>[^\"]*)\",\"(?<billing_id>[^\"]*)\",\"?(?<notes>[^\"]*)\",\"?(?<date>[^\"]*)\",\"?(?<desc>[^\"]*)\",\"?(?<action>[^\"]*)\",\"?(?<account>[^\"]*)\",\"?(?<quantity>[^\"]*)\",\"?(?<price>[^\"]*)\",\"?(?<disc_type>[^\"]*)\",\"?(?<disc_how>[^\"]*)\",\"?(?<discount>[^\"]*)\",\"?(?<taxable>[^\"]*)\",\"?(?<taxincluded>[^\"]*)\",\"?(?<tax_table>[^\"]*)\",\"(?<date_posted>[^\"]*)\",\"(?<due_date>[^\"]*)\",\"(?<account_posted>[^\"]*)\",\"(?<memo_posted>[^\"]*)\",\"(?<accu_splits>[^\"]*)\"");
g_string_assign (gui->regexp, "^((?<id>[^\",]*)|\"(?<id>[^\"]*)\"),((?<date_opened>[^\",]*)|\"(?<date_opened>[^\"]*)\"),((?<owner_id>[^\",]*)|\"(?<owner_id>[^\"]*)\"),((?<billing_id>[^\",]*)|\"(?<billing_id>[^\"]*)\"),((?<notes>[^\",]*)|\"(?<notes>[^\"]*)\"),((?<date>[^\",]*)|\"(?<date>[^\"]*)\"),((?<desc>[^\",]*)|\"(?<desc>[^\"]*)\"),((?<action>[^\",]*)|\"(?<action>[^\"]*)\"),((?<account>[^\",]*)|\"(?<account>[^\"]*)\"),((?<quantity>[^\",]*)|\"(?<quantity>[^\"]*)\"),((?<price>[^\",]*)|\"(?<price>[^\"]*)\"),((?<disc_type>[^\",]*)|\"(?<disc_type>[^\"]*)\"),((?<disc_how>[^\",]*)|\"(?<disc_how>[^\"]*)\"),((?<discount>[^\",]*)|\"(?<discount>[^\"]*)\"),((?<taxable>[^\",]*)|\"(?<taxable>[^\"]*)\"),((?<taxincluded>[^\",]*)|\"(?<taxincluded>[^\"]*)\"),((?<tax_table>[^\",]*)|\"(?<tax_table>[^\"]*)\"),((?<date_posted>[^\",]*)|\"(?<date_posted>[^\"]*)\"),((?<due_date>[^\",]*)|\"(?<due_date>[^\"]*)\"),((?<account_posted>[^\",]*)|\"(?<account_posted>[^\"]*)\"),((?<memo_posted>[^\",]*)|\"(?<memo_posted>[^\"]*)\"),((?<accu_splits>[^\",]*)|\"(?<accu_splits>[^\"]*)\")$");
gnc_bi_import_gui_filenameChanged_cb (gui->entryFilename, gui);
}
void gnc_bi_import_gui_option5_cb (GtkWidget *widget, gpointer data)