diff options
author | Federico Mena Quintero <federico@ximian.com> | 2001-08-17 04:27:04 +0800 |
---|---|---|
committer | Federico Mena Quintero <federico@src.gnome.org> | 2001-08-17 04:27:04 +0800 |
commit | ced6dc05f895375377fe0f063e6c572a884ed3a0 (patch) | |
tree | 9dbc9d3549131192640ead44375b7dfda34cd504 /calendar/gui | |
parent | 23c322c8934fb690cf1cbf9e155310e406892b75 (diff) | |
download | gsoc2013-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')
-rw-r--r-- | calendar/gui/dialogs/comp-editor-util.c | 71 | ||||
-rw-r--r-- | calendar/gui/dialogs/comp-editor-util.h | 1 | ||||
-rw-r--r-- | calendar/gui/dialogs/event-page.c | 8 | ||||
-rw-r--r-- | calendar/gui/dialogs/task-page.c | 8 |
4 files changed, 84 insertions, 4 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; +} diff --git a/calendar/gui/dialogs/comp-editor-util.h b/calendar/gui/dialogs/comp-editor-util.h index 45c45a72a3..0654289698 100644 --- a/calendar/gui/dialogs/comp-editor-util.h +++ b/calendar/gui/dialogs/comp-editor-util.h @@ -47,5 +47,6 @@ void comp_editor_contacts_to_widget (GtkWidget *contacts_entry, void comp_editor_contacts_to_component (GtkWidget *contacts_entry, CalComponent *comp); +char *comp_editor_strip_categories (const char *categories); #endif diff --git a/calendar/gui/dialogs/event-page.c b/calendar/gui/dialogs/event-page.c index a3947b1cba..8f9d974178 100644 --- a/calendar/gui/dialogs/event-page.c +++ b/calendar/gui/dialogs/event-page.c @@ -644,11 +644,15 @@ event_page_fill_component (CompEditorPage *page, CalComponent *comp) /* Categories */ cat = e_dialog_editable_get (priv->categories); - cal_component_set_categories (comp, cat); - + str = comp_editor_strip_categories (cat); if (cat) g_free (cat); + cal_component_set_categories (comp, str); + + if (str) + g_free (str); + /* Classification */ classif = e_dialog_radio_get (priv->classification_public, diff --git a/calendar/gui/dialogs/task-page.c b/calendar/gui/dialogs/task-page.c index f6ad6da413..84eb1017d4 100644 --- a/calendar/gui/dialogs/task-page.c +++ b/calendar/gui/dialogs/task-page.c @@ -533,11 +533,15 @@ task_page_fill_component (CompEditorPage *page, CalComponent *comp) /* Categories */ cat = e_dialog_editable_get (priv->categories); - cal_component_set_categories (comp, cat); - + str = comp_editor_strip_categories (cat); if (cat) g_free (cat); + cal_component_set_categories (comp, str); + + if (str) + g_free (str); + /* Contacts */ comp_editor_contacts_to_component (priv->contacts_entry, comp); } |