[evolution] EHTMLEditorUtils - Correctly remove class when it is surrounded by spaces
- From: Tomas Popela <tpopela src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution] EHTMLEditorUtils - Correctly remove class when it is surrounded by spaces
- Date: Wed, 29 Jun 2016 13:20:32 +0000 (UTC)
commit c170dd43ffaadc916f5fae7cbb329a9ee2ff5745
Author: Tomas Popela <tpopela redhat com>
Date: Wed Jun 29 13:41:14 2016 +0200
EHTMLEditorUtils - Correctly remove class when it is surrounded by spaces
Avoid the leftover spaces to remain in the class attribute.
e-util/e-html-editor-utils.c | 25 +++++++++++++------------
1 files changed, 13 insertions(+), 12 deletions(-)
---
diff --git a/e-util/e-html-editor-utils.c b/e-util/e-html-editor-utils.c
index 2899e92..be5b8c9 100644
--- a/e-util/e-html-editor-utils.c
+++ b/e-util/e-html-editor-utils.c
@@ -253,8 +253,9 @@ void
element_remove_class (WebKitDOMElement *element,
const gchar* class)
{
- gchar *element_class;
- GString *result;
+ gchar *element_class, *final_class;
+ GRegex *regex;
+ gchar *pattern = NULL;
if (!WEBKIT_DOM_IS_ELEMENT (element))
return;
@@ -264,19 +265,19 @@ element_remove_class (WebKitDOMElement *element,
element_class = webkit_dom_element_get_class_name (element);
- if (g_strcmp0 (element_class, class) == 0) {
- webkit_dom_element_remove_attribute (element, "class");
- g_free (element_class);
- return;
- }
+ pattern = g_strconcat ("[\\s]*", class, "[\\s]*", NULL);
+ regex = g_regex_new (pattern, 0, 0, NULL);
+ final_class = g_regex_replace (regex, element_class, -1, 0, " ", 0, NULL);
- result = e_str_replace_string (element_class, class, "");
- if (result) {
- webkit_dom_element_set_class_name (element, result->str);
- g_string_free (result, TRUE);
- }
+ if (g_strcmp0 (final_class, " ") != 0)
+ webkit_dom_element_set_class_name (element, final_class);
+ else
+ webkit_dom_element_remove_attribute (element, "class");
g_free (element_class);
+ g_free (final_class);
+ g_free (pattern);
+ g_regex_unref (regex);
}
void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]