Fixed NULL acertion if replacement don't correct
Also fixed multiple usage of replacement pointers (such as \1\1). Signed-off-by: Slava Zanko <slavazanko@gmail.com>
Этот коммит содержится в:
родитель
2e9a16487a
Коммит
facb94dc48
@ -152,8 +152,7 @@ transform_source (FileOpContext *ctx, const char *source)
|
|||||||
{
|
{
|
||||||
char *s = g_strdup (source);
|
char *s = g_strdup (source);
|
||||||
char *q;
|
char *q;
|
||||||
char *ret;
|
GString *destination_mask, *temp_string;
|
||||||
GString *destination_mask;
|
|
||||||
const char *fnsource = x_basename (s);
|
const char *fnsource = x_basename (s);
|
||||||
char *fnsource_fixed = g_strdup (fnsource);
|
char *fnsource_fixed = g_strdup (fnsource);
|
||||||
size_t j=0, len;
|
size_t j=0, len;
|
||||||
@ -175,10 +174,12 @@ transform_source (FileOpContext *ctx, const char *source)
|
|||||||
g_free (fnsource_fixed);
|
g_free (fnsource_fixed);
|
||||||
|
|
||||||
destination_mask = g_string_new(ctx->dest_mask);
|
destination_mask = g_string_new(ctx->dest_mask);
|
||||||
ret = g_string_free(mc_search_prepare_replace_str (ctx->search_handle, destination_mask), FALSE);
|
temp_string = mc_search_prepare_replace_str (ctx->search_handle, destination_mask);
|
||||||
g_string_free(destination_mask, TRUE);
|
g_string_free(destination_mask, TRUE);
|
||||||
g_free (s);
|
g_free (s);
|
||||||
return ret;
|
if (temp_string == NULL)
|
||||||
|
return NULL;
|
||||||
|
return g_string_free(temp_string, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -197,14 +197,12 @@ mc_search__cond_struct_new_regex_ci_str (const char *charset, const char *str, g
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tmp->str[loop] == '['
|
if (tmp->str[loop] == '[' && !mc_search_is_char_escaped (tmp->str, &(tmp->str[loop]) - 1)) {
|
||||||
&& !mc_search_is_char_escaped (tmp->str, &(tmp->str[loop]) - 1)) {
|
|
||||||
mc_search__cond_struct_new_regex_accum_append (charset, ret_str, accumulator);
|
mc_search__cond_struct_new_regex_accum_append (charset, ret_str, accumulator);
|
||||||
|
|
||||||
while (loop < str_len && !(tmp->str[loop] == ']'
|
while (loop < str_len && !(tmp->str[loop] == ']'
|
||||||
&& !mc_search_is_char_escaped (tmp->str,
|
&& !mc_search_is_char_escaped (tmp->str,
|
||||||
&(tmp->str[loop]) -
|
&(tmp->str[loop]) - 1))) {
|
||||||
1))) {
|
|
||||||
g_string_append_c (ret_str, tmp->str[loop]);
|
g_string_append_c (ret_str, tmp->str[loop]);
|
||||||
loop++;
|
loop++;
|
||||||
|
|
||||||
@ -300,33 +298,38 @@ mc_search__regex_found_cond (mc_search_t * mc_search, GString * search_str)
|
|||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
mc_search_regex__get_num_replace_tokens (const gchar * str, gsize len)
|
mc_search_regex__get_max_num_of_replace_tokens (const gchar * str, gsize len)
|
||||||
{
|
{
|
||||||
int count_tokens = 0;
|
int max_token = 0;
|
||||||
gsize loop;
|
gsize loop;
|
||||||
for (loop = 0; loop < len - 1; loop++) {
|
for (loop = 0; loop < len - 1; loop++) {
|
||||||
if (str[loop] == '\\' && (str[loop + 1] & (char) 0xf0) == 0x30 /* 0-9 */ ) {
|
if (str[loop] == '\\' && (str[loop + 1] & (char) 0xf0) == 0x30 /* 0-9 */ ) {
|
||||||
if (mc_search_is_char_escaped (str, &str[loop - 1]))
|
if (mc_search_is_char_escaped (str, &str[loop - 1]))
|
||||||
continue;
|
continue;
|
||||||
if (str[loop + 1] == '0')
|
if (max_token < str[loop + 1] - '0')
|
||||||
continue;
|
max_token = str[loop + 1] - '0';
|
||||||
|
|
||||||
count_tokens++;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (str[loop] == '$' && str[loop + 1] == '{') {
|
if (str[loop] == '$' && str[loop + 1] == '{') {
|
||||||
gsize tmp_len;
|
gsize tmp_len;
|
||||||
|
char *tmp_str;
|
||||||
|
int tmp_token;
|
||||||
if (mc_search_is_char_escaped (str, &str[loop - 1]))
|
if (mc_search_is_char_escaped (str, &str[loop - 1]))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for (tmp_len = 0;
|
for (tmp_len = 0;
|
||||||
loop + tmp_len + 2 < len && (str[loop + 2 + tmp_len] & (char) 0xf0) == 0x30;
|
loop + tmp_len + 2 < len && (str[loop + 2 + tmp_len] & (char) 0xf0) == 0x30;
|
||||||
tmp_len++);
|
tmp_len++);
|
||||||
if (str[loop + 2 + tmp_len] == '}')
|
if (str[loop + 2 + tmp_len] == '}') {
|
||||||
count_tokens++;
|
tmp_str = g_strndup (loop + 2, tmp_len);
|
||||||
|
tmp_token = atoi (tmp_str);
|
||||||
|
if (max_token < tmp_token)
|
||||||
|
max_token = tmp_token;
|
||||||
|
g_free (tmp_str);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return count_tokens;
|
return max_token;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
@ -632,7 +635,7 @@ mc_search_regex_prepare_replace_str (mc_search_t * mc_search, GString * replace_
|
|||||||
replace_transform_type_t replace_flags = REPLACE_T_NO_TRANSFORM;
|
replace_transform_type_t replace_flags = REPLACE_T_NO_TRANSFORM;
|
||||||
|
|
||||||
num_replace_tokens =
|
num_replace_tokens =
|
||||||
mc_search_regex__get_num_replace_tokens (replace_str->str, replace_str->len);
|
mc_search_regex__get_max_num_of_replace_tokens (replace_str->str, replace_str->len);
|
||||||
|
|
||||||
if (mc_search->num_rezults < 0)
|
if (mc_search->num_rezults < 0)
|
||||||
return g_string_new_len (replace_str->str, replace_str->len);
|
return g_string_new_len (replace_str->str, replace_str->len);
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user