and make it a bit faster.
pmo-trunk-r3507
gint notif_id;
display_date = modest_text_utils_get_display_date (tny_header_get_date_received (header));
- display_address = modest_text_utils_get_display_address (tny_header_get_from (header));
+
+ display_address = g_strdup(tny_header_get_from (header));
+ modest_text_utils_get_display_address (display_address); /* string is changed in-place */
+
summary = g_strdup_printf ("%s - %s", display_date, display_address);
notification = hildon_notification_new (summary,
tny_header_get_subject (header),
}
-gchar*
-modest_text_utils_get_display_address (const gchar *address)
+/* for optimization reasons, we change the string in-place */
+void
+modest_text_utils_get_display_address (gchar *address)
{
- gchar *display;
- gchar **tokens;
- gint i = 0;
+ int i;
if (!address)
- return NULL;
-
- g_return_val_if_fail (g_utf8_validate (address, -1, NULL), NULL);
+ return;
- tokens = g_strsplit_set ((const gchar*) address, "<>()", 3);
-
- /* Note that if any of the delimiters is the first character
- then g_strsplit_set will return "" as the first string */
- while (tokens[i] != NULL) {
- if (strlen ((char *) (tokens[i])) != 0)
- break;
- i++;
+ /* 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);
+ * */
+
+ /* 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;
+ }
+ }
}
+}
+
- display = g_strdup (tokens [i]);
- g_strchug (display);
- /* Free the other tokens */
- g_strfreev (tokens);
- return display;
-}
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;
* @address: original address (UTF8 string)
*
* make a 'display address' from an address:
- * "Foo Bar <foo@bar.cx> (Bla)" --> "Foo Bar"
- * ie. removes "<...>" and "(...)" parts
- * the change is in-place; removes leading/trailing whitespace
+ * "Foo Bar <foo@bar.cx>" --> "Foo Bar"
+ * ie. removes "<...>" parts
+ * the change is in-place; removes leading whitespace
*
- * Returns: a new allocated string with the display address. NULL in
- * case of error or if address == NULL
+ * NOTE: for optimization reasons, this function changes @address
+ * in-place
*/
-gchar* modest_text_utils_get_display_address (const gchar *address);
+void modest_text_utils_get_display_address (gchar *address);
/**
* modest_text_utils_get_email_address:
USER_NAME_FORBIDDEN_NAMES,
} ModestTextUtilsForbiddenCharType;
+
+/**
+ * modest_text_utils_is_forbidden_char:
+ * @character: some character
+ * @type: the type of forbidden char (see #ModestTextUtilsForbiddenCharType)
+ *
+ * check whether the given character is 'forbidden'
+ *
+ * Returns: TRUE if it's forbidden, FALSE otherwise
+ */
gboolean modest_text_utils_is_forbidden_char (const gchar character,
ModestTextUtilsForbiddenCharType type);
+
#endif /* __MODEST_TEXT_UTILS_H__ */
gboolean is_sender)
{
TnyHeaderFlags flags;
- gchar *address, *display_address;
+ gchar *address;
gint sender_receiver_col;
if (is_sender)
TNY_GTK_HEADER_LIST_MODEL_FLAGS_COLUMN, &flags,
-1);
- display_address = modest_text_utils_get_display_address (address);
+ modest_text_utils_get_display_address (address); /* string is changed in-place */
g_object_set (G_OBJECT(renderer),
"text",
- display_address,
+ address,
NULL);
- g_free (display_address);
g_free (address);
+
set_common_flags (renderer, flags);
}
/*
TnyHeaderFlags flags = 0;
TnyHeaderFlags prior_flags = 0;
- gchar *address = NULL, *display_address;
+ gchar *address = NULL;
gchar *subject = NULL;
gchar *header = NULL;
time_t date = 0;
/* FIXME: we hardcode the color to #666666; instead we should use SecondaryTextColour from the
* theme (gtkrc file) */
- display_address = modest_text_utils_get_display_address (address);
+ modest_text_utils_get_display_address (address); /* changed in-place */
header = g_markup_printf_escaped ("<span size='small' foreground='#666666'>%s</span>",
- display_address);
- g_free (display_address);
+ address);
g_free (address);
- address = display_address = NULL;
g_object_set (G_OBJECT (recipient_cell),
"markup", header,
NULL);