mirror of
https://github.com/MidnightCommander/mc
synced 2025-03-01 21:51:35 +03:00
Search Replace now handled \U,\u,\L,\l and \E modificators.
Also function mc_search__regex_is_char_escaped() renamed to mc_search_is_char_escaped() and moved into global visibility scope.
This commit is contained in:
parent
5e6c14a928
commit
a0d56381e0
@ -50,40 +50,42 @@ mc_search__glob_translate_to_regex (gchar * str, gsize * len)
|
||||
GString *buff = g_string_new ("");
|
||||
gsize orig_len = *len;
|
||||
gsize loop = 0;
|
||||
|
||||
gboolean inside_group = FALSE;
|
||||
while (loop < orig_len) {
|
||||
switch (str[loop]) {
|
||||
case '*':
|
||||
if (!mc_search__regex_is_char_escaped (str, &(str[loop]) - 1)) {
|
||||
g_string_append (buff, ".*");
|
||||
if (!mc_search_is_char_escaped (str, &(str[loop]) - 1)) {
|
||||
g_string_append (buff, (inside_group) ? ".*" : "(.*)");
|
||||
loop++;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case '?':
|
||||
if (!mc_search__regex_is_char_escaped (str, &(str[loop]) - 1)) {
|
||||
g_string_append (buff, ".");
|
||||
if (!mc_search_is_char_escaped (str, &(str[loop]) - 1)) {
|
||||
g_string_append (buff, (inside_group) ? "." : "(.)");
|
||||
loop++;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case ',':
|
||||
if (!mc_search__regex_is_char_escaped (str, &(str[loop]) - 1)) {
|
||||
if (!mc_search_is_char_escaped (str, &(str[loop]) - 1)) {
|
||||
g_string_append (buff, "|");
|
||||
loop++;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case '{':
|
||||
if (!mc_search__regex_is_char_escaped (str, &(str[loop]) - 1)) {
|
||||
if (!mc_search_is_char_escaped (str, &(str[loop]) - 1)) {
|
||||
g_string_append (buff, "(");
|
||||
inside_group = TRUE;
|
||||
loop++;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case '}':
|
||||
if (!mc_search__regex_is_char_escaped (str, &(str[loop]) - 1)) {
|
||||
if (!mc_search_is_char_escaped (str, &(str[loop]) - 1)) {
|
||||
g_string_append (buff, ")");
|
||||
inside_group = FALSE;
|
||||
loop++;
|
||||
continue;
|
||||
}
|
||||
|
@ -70,17 +70,17 @@ mc_search__hex_translate_to_regex (gchar * str, gsize * len)
|
||||
}
|
||||
|
||||
if (*(tmp_str + loop) == '"') {
|
||||
loop++;
|
||||
gsize loop2=0;
|
||||
while (loop + loop2 < *len){
|
||||
if (*(tmp_str + loop + loop2) == '"' &&
|
||||
!mc_search__regex_is_char_escaped(tmp_str, tmp_str + loop + loop2 - 1))
|
||||
break;
|
||||
loop2++;
|
||||
}
|
||||
g_string_append_len(buff, tmp_str + loop, loop2 - 1);
|
||||
loop+=loop2;
|
||||
continue;
|
||||
loop++;
|
||||
gsize loop2 = 0;
|
||||
while (loop + loop2 < *len) {
|
||||
if (*(tmp_str + loop + loop2) == '"' &&
|
||||
!mc_search_is_char_escaped (tmp_str, tmp_str + loop + loop2 - 1))
|
||||
break;
|
||||
loop2++;
|
||||
}
|
||||
g_string_append_len (buff, tmp_str + loop, loop2 - 1);
|
||||
loop += loop2;
|
||||
continue;
|
||||
}
|
||||
loop++;
|
||||
}
|
||||
@ -118,7 +118,8 @@ mc_search__run_hex (mc_search_t * mc_search, const void *user_data,
|
||||
GString *
|
||||
mc_search_hex_prepare_replace_str (mc_search_t * mc_search, GString * replace_str)
|
||||
{
|
||||
return mc_search_regex_prepare_replace_str (mc_search, replace_str);
|
||||
(void) mc_search;
|
||||
return g_string_new_len (replace_str->str, replace_str->len);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -56,8 +56,6 @@ GString *mc_search__tolower_case_str (const char *, const char *, gsize);
|
||||
|
||||
GString *mc_search__toupper_case_str (const char *, const char *, gsize);
|
||||
|
||||
gboolean mc_search__regex_is_char_escaped (const char *, const char *);
|
||||
|
||||
/* search/regex.c : */
|
||||
|
||||
void mc_search__cond_struct_new_init_regex (const char *, mc_search_t *, mc_search_cond_t *);
|
||||
@ -72,6 +70,8 @@ void mc_search__cond_struct_new_init_normal (const char *, mc_search_t *, mc_sea
|
||||
|
||||
gboolean mc_search__run_normal (mc_search_t *, const void *, gsize, gsize, gsize *);
|
||||
|
||||
GString *mc_search_normal_prepare_replace_str (mc_search_t *, GString *);
|
||||
|
||||
/* search/glob.c : */
|
||||
|
||||
void mc_search__cond_struct_new_init_glob (const char *, mc_search_t *, mc_search_cond_t *);
|
||||
|
@ -88,9 +88,12 @@ mc_search__get_one_symbol (const char *charset, const char *str, gsize str_len,
|
||||
gsize converted_str_len;
|
||||
gchar *converted_str2;
|
||||
|
||||
if (charset == NULL)
|
||||
charset = cp_source;
|
||||
|
||||
converted_str = mc_search__recode_str (str, str_len, charset, cp_display, &converted_str_len);
|
||||
#else
|
||||
converted_str = g_strndup(str, str_len);
|
||||
converted_str = g_strndup (str, str_len);
|
||||
#endif
|
||||
|
||||
next_char = (char *) str_cget_next_char (converted_str);
|
||||
@ -103,13 +106,12 @@ mc_search__get_one_symbol (const char *charset, const char *str, gsize str_len,
|
||||
converted_str2 =
|
||||
mc_search__recode_str (converted_str, tmp_len, cp_display, charset, &converted_str_len);
|
||||
#endif
|
||||
|
||||
if (str_isalnum (converted_str) && !str_isdigit (converted_str))
|
||||
*just_letters = TRUE;
|
||||
else
|
||||
*just_letters = FALSE;
|
||||
|
||||
|
||||
if (just_letters) {
|
||||
if (str_isalnum (converted_str) && !str_isdigit (converted_str))
|
||||
*just_letters = TRUE;
|
||||
else
|
||||
*just_letters = FALSE;
|
||||
}
|
||||
#ifdef HAVE_CHARSET
|
||||
g_free (converted_str);
|
||||
return converted_str2;
|
||||
@ -142,6 +144,9 @@ mc_search__tolower_case_str (const char *charset, const char *str, gsize str_len
|
||||
gsize converted_str_len;
|
||||
gsize tmp_len;
|
||||
|
||||
if (charset == NULL)
|
||||
charset = cp_source;
|
||||
|
||||
tmp_str2 = converted_str =
|
||||
mc_search__recode_str (str, str_len, charset, cp_display, &converted_str_len);
|
||||
if (converted_str == NULL)
|
||||
@ -162,20 +167,20 @@ mc_search__tolower_case_str (const char *charset, const char *str, gsize str_len
|
||||
return NULL;
|
||||
|
||||
ret = g_string_new_len (tmp_str2, tmp_len);
|
||||
g_free(tmp_str2);
|
||||
g_free (tmp_str2);
|
||||
return ret;
|
||||
#else
|
||||
const gchar *tmp_str1 = str;
|
||||
gchar *converted_str, *tmp_str2;
|
||||
gsize converted_str_len = str_len+1;
|
||||
gsize converted_str_len = str_len + 1;
|
||||
|
||||
tmp_str2 = converted_str = g_strndup(str, str_len);
|
||||
tmp_str2 = converted_str = g_strndup (str, str_len);
|
||||
|
||||
while (str_tolower (tmp_str1, &tmp_str2, &converted_str_len))
|
||||
tmp_str1 += str_length_char (tmp_str1);
|
||||
|
||||
ret = g_string_new_len (converted_str, str_len);
|
||||
g_free(converted_str);
|
||||
g_free (converted_str);
|
||||
return ret;
|
||||
#endif
|
||||
}
|
||||
@ -191,6 +196,9 @@ mc_search__toupper_case_str (const char *charset, const char *str, gsize str_len
|
||||
gsize converted_str_len;
|
||||
gsize tmp_len;
|
||||
|
||||
if (charset == NULL)
|
||||
charset = cp_source;
|
||||
|
||||
tmp_str2 = converted_str =
|
||||
mc_search__recode_str (str, str_len, charset, cp_display, &converted_str_len);
|
||||
if (converted_str == NULL)
|
||||
@ -212,20 +220,20 @@ mc_search__toupper_case_str (const char *charset, const char *str, gsize str_len
|
||||
return NULL;
|
||||
|
||||
ret = g_string_new_len (tmp_str2, tmp_len);
|
||||
g_free(tmp_str2);
|
||||
g_free (tmp_str2);
|
||||
return ret;
|
||||
#else
|
||||
const gchar *tmp_str1 = str;
|
||||
gchar *converted_str, *tmp_str2;
|
||||
gsize converted_str_len = str_len+1;
|
||||
gsize converted_str_len = str_len + 1;
|
||||
|
||||
tmp_str2 = converted_str = g_strndup(str, str_len);
|
||||
tmp_str2 = converted_str = g_strndup (str, str_len);
|
||||
|
||||
while (str_toupper (tmp_str1, &tmp_str2, &converted_str_len))
|
||||
tmp_str1 += str_length_char (tmp_str1);
|
||||
|
||||
ret = g_string_new_len (converted_str, str_len);
|
||||
g_free(converted_str);
|
||||
g_free (converted_str);
|
||||
return ret;
|
||||
#endif
|
||||
}
|
||||
@ -233,10 +241,10 @@ mc_search__toupper_case_str (const char *charset, const char *str, gsize str_len
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
gboolean
|
||||
mc_search__regex_is_char_escaped (const char *start, const char *current)
|
||||
mc_search_is_char_escaped (const char *start, const char *current)
|
||||
{
|
||||
int num_esc = 0;
|
||||
while (*current == '\\' && current >= start) {
|
||||
while (current >= start && *current == '\\' ) {
|
||||
num_esc++;
|
||||
current--;
|
||||
}
|
||||
|
@ -85,9 +85,10 @@ mc_search__normal_translate_to_regex (gchar * str, gsize * len)
|
||||
|
||||
void
|
||||
mc_search__cond_struct_new_init_normal (const char *charset, mc_search_t * mc_search,
|
||||
mc_search_cond_t * mc_search_cond)
|
||||
mc_search_cond_t * mc_search_cond)
|
||||
{
|
||||
GString *tmp = mc_search__normal_translate_to_regex (mc_search_cond->str->str, &mc_search_cond->len);
|
||||
GString *tmp =
|
||||
mc_search__normal_translate_to_regex (mc_search_cond->str->str, &mc_search_cond->len);
|
||||
|
||||
g_string_free (mc_search_cond->str, TRUE);
|
||||
mc_search_cond->str = tmp;
|
||||
@ -100,7 +101,7 @@ mc_search__cond_struct_new_init_normal (const char *charset, mc_search_t * mc_se
|
||||
|
||||
gboolean
|
||||
mc_search__run_normal (mc_search_t * mc_search, const void *user_data,
|
||||
gsize start_search, gsize end_search, gsize * found_len)
|
||||
gsize start_search, gsize end_search, gsize * found_len)
|
||||
{
|
||||
return mc_search__run_regex (mc_search, user_data, start_search, end_search, found_len);
|
||||
}
|
||||
@ -109,5 +110,6 @@ mc_search__run_normal (mc_search_t * mc_search, const void *user_data,
|
||||
GString *
|
||||
mc_search_normal_prepare_replace_str (mc_search_t * mc_search, GString * replace_str)
|
||||
{
|
||||
return mc_search_regex_prepare_replace_str (mc_search, replace_str);
|
||||
(void) mc_search;
|
||||
return g_string_new_len (replace_str->str, replace_str->len);
|
||||
}
|
||||
|
@ -40,6 +40,14 @@
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
typedef enum {
|
||||
REPLACE_T_NO_TRANSFORM = 0,
|
||||
REPLACE_T_UPP_TRANSFORM_CHAR = 1,
|
||||
REPLACE_T_LOW_TRANSFORM_CHAR = 2,
|
||||
REPLACE_T_UPP_TRANSFORM = 4,
|
||||
REPLACE_T_LOW_TRANSFORM = 8
|
||||
} replace_transform_type_t;
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
/*** file scope functions ************************************************************************/
|
||||
@ -72,7 +80,7 @@ mc_search__regex_str_append_if_special (GString * copy_to, GString * regex_str,
|
||||
while (*spec_chr) {
|
||||
spec_chr_len = strlen (*spec_chr);
|
||||
if (!strncmp (tmp_regex_str, *spec_chr, spec_chr_len)) {
|
||||
if (!mc_search__regex_is_char_escaped (regex_str->str, tmp_regex_str - 1)) {
|
||||
if (!mc_search_is_char_escaped (regex_str->str, tmp_regex_str - 1)) {
|
||||
if (!strncmp ("\\x", *spec_chr, spec_chr_len)) {
|
||||
if (*(tmp_regex_str + spec_chr_len) == '{') {
|
||||
while ((spec_chr_len < regex_str->len - *offset)
|
||||
@ -190,11 +198,11 @@ mc_search__cond_struct_new_regex_ci_str (const char *charset, const char *str, g
|
||||
}
|
||||
|
||||
if (tmp->str[loop] == '['
|
||||
&& !mc_search__regex_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);
|
||||
|
||||
while (loop < str_len && !(tmp->str[loop] == ']'
|
||||
&& !mc_search__regex_is_char_escaped (tmp->str,
|
||||
&& !mc_search_is_char_escaped (tmp->str,
|
||||
&(tmp->str[loop]) -
|
||||
1))) {
|
||||
g_string_append_c (ret_str, tmp->str[loop]);
|
||||
@ -298,7 +306,9 @@ mc_search_regex__get_num_replace_tokens (const gchar * str, gsize len)
|
||||
gsize loop;
|
||||
for (loop = 0; loop < len - 1; loop++) {
|
||||
if (str[loop] == '\\' && (str[loop + 1] & (char) 0xf0) == 0x30 /* 0-9 */ ) {
|
||||
if (mc_search__regex_is_char_escaped (str, &str[loop - 1]))
|
||||
if (mc_search_is_char_escaped (str, &str[loop - 1]))
|
||||
continue;
|
||||
if (str[loop + 1] == '0')
|
||||
continue;
|
||||
|
||||
count_tokens++;
|
||||
@ -306,7 +316,7 @@ mc_search_regex__get_num_replace_tokens (const gchar * str, gsize len)
|
||||
}
|
||||
if (str[loop] == '$' && str[loop + 1] == '{') {
|
||||
gsize tmp_len;
|
||||
if (mc_search__regex_is_char_escaped (str, &str[loop - 1]))
|
||||
if (mc_search_is_char_escaped (str, &str[loop - 1]))
|
||||
continue;
|
||||
|
||||
for (tmp_len = 0;
|
||||
@ -321,12 +331,10 @@ mc_search_regex__get_num_replace_tokens (const gchar * str, gsize len)
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
mc_search_regex__append_found_token_by_num (const mc_search_t * mc_search, const gchar * fnd_str,
|
||||
GString * str, gsize index)
|
||||
static char *
|
||||
mc_search_regex__get_token_by_num (const mc_search_t * mc_search, gsize index)
|
||||
{
|
||||
int fnd_start, fnd_end, fnd_len;
|
||||
gchar *start_str;
|
||||
int fnd_start, fnd_end;
|
||||
|
||||
#if GLIB_CHECK_VERSION (2, 14, 0)
|
||||
g_match_info_fetch_pos (mc_search->regex_match_info, index, &fnd_start, &fnd_end);
|
||||
@ -340,16 +348,134 @@ mc_search_regex__append_found_token_by_num (const mc_search_t * mc_search, const
|
||||
#endif /* HAVE_LIBPCRE */
|
||||
#endif /* GLIB_CHECK_VERSION (2, 14, 0) */
|
||||
|
||||
fnd_len = fnd_end - fnd_start;
|
||||
start_str = fnd_str + fnd_start;
|
||||
if (fnd_end - fnd_start == 0)
|
||||
return NULL;
|
||||
|
||||
if (fnd_len == 0)
|
||||
return;
|
||||
|
||||
g_string_append_len (str, start_str, fnd_len);
|
||||
return g_strndup (mc_search->regex_buffer->str + fnd_start, fnd_end - fnd_start);
|
||||
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
static int
|
||||
mc_search_regex__process_replace_str (const GString * replace_str, const gsize current_pos,
|
||||
gsize * skip_len, replace_transform_type_t * replace_flags)
|
||||
{
|
||||
int ret = -1;
|
||||
char *tmp_str;
|
||||
const char *curr_str = &(replace_str->str[current_pos]);
|
||||
|
||||
if (current_pos > replace_str->len)
|
||||
return -1;
|
||||
|
||||
*skip_len = 0;
|
||||
|
||||
if (*curr_str == '$' && *(curr_str + 1) == '{' && (*(curr_str + 2) & (char) 0xf0) == 0x30) {
|
||||
if (mc_search_is_char_escaped (replace_str->str, curr_str - 1))
|
||||
return -1;
|
||||
|
||||
for (*skip_len = 0;
|
||||
current_pos + *skip_len + 2 < replace_str->len
|
||||
&& (*(curr_str + 2 + *skip_len) & (char) 0xf0) == 0x30; *skip_len++);
|
||||
|
||||
if (*(curr_str + 2 + *skip_len) != '}')
|
||||
return -1;
|
||||
|
||||
tmp_str = g_strndup (curr_str + 2, *skip_len);
|
||||
if (tmp_str == NULL)
|
||||
return -1;
|
||||
|
||||
ret = atoi (tmp_str);
|
||||
g_free (tmp_str);
|
||||
|
||||
*skip_len += 3; /* ${} */
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (*curr_str == '\\') {
|
||||
if (mc_search_is_char_escaped (replace_str->str, curr_str - 1))
|
||||
return -1;
|
||||
|
||||
if ((*(curr_str + 1) & (char) 0xf0) == 0x30) {
|
||||
ret = *(curr_str + 1) - '0';
|
||||
*skip_len = 2; /* \\ and one digit */
|
||||
return ret;
|
||||
}
|
||||
ret = -2;
|
||||
*skip_len += 2;
|
||||
switch (*(curr_str + 1)) {
|
||||
case 'U':
|
||||
*replace_flags |= REPLACE_T_UPP_TRANSFORM;
|
||||
*replace_flags &= ~REPLACE_T_LOW_TRANSFORM;
|
||||
break;
|
||||
case 'u':
|
||||
*replace_flags |= REPLACE_T_UPP_TRANSFORM_CHAR;
|
||||
break;
|
||||
case 'L':
|
||||
*replace_flags |= REPLACE_T_LOW_TRANSFORM;
|
||||
*replace_flags &= ~REPLACE_T_UPP_TRANSFORM;
|
||||
break;
|
||||
case 'l':
|
||||
*replace_flags |= REPLACE_T_LOW_TRANSFORM_CHAR;
|
||||
break;
|
||||
case 'E':
|
||||
*replace_flags = REPLACE_T_NO_TRANSFORM;
|
||||
break;
|
||||
default:
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
static void
|
||||
mc_search_regex__process_append_str (GString * dest_str, const char *from, gsize len,
|
||||
replace_transform_type_t * replace_flags)
|
||||
{
|
||||
gsize loop = 0;
|
||||
gsize char_len;
|
||||
char *tmp_str;
|
||||
GString *tmp_string;
|
||||
|
||||
if (len == -1)
|
||||
len = strlen (from);
|
||||
|
||||
if (*replace_flags == REPLACE_T_NO_TRANSFORM) {
|
||||
g_string_append_len (dest_str, from, len);
|
||||
return;
|
||||
}
|
||||
while (loop < len) {
|
||||
tmp_str = mc_search__get_one_symbol (NULL, from + loop, len - loop, NULL);
|
||||
char_len = strlen (tmp_str);
|
||||
if (*replace_flags & REPLACE_T_UPP_TRANSFORM_CHAR) {
|
||||
*replace_flags &= !REPLACE_T_UPP_TRANSFORM_CHAR;
|
||||
tmp_string = mc_search__toupper_case_str (NULL, tmp_str, char_len);
|
||||
g_string_append (dest_str, tmp_string->str);
|
||||
g_string_free (tmp_string, TRUE);
|
||||
|
||||
} else if (*replace_flags & REPLACE_T_LOW_TRANSFORM_CHAR) {
|
||||
*replace_flags &= !REPLACE_T_LOW_TRANSFORM_CHAR;
|
||||
tmp_string = mc_search__toupper_case_str (NULL, tmp_str, char_len);
|
||||
g_string_append (dest_str, tmp_string->str);
|
||||
g_string_free (tmp_string, TRUE);
|
||||
|
||||
} else if (*replace_flags & REPLACE_T_UPP_TRANSFORM) {
|
||||
tmp_string = mc_search__toupper_case_str (NULL, tmp_str, char_len);
|
||||
g_string_append (dest_str, tmp_string->str);
|
||||
g_string_free (tmp_string, TRUE);
|
||||
|
||||
} else if (*replace_flags & REPLACE_T_LOW_TRANSFORM) {
|
||||
tmp_string = mc_search__tolower_case_str (NULL, tmp_str, char_len);
|
||||
g_string_append (dest_str, tmp_string->str);
|
||||
g_string_free (tmp_string, TRUE);
|
||||
|
||||
} else {
|
||||
g_string_append (dest_str, tmp_str);
|
||||
}
|
||||
g_free (tmp_str);
|
||||
loop += char_len;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*** public functions ****************************************************************************/
|
||||
|
||||
@ -499,11 +625,11 @@ mc_search_regex_prepare_replace_str (mc_search_t * mc_search, GString * replace_
|
||||
GString *ret;
|
||||
gchar *tmp_str;
|
||||
|
||||
int num_replace_tokens;
|
||||
int num_replace_tokens, index;
|
||||
gsize loop;
|
||||
gsize index, len;
|
||||
|
||||
gsize len;
|
||||
gchar *prev_str;
|
||||
replace_transform_type_t replace_flags = REPLACE_T_NO_TRANSFORM;
|
||||
|
||||
num_replace_tokens =
|
||||
mc_search_regex__get_num_replace_tokens (replace_str->str, replace_str->len);
|
||||
@ -521,32 +647,20 @@ mc_search_regex_prepare_replace_str (mc_search_t * mc_search, GString * replace_
|
||||
ret = g_string_new ("");
|
||||
prev_str = replace_str->str;
|
||||
for (loop = 0; loop < replace_str->len - 1; loop++) {
|
||||
tmp_str = NULL;
|
||||
index = mc_search_regex__process_replace_str (replace_str, loop, &len, &replace_flags);
|
||||
|
||||
if (replace_str->str[loop] == '\\'
|
||||
&& (replace_str->str[loop + 1] & (char) 0xf0) == 0x30 /* 0-9 */ ) {
|
||||
/* \1 relace tokens */
|
||||
if (!mc_search__regex_is_char_escaped (replace_str->str, &replace_str->str[loop - 1]))
|
||||
tmp_str = g_strndup (&(replace_str->str[loop + 1]), 1);
|
||||
len = 2;
|
||||
|
||||
} else if (replace_str->str[loop] == '$' && replace_str->str[loop + 1] == '{'
|
||||
&& (replace_str->str[loop + 2] & (char) 0xf0) == 0x30) {
|
||||
/* ${1} replace token */
|
||||
for (len = 0;
|
||||
loop + len + 2 < replace_str->len
|
||||
&& (replace_str->str[loop + 2 + len] & (char) 0xf0) == 0x30; len++);
|
||||
if (replace_str->str[loop + 2 + len] == '}')
|
||||
tmp_str = g_strndup (&(replace_str->str[loop + 2]), len);
|
||||
len += 3;
|
||||
}
|
||||
|
||||
if (tmp_str == NULL)
|
||||
if (index == -1)
|
||||
continue;
|
||||
|
||||
index = (gsize) atoi (tmp_str);
|
||||
g_free (tmp_str);
|
||||
tmp_str = NULL;
|
||||
if (index == -2) {
|
||||
if (loop)
|
||||
mc_search_regex__process_append_str (ret, prev_str,
|
||||
replace_str->str - prev_str + loop,
|
||||
&replace_flags);
|
||||
prev_str = replace_str->str + loop + len;
|
||||
loop += len - 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (index > mc_search->num_rezults) {
|
||||
g_string_free (ret, TRUE);
|
||||
@ -554,15 +668,26 @@ mc_search_regex_prepare_replace_str (mc_search_t * mc_search, GString * replace_
|
||||
mc_search->error_str = g_strdup_printf (STR_E_RPL_INVALID_TOKEN, index);
|
||||
return NULL;
|
||||
}
|
||||
if (loop)
|
||||
g_string_append_len (ret, prev_str, replace_str->str - prev_str + loop);
|
||||
|
||||
mc_search_regex__append_found_token_by_num (mc_search,
|
||||
mc_search->regex_buffer->str, ret, index);
|
||||
|
||||
|
||||
tmp_str = mc_search_regex__get_token_by_num (mc_search, index);
|
||||
|
||||
if (tmp_str == NULL)
|
||||
continue;
|
||||
|
||||
if (loop)
|
||||
mc_search_regex__process_append_str (ret, prev_str, replace_str->str - prev_str + loop,
|
||||
&replace_flags);
|
||||
prev_str = replace_str->str + loop + len;
|
||||
|
||||
mc_search_regex__process_append_str (ret, tmp_str, -1, &replace_flags);
|
||||
g_free (tmp_str);
|
||||
loop += len - 1;
|
||||
}
|
||||
g_string_append_len (ret, prev_str, replace_str->str - prev_str + replace_str->len);
|
||||
mc_search_regex__process_append_str (ret, prev_str,
|
||||
replace_str->str - prev_str + replace_str->len,
|
||||
&replace_flags);
|
||||
|
||||
return ret;
|
||||
//#endif /* GLIB_CHECK_VERSION (2, 14, 0) */
|
||||
}
|
||||
|
@ -119,10 +119,10 @@ mc_search__conditions_new (mc_search_t * mc_search)
|
||||
cp_source));
|
||||
}
|
||||
#else
|
||||
g_ptr_array_add (ret,
|
||||
(gpointer) mc_search__cond_struct_new (mc_search, mc_search->original,
|
||||
mc_search->original_len,
|
||||
str_detect_termencoding()));
|
||||
g_ptr_array_add (ret,
|
||||
(gpointer) mc_search__cond_struct_new (mc_search, mc_search->original,
|
||||
mc_search->original_len,
|
||||
str_detect_termencoding ()));
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
@ -326,9 +326,15 @@ mc_search_prepare_replace_str (mc_search_t * mc_search, GString * replace_str)
|
||||
case MC_SEARCH_T_REGEX:
|
||||
ret = mc_search_regex_prepare_replace_str (mc_search, replace_str);
|
||||
break;
|
||||
case MC_SEARCH_T_NORMAL:
|
||||
case MC_SEARCH_T_HEX:
|
||||
case MC_SEARCH_T_GLOB:
|
||||
ret = mc_search_glob_prepare_replace_str (mc_search, replace_str);
|
||||
break;
|
||||
case MC_SEARCH_T_NORMAL:
|
||||
ret = mc_search_normal_prepare_replace_str (mc_search, replace_str);
|
||||
break;
|
||||
case MC_SEARCH_T_HEX:
|
||||
ret = mc_search_hex_prepare_replace_str (mc_search, replace_str);
|
||||
break;
|
||||
default:
|
||||
ret = g_string_new_len (replace_str->str, replace_str->len);
|
||||
break;
|
||||
@ -357,28 +363,28 @@ mc_search_is_fixed_search_str (mc_search_t * mc_search)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
gboolean
|
||||
mc_search (const gchar *pattern, const gchar *str, mc_search_type_t type)
|
||||
mc_search (const gchar * pattern, const gchar * str, mc_search_type_t type)
|
||||
{
|
||||
gboolean ret;
|
||||
mc_search_t *search = mc_search_new(pattern, -1);
|
||||
mc_search_t *search = mc_search_new (pattern, -1);
|
||||
if (search == NULL)
|
||||
return FALSE;
|
||||
search->search_type = type;
|
||||
search->is_case_sentitive = TRUE;
|
||||
ret = mc_search_run(search,str,0,strlen(str),NULL);
|
||||
mc_search_free(search);
|
||||
ret = mc_search_run (search, str, 0, strlen (str), NULL);
|
||||
mc_search_free (search);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
mc_search_getstart_rezult_by_num(mc_search_t *mc_search, int index)
|
||||
mc_search_getstart_rezult_by_num (mc_search_t * mc_search, int index)
|
||||
{
|
||||
if (!mc_search)
|
||||
return 0;
|
||||
return 0;
|
||||
if (mc_search->search_type == MC_SEARCH_T_NORMAL)
|
||||
return 0;
|
||||
return 0;
|
||||
#if GLIB_CHECK_VERSION (2, 14, 0)
|
||||
gint start_pos;
|
||||
gint end_pos;
|
||||
@ -386,7 +392,7 @@ mc_search_getstart_rezult_by_num(mc_search_t *mc_search, int index)
|
||||
return (int) start_pos;
|
||||
#else /* GLIB_CHECK_VERSION (2, 14, 0) */
|
||||
#if HAVE_LIBPCRE
|
||||
return mc_search->iovector[index*2];
|
||||
return mc_search->iovector[index * 2];
|
||||
#else /* HAVE_LIBPCRE */
|
||||
return mc_search->regex_match_info[index].rm_so;
|
||||
#endif /* HAVE_LIBPCRE */
|
||||
@ -397,12 +403,12 @@ mc_search_getstart_rezult_by_num(mc_search_t *mc_search, int index)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
mc_search_getend_rezult_by_num(mc_search_t *mc_search, int index)
|
||||
mc_search_getend_rezult_by_num (mc_search_t * mc_search, int index)
|
||||
{
|
||||
if (!mc_search)
|
||||
return 0;
|
||||
return 0;
|
||||
if (mc_search->search_type == MC_SEARCH_T_NORMAL)
|
||||
return 0;
|
||||
return 0;
|
||||
#if GLIB_CHECK_VERSION (2, 14, 0)
|
||||
gint start_pos;
|
||||
gint end_pos;
|
||||
@ -410,7 +416,7 @@ mc_search_getend_rezult_by_num(mc_search_t *mc_search, int index)
|
||||
return (int) end_pos;
|
||||
#else /* GLIB_CHECK_VERSION (2, 14, 0) */
|
||||
#if HAVE_LIBPCRE
|
||||
return mc_search->iovector[index*2+1];
|
||||
return mc_search->iovector[index * 2 + 1];
|
||||
#else /* HAVE_LIBPCRE */
|
||||
return mc_search->regex_match_info[index].rm_eo;
|
||||
#endif /* HAVE_LIBPCRE */
|
||||
|
@ -137,4 +137,6 @@ gboolean mc_search (const gchar *, const gchar *, mc_search_type_t);
|
||||
int mc_search_getstart_rezult_by_num (mc_search_t *, int);
|
||||
int mc_search_getend_rezult_by_num (mc_search_t *, int);
|
||||
|
||||
gboolean mc_search_is_char_escaped (const char *, const char *);
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user