/** A set of sensible defaults for parsing CSV files. * @return StfParseOptions_t* for parsing a file with comma separators */ static StfParseOptions_t* default_parse_options (void) { StfParseOptions_t* options = stf_parse_options_new(); stf_parse_options_set_type (options, PARSE_TYPE_CSV); stf_parse_options_csv_set_separators (options, ",", NULL); return options; }
/** * csv_page_global_change * @widget : the widget which emitted the signal * @data : mother struct * * This will update the preview based on the state of * the widgets on the csv page * * returns : nothing **/ static void csv_page_global_change (G_GNUC_UNUSED GtkWidget *widget, StfDialogData *pagedata) { StfParseOptions_t *parseoptions = pagedata->parseoptions; RenderData_t *renderdata = pagedata->csv.renderdata; GSList *sepstr; GString *sepc = g_string_new (NULL); GStringChunk *lines_chunk; GPtrArray *lines; StfTrimType_t trim; sepstr = NULL; if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (pagedata->csv.csv_custom))) { char *csvcustomtext = gtk_editable_get_chars (GTK_EDITABLE (pagedata->csv.csv_customseparator), 0, -1); if (strcmp (csvcustomtext, "") != 0) sepstr = g_slist_append (sepstr, csvcustomtext); else g_free (csvcustomtext); } if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (pagedata->csv.csv_tab))) g_string_append_c (sepc, '\t'); if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (pagedata->csv.csv_colon))) g_string_append_c (sepc, ':'); if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (pagedata->csv.csv_comma))) g_string_append_c (sepc, ','); if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (pagedata->csv.csv_space))) g_string_append_c (sepc, ' '); if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (pagedata->csv.csv_semicolon))) g_string_append_c (sepc, ';'); if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (pagedata->csv.csv_hyphen))) g_string_append_c (sepc, '-'); stf_parse_options_csv_set_separators (parseoptions, strcmp (sepc->str, "") == 0 ? NULL : sepc->str, sepstr); g_string_free (sepc, TRUE); go_slist_free_custom (sepstr, g_free); stf_parse_options_csv_set_duplicates (parseoptions, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (pagedata->csv.csv_duplicates))); stf_parse_options_csv_set_trim_seps (parseoptions, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (pagedata->csv.csv_trim_seps))); lines_chunk = g_string_chunk_new (100 * 1024); /* Don't trim on this page. */ trim = parseoptions->trim_spaces; stf_parse_options_set_trim_spaces (parseoptions, TRIM_TYPE_NEVER); lines = stf_parse_general (parseoptions, lines_chunk, pagedata->cur, pagedata->cur_end); stf_parse_options_set_trim_spaces (parseoptions, trim); stf_preview_set_lines (renderdata, lines_chunk, lines); }
static void test_gnc_csv_parse_semicolon_sep (Fixture *fixture, gconstpointer pData) { GSList* sep_list = NULL; sep_list = g_slist_append (sep_list, ";"); stf_parse_options_csv_set_separators (fixture->parse_data->options, NULL, sep_list); g_slist_free (sep_list); test_gnc_csv_parse_helper (fixture->parse_data, pData); }