script-fu: make regex matching return character indexes

Since tinyscheme uses utf-8 for strings match the behaviour for the
script-fu regex utilities as well. Fixes bug #764811
This commit is contained in:
Simon Budig 2016-05-25 20:17:02 +02:00
parent 5feba030ca
commit bdae0de1aa
1 changed files with 9 additions and 0 deletions

View File

@ -79,6 +79,7 @@ foreign_re_match (scheme *sc,
{
pointer retval = sc->F;
gboolean success;
gboolean is_valid_utf8;
GRegex *regex;
pointer first_arg, second_arg;
pointer third_arg = sc->NIL;
@ -98,6 +99,8 @@ foreign_re_match (scheme *sc,
pattern = sc->vptr->string_value (first_arg);
string = sc->vptr->string_value (second_arg);
is_valid_utf8 = g_utf8_validate (string, -1, NULL);
args = sc->vptr->pair_cdr (args);
if (args != sc->NIL)
@ -134,6 +137,12 @@ foreign_re_match (scheme *sc,
g_match_info_fetch_pos (match_info, i, &start, &end);
if (is_valid_utf8)
{
start = g_utf8_pointer_to_offset (string, string + start);
end = g_utf8_pointer_to_offset (string, string + end);
}
#undef cons
set_vector_elem (third_arg, i,
sc->vptr->cons(sc,