[evolution-data-server] Add e_util_strdup_strip().
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] Add e_util_strdup_strip().
- Date: Wed, 23 May 2012 00:02:50 +0000 (UTC)
commit 2d64b73d963637554221b3784a4c7ed5da1cf999
Author: Matthew Barnes <mbarnes redhat com>
Date: Tue May 22 19:55:03 2012 -0400
Add e_util_strdup_strip().
Duplicates an input string and strips off any leading or trailing
whitespace. The resulting string is returned unless it is empty or
NULL, in which case the function returns NULL.
Useful in "set" functions for string properties.
Helps avoid expressions like (str != NULL && *str != '\0').
.../libedataserver/libedataserver-sections.txt | 1 +
libedataserver/e-data-server-util.c | 31 ++++++++++++++++++++
libedataserver/e-data-server-util.h | 1 +
3 files changed, 33 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/libedataserver/libedataserver-sections.txt b/docs/reference/libedataserver/libedataserver-sections.txt
index 9936e20..e666219 100644
--- a/docs/reference/libedataserver/libedataserver-sections.txt
+++ b/docs/reference/libedataserver/libedataserver-sections.txt
@@ -534,6 +534,7 @@ tm
e_get_user_cache_dir
e_get_user_config_dir
e_get_user_data_dir
+e_util_strdup_strip
e_util_strstrcase
e_util_unicode_get_utf8
e_util_utf8_strstrcase
diff --git a/libedataserver/e-data-server-util.c b/libedataserver/e-data-server-util.c
index 0d7e891..37f2bf7 100644
--- a/libedataserver/e-data-server-util.c
+++ b/libedataserver/e-data-server-util.c
@@ -124,6 +124,37 @@ e_get_user_data_dir (void)
}
/**
+ * e_util_strdup_strip:
+ * @string: (allow-none): a string value, or %NULL
+ *
+ * Duplicates @string and strips off any leading or trailing whitespace.
+ * The resulting string is returned unless it is empty or %NULL, in which
+ * case the function returns %NULL.
+ *
+ * Free the returned string with g_free().
+ *
+ * Returns: a newly-allocated, stripped copy of @string, or %NULL
+ *
+ * Since: 3.6
+ **/
+gchar *
+e_util_strdup_strip (const gchar *string)
+{
+ gchar *duplicate;
+
+ duplicate = g_strdup (string);
+ if (duplicate != NULL) {
+ g_strstrip (duplicate);
+ if (*duplicate == '\0') {
+ g_free (duplicate);
+ duplicate = NULL;
+ }
+ }
+
+ return duplicate;
+}
+
+/**
* e_util_strstrcase:
* @haystack: The string to search in.
* @needle: The string to search for.
diff --git a/libedataserver/e-data-server-util.h b/libedataserver/e-data-server-util.h
index 4deb2c9..f9ba9cb 100644
--- a/libedataserver/e-data-server-util.h
+++ b/libedataserver/e-data-server-util.h
@@ -33,6 +33,7 @@ const gchar * e_get_user_cache_dir (void);
const gchar * e_get_user_config_dir (void);
const gchar * e_get_user_data_dir (void);
+gchar * e_util_strdup_strip (const gchar *string);
gchar * e_util_strstrcase (const gchar *haystack,
const gchar *needle);
gchar * e_util_unicode_get_utf8 (const gchar *text,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]