Kaydet (Commit) 2a459382 authored tarafından Nick Treleaven's avatar Nick Treleaven

Add utils_find_open_xml_tag_pos() API function (patch by Eugene

Arshinov, thanks).



git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@5733 ea778897-0a13-0410-b9d1-a72fbfd435f5
üst 26c4e598
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:
......
......@@ -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 \
......
......@@ -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;
......
......@@ -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 = {
......
......@@ -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. "<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 the found tag is an opening, not a closing tag or empty <> */
if (*cur == '<' && *(cur + 1) != '/' && *(cur + 1) != '>')
return cur;
return NULL;
}
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment