Hi Nick.

On Thu, 21 Apr 2011 14:21:39 +0100%
Nick Treleaven <nick.trelea...@btinternet.com> wrote:

> On Sun, 3 Apr 2011 15:05:21 +0400
> Eugene Arshinov <earshi...@gmail.com> wrote:
> 
> > If anyone has some free time for me, please take a look at a
> > message I sent in November [1].  There I attached two patches for
> > Geany which were (and still are) necessary for XML Snippets plugin
> > that was discussed in that thread.  You can also read at [1] about
> > what the patches do.
> > 
> > Now I attach the updated patches.  Hope they will become a part of
> > Geany and the plugin (not yet released anywhere) will no longer
> > depend on these «third-party» patches.
> 
> I've now fixed the bug with {ob}pc{cb} in a different way and cleaned
> up the original code so the cursor positions is handled quite simply,
> also fixing tabs+spaces mode cursor positions.

Okay, thank you for this change.  I saw that your implementation is
shorter and simpler than mine.

> 
> I'm not sure that exposing editor_snippets_make_replacements() is a
> good idea.

This is actually a bug in the patch…  The plugin does not need this
function.  Updated patch (which only adds utils_find_open_xml_tag_pos)
attached.

--
Best regards,
Eugene.
diff --git a/ChangeLog b/ChangeLog
index 7a2600b..29e5a99 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2011-04-19  Eugene Arshinov  <earshinov(at)gmail(dot)com>
+
+ * plugins/geanyfunctions.h, src/plugindata.h, src/plugins.c,
+   src/utils.c, src/utils.h:
+   Add utils_find_open_xml_tag_pos() function which was previously a
+   part of utils_find_open_xml_tag(). Add the new function to API.
+
+
 2011-04-19  Nick Treleaven  <nick(dot)treleaven(at)btinternet(dot)com>
 
  * src/editor.c:
diff --git a/plugins/geanyfunctions.h b/plugins/geanyfunctions.h
index 8814cfc..5af341e 100644
--- a/plugins/geanyfunctions.h
+++ b/plugins/geanyfunctions.h
@@ -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 \
diff --git a/src/plugindata.h b/src/plugindata.h
index a831cb7..444f5ed 100644
--- a/src/plugindata.h
+++ b/src/plugindata.h
@@ -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 @@ typedef struct UtilsFuncs
 				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;
 
diff --git a/src/plugins.c b/src/plugins.c
index 886332c..66c7d9e 100644
--- a/src/plugins.c
+++ b/src/plugins.c
@@ -225,7 +225,8 @@ static UtilsFuncs utils_funcs = {
 	&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 = {
diff --git a/src/utils.c b/src/utils.c
index 5ea6042..9125118 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -285,13 +285,34 @@ gint utils_write_file(const gchar *filename, const gchar *text)
 }
 
 
-/** 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;
+
+	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++;
+	return g_strndup(begin, cur-begin);
+}
+
+
+/** 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,27 +340,15 @@ gchar *utils_find_open_xml_tag(const gchar sel[], gint size)
 	{
 		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;
-
-		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);
-	}
+	if (*cur == '<' && *(cur+1) != '/')
+		/* if the found tag is an opening, not a closing tag */
+		return cur;
 
 	return NULL;
 }
diff --git a/src/utils.h b/src/utils.h
index d582c98..5a9ef08 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -142,6 +142,8 @@ gint utils_write_file(const gchar *filename, const gchar *text);
 
 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);
_______________________________________________
Geany-devel mailing list
Geany-devel@uvena.de
https://lists.uvena.de/cgi-bin/mailman/listinfo/geany-devel

Reply via email to