diff --git a/ChangeLog b/ChangeLog index 7a2600b4c..ee9020af9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2011-04-23 Nick Treleaven + + * 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 * src/editor.c: diff --git a/plugins/geanyfunctions.h b/plugins/geanyfunctions.h index 8814cfcd8..5af341edf 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 a831cb777..444f5ed7a 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 886332cfe..66c7d9e3d 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 5ea604272..6600decee 100644 --- a/src/utils.c +++ b/src/utils.c @@ -285,12 +285,37 @@ 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; + 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,27 +344,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. "