From 50f72ab6a11e25dbf9431c06adb3f7f16315befe Mon Sep 17 00:00:00 2001 From: hiro Date: Thu, 30 Nov 2017 02:40:07 +0000 Subject: addressbook csv export: fixed double-quote escape and added header line. git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@3587 ee746299-78ed-0310-b773-934348b2243d --- libsylph/utils.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'libsylph') diff --git a/libsylph/utils.c b/libsylph/utils.c index a76d0a55..aabce066 100644 --- a/libsylph/utils.c +++ b/libsylph/utils.c @@ -1730,6 +1730,12 @@ gchar **strsplit_csv(const gchar *str, gchar delim, gint max_tokens) return str_array; } +/* Concatenate multiple strings into a CSV (TSV) record. + * If delimiter characters or double-quotes appear in the string, + it is enclosed by double quotes. + * Double quote characters are escaped by another double quote. + * Strings must not include line breaks in this implementation. + */ gchar *strconcat_csv(gchar delim, const gchar *field1, ...) { va_list args; @@ -1749,7 +1755,7 @@ gchar *strconcat_csv(gchar delim, const gchar *field1, ...) if (count > 0) g_string_append_c(csv, delim); - if (delim != '\t' && strchr(s, delim) != NULL) + if (strchr(s, delim) != NULL || strchr(s, '"') != NULL) add_quote = TRUE; if (add_quote) g_string_append_c(csv, '"'); -- cgit v1.2.3