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
This commit is contained in:
parent
26c4e5983c
commit
2a45938205
@ -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>
|
2011-04-19 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
|
||||||
|
|
||||||
* src/editor.c:
|
* src/editor.c:
|
||||||
|
@ -262,6 +262,8 @@
|
|||||||
geany_functions->p_utils->utils_copy_environment
|
geany_functions->p_utils->utils_copy_environment
|
||||||
#define utils_find_open_xml_tag \
|
#define utils_find_open_xml_tag \
|
||||||
geany_functions->p_utils->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 \
|
#define ui_dialog_vbox_new \
|
||||||
geany_functions->p_ui->ui_dialog_vbox_new
|
geany_functions->p_ui->ui_dialog_vbox_new
|
||||||
#define ui_frame_new_with_alignment \
|
#define ui_frame_new_with_alignment \
|
||||||
|
@ -54,7 +54,7 @@
|
|||||||
* @warning You should not test for values below 200 as previously
|
* @warning You should not test for values below 200 as previously
|
||||||
* @c GEANY_API_VERSION was defined as an enum value, not a macro.
|
* @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
|
/** The Application Binary Interface (ABI) version, incremented whenever
|
||||||
* existing fields in the plugin data types have to be changed or reordered.
|
* existing fields in the plugin data types have to be changed or reordered.
|
||||||
@ -439,6 +439,7 @@ typedef struct UtilsFuncs
|
|||||||
GError **error);
|
GError **error);
|
||||||
gchar** (*utils_copy_environment)(const gchar **exclude_vars, const gchar *first_varname, ...);
|
gchar** (*utils_copy_environment)(const gchar **exclude_vars, const gchar *first_varname, ...);
|
||||||
gchar* (*utils_find_open_xml_tag) (const gchar sel[], gint size);
|
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;
|
UtilsFuncs;
|
||||||
|
|
||||||
|
@ -225,7 +225,8 @@ static UtilsFuncs utils_funcs = {
|
|||||||
&utils_str_remove_chars,
|
&utils_str_remove_chars,
|
||||||
&utils_get_file_list_full,
|
&utils_get_file_list_full,
|
||||||
&utils_copy_environment,
|
&utils_copy_environment,
|
||||||
&utils_find_open_xml_tag
|
&utils_find_open_xml_tag,
|
||||||
|
&utils_find_open_xml_tag_pos
|
||||||
};
|
};
|
||||||
|
|
||||||
static UIUtilsFuncs uiutils_funcs = {
|
static UIUtilsFuncs uiutils_funcs = {
|
||||||
|
49
src/utils.c
49
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 sel .
|
||||||
* @param size .
|
* @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)
|
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 */
|
/* stolen from anjuta and modified */
|
||||||
const gchar *begin, *cur;
|
const gchar *begin, *cur;
|
||||||
@ -319,27 +344,15 @@ gchar *utils_find_open_xml_tag(const gchar sel[], gint size)
|
|||||||
{
|
{
|
||||||
if (*cur == '<')
|
if (*cur == '<')
|
||||||
break;
|
break;
|
||||||
|
/* exit immediately if such non-valid XML/HTML is detected, e.g. "<script>if a >" */
|
||||||
else if (*cur == '>')
|
else if (*cur == '>')
|
||||||
break;
|
break;
|
||||||
--cur;
|
--cur;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*cur == '<')
|
/* if the found tag is an opening, not a closing tag or empty <> */
|
||||||
{
|
if (*cur == '<' && *(cur + 1) != '/' && *(cur + 1) != '>')
|
||||||
GString *result;
|
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;
|
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);
|
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);
|
gboolean utils_is_short_html_tag(const gchar *tag_name);
|
||||||
|
|
||||||
void utils_ensure_same_eol_characters(GString *string, gint target_eol_mode);
|
void utils_ensure_same_eol_characters(GString *string, gint target_eol_mode);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user