From 28e49fdc3673445257be5213c1a264fe8767bffd Mon Sep 17 00:00:00 2001 From: hiro Date: Wed, 29 Nov 2017 07:53:24 +0000 Subject: addressbook: implemented CSV export feature. git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@3584 ee746299-78ed-0310-b773-934348b2243d --- libsylph/libsylph-0.def | 1 + libsylph/utils.c | 40 +++++++++++++++++++++++++++++++++++++++- libsylph/utils.h | 6 +++++- 3 files changed, 45 insertions(+), 2 deletions(-) (limited to 'libsylph') diff --git a/libsylph/libsylph-0.def b/libsylph/libsylph-0.def index 7f9a4a6c..f625f1f5 100644 --- a/libsylph/libsylph-0.def +++ b/libsylph/libsylph-0.def @@ -711,3 +711,4 @@ EXPORTS procmsg_save_message_as_text @ 710 procmime_get_tmp_file_name_for_user @ 711 procmime_scan_message_stream @ 712 + strconcat_csv @ 713 diff --git a/libsylph/utils.c b/libsylph/utils.c index 1e40d52f..a76d0a55 100644 --- a/libsylph/utils.c +++ b/libsylph/utils.c @@ -1,6 +1,6 @@ /* * LibSylph -- E-Mail client library - * Copyright (C) 1999-2013 Hiroyuki Yamamoto + * Copyright (C) 1999-2017 Hiroyuki Yamamoto * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -1730,6 +1730,44 @@ gchar **strsplit_csv(const gchar *str, gchar delim, gint max_tokens) return str_array; } +gchar *strconcat_csv(gchar delim, const gchar *field1, ...) +{ + va_list args; + gchar *s; + GString *csv; + gint count = 0; + const gchar *p; + + g_return_val_if_fail(field1 != NULL, NULL); + + csv = g_string_new(""); + + va_start(args, field1); + s = (gchar *)field1; + while (s) { + gboolean add_quote = FALSE; + + if (count > 0) + g_string_append_c(csv, delim); + if (delim != '\t' && strchr(s, delim) != NULL) + add_quote = TRUE; + if (add_quote) + g_string_append_c(csv, '"'); + for (p = s; *p != '\0'; p++) { + if (*p == '"') + g_string_append_c(csv, '"'); + g_string_append_c(csv, *p); + } + if (add_quote) + g_string_append_c(csv, '"'); + count++; + s = va_arg(args, gchar*); + } + va_end(args); + + return g_string_free(csv, FALSE); +} + gchar *get_abbrev_newsgroup_name(const gchar *group, gint len) { gchar *abbrev_group; diff --git a/libsylph/utils.h b/libsylph/utils.h index 8fedd9d0..9ac65cf4 100644 --- a/libsylph/utils.h +++ b/libsylph/utils.h @@ -1,6 +1,6 @@ /* * LibSylph -- E-Mail client library - * Copyright (C) 1999-2013 Hiroyuki Yamamoto + * Copyright (C) 1999-2017 Hiroyuki Yamamoto * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -386,6 +386,10 @@ gchar **strsplit_csv (const gchar *str, gchar delim, gint max_tokens); +gchar *strconcat_csv (gchar delim, + const gchar *field1, + ...) G_GNUC_MALLOC G_GNUC_NULL_TERMINATED; + gchar *get_abbrev_newsgroup_name (const gchar *group, gint len); gchar *trim_string (const gchar *str, -- cgit v1.2.3