aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/gui/dialogs/comp-editor-util.c
diff options
context:
space:
mode:
authorFederico Mena Quintero <federico@ximian.com>2001-08-17 04:27:04 +0800
committerFederico Mena Quintero <federico@src.gnome.org>2001-08-17 04:27:04 +0800
commitced6dc05f895375377fe0f063e6c572a884ed3a0 (patch)
tree9dbc9d3549131192640ead44375b7dfda34cd504 /calendar/gui/dialogs/comp-editor-util.c
parent23c322c8934fb690cf1cbf9e155310e406892b75 (diff)
downloadgsoc2013-evolution-ced6dc05f895375377fe0f063e6c572a884ed3a0.tar
gsoc2013-evolution-ced6dc05f895375377fe0f063e6c572a884ed3a0.tar.gz
gsoc2013-evolution-ced6dc05f895375377fe0f063e6c572a884ed3a0.tar.bz2
gsoc2013-evolution-ced6dc05f895375377fe0f063e6c572a884ed3a0.tar.lz
gsoc2013-evolution-ced6dc05f895375377fe0f063e6c572a884ed3a0.tar.xz
gsoc2013-evolution-ced6dc05f895375377fe0f063e6c572a884ed3a0.tar.zst
gsoc2013-evolution-ced6dc05f895375377fe0f063e6c572a884ed3a0.zip
New function to strip surrounding whitespace from a string of categories
2001-08-16 Federico Mena Quintero <federico@ximian.com> * gui/dialogs/comp-editor-util.c (comp_editor_strip_categories): New function to strip surrounding whitespace from a string of categories entered by the user. * gui/dialogs/task-page.c (task_page_fill_component): Use comp_editor_strip_categories(). * gui/dialogs/event-page.c (event_page_fill_component): Likewise. svn path=/trunk/; revision=12122
Diffstat (limited to 'calendar/gui/dialogs/comp-editor-util.c')
-rw-r--r--calendar/gui/dialogs/comp-editor-util.c71
1 files changed, 71 insertions, 0 deletions
diff --git a/calendar/gui/dialogs/comp-editor-util.c b/calendar/gui/dialogs/comp-editor-util.c
index 8ef7aebbab..df682f6880 100644
--- a/calendar/gui/dialogs/comp-editor-util.c
+++ b/calendar/gui/dialogs/comp-editor-util.c
@@ -472,3 +472,74 @@ comp_editor_contacts_to_component (GtkWidget *contacts_entry,
}
g_slist_free (contact_list);
}
+
+/**
+ * comp_editor_strip_categories:
+ * @categories: A string of category names entered by the user.
+ *
+ * Takes a string of the form "categ, categ, categ, ..." and removes the
+ * whitespace between categories to result in "categ,categ,categ,..."
+ *
+ * Return value: The category names stripped of surrounding whitespace
+ * and separated with commas.
+ **/
+char *
+comp_editor_strip_categories (const char *categories)
+{
+ char *new_categories;
+ const char *start, *end;
+ const char *p;
+ char *new_p;
+
+ if (!categories)
+ return NULL;
+
+ new_categories = g_new (char, strlen (categories) + 1);
+
+ start = end = NULL;
+ new_p = new_categories;
+
+ for (p = categories; *p; p++) {
+ int c;
+
+ c = *p;
+
+ if (isspace (c))
+ continue;
+ else if (c == ',') {
+ int len;
+
+ if (!start)
+ continue;
+
+ g_assert (start <= end);
+
+ len = end - start + 1;
+ strncpy (new_p, start, len);
+ new_p[len] = ',';
+ new_p += len + 1;
+
+ start = end = NULL;
+ } else {
+ if (!start) {
+ start = p;
+ end = p;
+ } else
+ end = p;
+ }
+ }
+
+ if (start) {
+ int len;
+
+ g_assert (start <= end);
+
+ len = end - start + 1;
+ strncpy (new_p, start, len);
+ new_p += len;
+ }
+
+ *new_p = '\0';
+
+ return new_categories;
+}