SF.net SVN: geany:[5733] trunk

ntrel at users.sourceforge.net ntrel at xxxxx
Sat Apr 23 11:44:31 UTC 2011


Revision: 5733
          http://geany.svn.sourceforge.net/geany/?rev=5733&view=rev
Author:   ntrel
Date:     2011-04-23 11:44:31 +0000 (Sat, 23 Apr 2011)

Log Message:
-----------
Add utils_find_open_xml_tag_pos() API function (patch by Eugene
Arshinov, thanks).

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/plugins/geanyfunctions.h
    trunk/src/plugindata.h
    trunk/src/plugins.c
    trunk/src/utils.c
    trunk/src/utils.h

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2011-04-20 13:53:12 UTC (rev 5732)
+++ trunk/ChangeLog	2011-04-23 11:44:31 UTC (rev 5733)
@@ -1,3 +1,11 @@
+2011-04-23  Nick Treleaven  <nick(dot)treleaven(at)btinternet(dot)com>
+
+ * src/utils.c, src/utils.h, src/plugindata.h, src/plugins.c,
+   plugins/geanyfunctions.h:
+   Add utils_find_open_xml_tag_pos() API function (patch by Eugene
+   Arshinov, thanks).
+
+
 2011-04-19  Nick Treleaven  <nick(dot)treleaven(at)btinternet(dot)com>
 
  * src/editor.c:

Modified: trunk/plugins/geanyfunctions.h
===================================================================
--- trunk/plugins/geanyfunctions.h	2011-04-20 13:53:12 UTC (rev 5732)
+++ trunk/plugins/geanyfunctions.h	2011-04-23 11:44:31 UTC (rev 5733)
@@ -262,6 +262,8 @@
 	geany_functions->p_utils->utils_copy_environment
 #define utils_find_open_xml_tag \
 	geany_functions->p_utils->utils_find_open_xml_tag
+#define utils_find_open_xml_tag_pos \
+	geany_functions->p_utils->utils_find_open_xml_tag_pos
 #define ui_dialog_vbox_new \
 	geany_functions->p_ui->ui_dialog_vbox_new
 #define ui_frame_new_with_alignment \

Modified: trunk/src/plugindata.h
===================================================================
--- trunk/src/plugindata.h	2011-04-20 13:53:12 UTC (rev 5732)
+++ trunk/src/plugindata.h	2011-04-23 11:44:31 UTC (rev 5733)
@@ -54,7 +54,7 @@
  * @warning You should not test for values below 200 as previously
  * @c GEANY_API_VERSION was defined as an enum value, not a macro.
  */
-#define GEANY_API_VERSION 209
+#define GEANY_API_VERSION 210
 
 /** The Application Binary Interface (ABI) version, incremented whenever
  * existing fields in the plugin data types have to be changed or reordered.
@@ -439,6 +439,7 @@
 				GError **error);
 	gchar**		(*utils_copy_environment)(const gchar **exclude_vars, const gchar *first_varname, ...);
 	gchar*		(*utils_find_open_xml_tag) (const gchar sel[], gint size);
+	const gchar*	(*utils_find_open_xml_tag_pos) (const gchar sel[], gint size);
 }
 UtilsFuncs;
 

Modified: trunk/src/plugins.c
===================================================================
--- trunk/src/plugins.c	2011-04-20 13:53:12 UTC (rev 5732)
+++ trunk/src/plugins.c	2011-04-23 11:44:31 UTC (rev 5733)
@@ -225,7 +225,8 @@
 	&utils_str_remove_chars,
 	&utils_get_file_list_full,
 	&utils_copy_environment,
-	&utils_find_open_xml_tag
+	&utils_find_open_xml_tag,
+	&utils_find_open_xml_tag_pos
 };
 
 static UIUtilsFuncs uiutils_funcs = {

Modified: trunk/src/utils.c
===================================================================
--- trunk/src/utils.c	2011-04-20 13:53:12 UTC (rev 5732)
+++ trunk/src/utils.c	2011-04-23 11:44:31 UTC (rev 5733)
@@ -285,13 +285,38 @@
 }
 
 
-/** Searches backward through @a size bytes looking for a '<', then returns the tag, if any.
+/** Searches backward through @a size bytes looking for a '<'.
  * @param sel .
  * @param size .
- * @return The tag name.
+ * @return The tag name (newly allocated) or @c NULL if no opening tag was found.
  */
 gchar *utils_find_open_xml_tag(const gchar sel[], gint size)
 {
+	const gchar *cur, *begin;
+	gint len;
+
+	cur = utils_find_open_xml_tag_pos(sel, size);
+	if (cur == NULL)
+		return NULL;
+
+	cur++; /* skip the bracket */
+	begin = cur;
+	while (strchr(":_-.", *cur) || isalnum(*cur))
+		cur++;
+
+	len = cur - begin;
+	g_return_val_if_fail(len, NULL);
+	return g_strndup(begin, len);
+}
+
+
+/** Searches backward through @a size bytes looking for a '<'.
+ * @param sel .
+ * @param size .
+ * @return pointer to '<' of the found opening tag within @a sel, or @c NULL if no opening tag was found.
+ */
+const gchar *utils_find_open_xml_tag_pos(const gchar sel[], gint size)
+{
 	/* stolen from anjuta and modified */
 	const gchar *begin, *cur;
 
@@ -319,28 +344,16 @@
 	{
 		if (*cur == '<')
 			break;
+		/* exit immediately if such non-valid XML/HTML is detected, e.g. "<script>if a >" */
 		else if (*cur == '>')
 			break;
 		--cur;
 	}
 
-	if (*cur == '<')
-	{
-		GString *result;
+	/* if the found tag is an opening, not a closing tag or empty <> */
+	if (*cur == '<' && *(cur + 1) != '/' && *(cur + 1) != '>')
+		return cur;
 
-		cur++;
-		if (*cur == '/')
-			return NULL; /* we found a closing tag */
-
-		result = g_string_sized_new(64);
-		while (strchr(":_-.", *cur) || isalnum(*cur))
-		{
-			g_string_append_c(result, *cur);
-			cur++;
-		}
-		return g_string_free(result, FALSE);
-	}
-
 	return NULL;
 }
 

Modified: trunk/src/utils.h
===================================================================
--- trunk/src/utils.h	2011-04-20 13:53:12 UTC (rev 5732)
+++ trunk/src/utils.h	2011-04-23 11:44:31 UTC (rev 5733)
@@ -142,6 +142,8 @@
 
 gchar *utils_find_open_xml_tag(const gchar sel[], gint size);
 
+const gchar *utils_find_open_xml_tag_pos(const gchar sel[], gint size);
+
 gboolean utils_is_short_html_tag(const gchar *tag_name);
 
 void utils_ensure_same_eol_characters(GString *string, gint target_eol_mode);


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the Commits mailing list