* modest-text-utils.[ch]:
authorDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Mon, 11 Dec 2006 12:42:15 +0000 (12:42 +0000)
committerDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Mon, 11 Dec 2006 12:42:15 +0000 (12:42 +0000)
  - modest_text_utils_display_address:
    small cleanup, clarifications --> unit tests work

pmo-trunk-r540

src/modest-text-utils.c
src/modest-text-utils.h

index 1fb11e7..0900a69 100644 (file)
@@ -664,16 +664,24 @@ modest_text_utils_display_address (gchar *address)
 
        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;
 }
 
index 05a4b9b..d85db84 100644 (file)
@@ -34,6 +34,7 @@
 #define __MODEST_TEXT_UTILS_H__
 
 #include <time.h>
+#include <glib.h>
 
 /**
  * modest_text_utils_derived_subject:
@@ -145,8 +146,9 @@ size_t modest_text_utils_strftime(char *s, size_t max, const char  *fmt, const
  * @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