}
-
-gchar*
+/* for optimization reasons, we change the string in-place */
+void
modest_text_utils_get_display_address (gchar *address)
{
- gchar *cursor;
+ int i;
if (!address)
- return NULL;
+ return;
- g_return_val_if_fail (g_utf8_validate (address, -1, NULL), NULL);
+ /* should not be needed, and otherwise, we probably won't screw up the address
+ * more than it already is :)
+ * g_return_val_if_fail (g_utf8_validate (address, -1, NULL), NULL);
+ * */
- g_strchug (address); /* remove leading whitespace */
+ /* remove leading whitespace */
+ if (address[0] == ' ')
+ g_strchug (address);
+
+ for (i = 0; address[i]; ++i) {
+ if (address[i] == '<') {
+ if (G_UNLIKELY(i == 0))
+ return; /* there's nothing else, leave it */
+ else {
+ address[i] = '\0'; /* terminate the string here */
+ return;
+ }
+ }
+ }
+}
- /* <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';
- /* 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;
-}
gchar *
modest_text_utils_get_email_address (const gchar *full_address)
regex_t rx;
const gchar* domain_regex = "^[a-z0-9]([.]?[a-z0-9-])*[a-z0-9]$";
+ memset (&rx, 0, sizeof(regex_t)); /* coverity wants this... */
+
if (!domain)
return FALSE;