Renamed function shell_is_char_escaped to strutils_is_char_escaped; removed function mc_search_is_char_escaped

* All calls of function mc_search_is_char_escaped replaced to strutils_is_char_escaped

Signed-off-by: Slava Zanko <slavazanko@gmail.com>
This commit is contained in:
Slava Zanko 2009-06-09 12:01:00 +03:00
parent 5f810602e0
commit 786174fac8
6 changed files with 31 additions and 35 deletions

View File

@ -32,6 +32,7 @@
#include "../src/search/search.h"
#include "../src/search/internal.h"
#include "../src/strutil.h"
#include "../src/strescape.h"
#include "../src/charsets.h"
/*** global variables ****************************************************************************/
@ -54,28 +55,28 @@ mc_search__glob_translate_to_regex (gchar * str, gsize * len)
while (loop < orig_len) {
switch (str[loop]) {
case '*':
if (!mc_search_is_char_escaped (str, &(str[loop]) - 1)) {
if (!strutils_is_char_escaped (str, &(str[loop]) )) {
g_string_append (buff, (inside_group) ? ".*" : "(.*)");
loop++;
continue;
}
break;
case '?':
if (!mc_search_is_char_escaped (str, &(str[loop]) - 1)) {
if (!strutils_is_char_escaped (str, &(str[loop]) )) {
g_string_append (buff, (inside_group) ? "." : "(.)");
loop++;
continue;
}
break;
case ',':
if (!mc_search_is_char_escaped (str, &(str[loop]) - 1)) {
if (!strutils_is_char_escaped (str, &(str[loop]) )) {
g_string_append (buff, "|");
loop++;
continue;
}
break;
case '{':
if (!mc_search_is_char_escaped (str, &(str[loop]) - 1)) {
if (!strutils_is_char_escaped (str, &(str[loop]) )) {
g_string_append (buff, "(");
inside_group = TRUE;
loop++;
@ -83,7 +84,7 @@ mc_search__glob_translate_to_regex (gchar * str, gsize * len)
}
break;
case '}':
if (!mc_search_is_char_escaped (str, &(str[loop]) - 1)) {
if (!strutils_is_char_escaped (str, &(str[loop]) )) {
g_string_append (buff, ")");
inside_group = FALSE;
loop++;

View File

@ -33,6 +33,7 @@
#include "../src/search/search.h"
#include "../src/search/internal.h"
#include "../src/strutil.h"
#include "../src/strescape.h"
#include "../src/charsets.h"
/*** global variables ****************************************************************************/
@ -74,7 +75,7 @@ mc_search__hex_translate_to_regex (gchar * str, gsize * len)
gsize loop2 = 0;
while (loop + loop2 < *len) {
if (*(tmp_str + loop + loop2) == '"' &&
!mc_search_is_char_escaped (tmp_str, tmp_str + loop + loop2 - 1))
!strutils_is_char_escaped (tmp_str, tmp_str + loop + loop2 ))
break;
loop2++;
}

View File

@ -240,19 +240,6 @@ mc_search__toupper_case_str (const char *charset, const char *str, gsize str_len
/* --------------------------------------------------------------------------------------------- */
gboolean
mc_search_is_char_escaped (const char *start, const char *current)
{
int num_esc = 0;
while (current >= start && *current == '\\' ) {
num_esc++;
current--;
}
return (gboolean) num_esc % 2;
}
/* --------------------------------------------------------------------------------------------- */
gchar **
mc_search_get_types_strings_array (void)
{
@ -273,3 +260,5 @@ mc_search_get_types_strings_array (void)
g_string_free (tmp, TRUE);
return ret;
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -32,6 +32,7 @@
#include "../src/search/search.h"
#include "../src/search/internal.h"
#include "../src/strutil.h"
#include "../src/strescape.h"
#include "../src/charsets.h"
/*** global variables ****************************************************************************/
@ -80,7 +81,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_is_char_escaped (regex_str->str, tmp_regex_str - 1)) {
if (!strutils_is_char_escaped (regex_str->str, tmp_regex_str)) {
if (!strncmp ("\\x", *spec_chr, spec_chr_len)) {
if (*(tmp_regex_str + spec_chr_len) == '{') {
while ((spec_chr_len < regex_str->len - *offset)
@ -197,12 +198,12 @@ mc_search__cond_struct_new_regex_ci_str (const char *charset, const char *str, g
continue;
}
if (tmp->str[loop] == '[' && !mc_search_is_char_escaped (tmp->str, &(tmp->str[loop]) - 1)) {
if (tmp->str[loop] == '[' && !strutils_is_char_escaped (tmp->str, &(tmp->str[loop]))) {
mc_search__cond_struct_new_regex_accum_append (charset, ret_str, accumulator);
while (loop < str_len && !(tmp->str[loop] == ']'
&& !mc_search_is_char_escaped (tmp->str,
&(tmp->str[loop]) - 1))) {
&& !strutils_is_char_escaped (tmp->str,
&(tmp->str[loop])))) {
g_string_append_c (ret_str, tmp->str[loop]);
loop++;
@ -304,7 +305,7 @@ mc_search_regex__get_max_num_of_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_is_char_escaped (str, &str[loop - 1]))
if (strutils_is_char_escaped (str, &str[loop]))
continue;
if (max_token < str[loop + 1] - '0')
max_token = str[loop + 1] - '0';
@ -314,7 +315,7 @@ mc_search_regex__get_max_num_of_replace_tokens (const gchar * str, gsize len)
gsize tmp_len;
char *tmp_str;
int tmp_token;
if (mc_search_is_char_escaped (str, &str[loop - 1]))
if (strutils_is_char_escaped (str, &str[loop]))
continue;
for (tmp_len = 0;
@ -373,7 +374,7 @@ mc_search_regex__process_replace_str (const GString * replace_str, const gsize c
*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))
if (strutils_is_char_escaped (replace_str->str, curr_str ))
return -1;
for (*skip_len = 0;
@ -395,7 +396,7 @@ mc_search_regex__process_replace_str (const GString * replace_str, const gsize c
}
if (*curr_str == '\\') {
if (mc_search_is_char_escaped (replace_str->str, curr_str - 1))
if (strutils_is_char_escaped (replace_str->str, curr_str ))
return -1;
if ((*(curr_str + 1) & (char) 0xf0) == 0x30) {

View File

@ -137,6 +137,4 @@ 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

View File

@ -194,13 +194,19 @@ out:
otherwise return FALSE
*/
gboolean
shell_is_char_escaped ( const char *in )
strutils_is_char_escaped ( const char *start, const char *current )
{
if (in == NULL || !*in || in[0] != '\\')
return FALSE;
if (shell_escape_toesc(in[1]))
return TRUE;
int num_esc = 0;
if (start == NULL || current == NULL || current <= start)
return FALSE;
current--;
while (current >= start && *current == '\\' ) {
num_esc++;
current--;
}
return (gboolean) num_esc % 2;
}