[evolution/wip/webkit2] 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/wip/webkit2] EHTMLEditorUtils - Correctly remove class when it is surrounded by spaces
- Date: Fri, 1 Jul 2016 13:08:43 +0000 (UTC)
commit 3a2b4e3cb22e4a0527f96ec7cb8f345c4d3f6a1d
Author: Tomas Popela <tpopela redhat com>
Date: Thu Jun 30 11:56:49 2016 +0200
EHTMLEditorUtils - Correctly remove class when it is surrounded by spaces
Avoid the leftover spaces to remain in the class attribute.
web-extensions/e-dom-utils.c | 25 +++++++++++++------------
1 files changed, 13 insertions(+), 12 deletions(-)
---
diff --git a/web-extensions/e-dom-utils.c b/web-extensions/e-dom-utils.c
index ef6248f..3820c84 100644
--- a/web-extensions/e-dom-utils.c
+++ b/web-extensions/e-dom-utils.c
@@ -1532,8 +1532,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;
@@ -1543,19 +1544,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]