g_return_val_if_fail (g_utf8_validate (address, -1, NULL), NULL);
- /* simplistic --> remove <email@address> from display name */
+ g_strchug (address); /* remove leading whitespace */
+
+ /* <email@address> from display name */
cursor = g_strstr_len (address, strlen(address), "<");
+ if (cursor == address) /* there's nothing else? leave it */
+ return address;
if (cursor)
cursor[0]='\0';
- /* simplistic --> remove (bla bla) from display name */
+ /* remove (bla bla) from display name */
cursor = g_strstr_len (address, strlen(address), "(");
+ if (cursor == address) /* there's nothing else? leave it */
+ return address;
if (cursor)
cursor[0]='\0';
-
+
+ g_strchomp (address); /* remove trailing whitespace */
+
return address;
}
#define __MODEST_TEXT_UTILS_H__
#include <time.h>
+#include <glib.h>
/**
* modest_text_utils_derived_subject:
* @address: original address (UTF8 string)
*
* make a 'display address' from an address:
- * "Foo Bar <foo@bar.cx> (Bla)" --> "Foo Bar"
- * the change is in-place
+ * "Foo Bar <foo@bar.cx> (Bla)" --> "Foo Bar"
+ * ie. removes "<...>" and "(...)" parts
+ * the change is in-place; removes leading/trailing whitespace
*
* Returns: the new address. The string is *not* newly allocated.
* NULL in case of error