mirror of https://github.com/MidnightCommander/mc
Minor optimization of translation function arguments.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
601047b6a1
commit
5cac8caabe
|
@ -48,13 +48,14 @@
|
|||
/*** file scope functions ************************************************************************/
|
||||
|
||||
static GString *
|
||||
mc_search__glob_translate_to_regex (gchar * str, gsize * len)
|
||||
mc_search__glob_translate_to_regex (const GString * astr)
|
||||
{
|
||||
const char *str = astr->str;
|
||||
GString *buff = g_string_new ("");
|
||||
gsize orig_len = *len;
|
||||
gsize loop = 0;
|
||||
gboolean inside_group = FALSE;
|
||||
while (loop < orig_len)
|
||||
|
||||
while (loop < astr->len)
|
||||
{
|
||||
switch (str[loop])
|
||||
{
|
||||
|
@ -114,7 +115,7 @@ mc_search__glob_translate_to_regex (gchar * str, gsize * len)
|
|||
g_string_append_c (buff, str[loop]);
|
||||
loop++;
|
||||
}
|
||||
*len = buff->len;
|
||||
|
||||
return buff;
|
||||
}
|
||||
|
||||
|
@ -162,9 +163,9 @@ void
|
|||
mc_search__cond_struct_new_init_glob (const char *charset, mc_search_t * lc_mc_search,
|
||||
mc_search_cond_t * mc_search_cond)
|
||||
{
|
||||
GString *tmp =
|
||||
mc_search__glob_translate_to_regex (mc_search_cond->str->str, &mc_search_cond->str->len);
|
||||
GString *tmp;
|
||||
|
||||
tmp = mc_search__glob_translate_to_regex (mc_search_cond->str);
|
||||
g_string_free (mc_search_cond->str, TRUE);
|
||||
|
||||
if (lc_mc_search->is_entire_line)
|
||||
|
@ -175,7 +176,6 @@ mc_search__cond_struct_new_init_glob (const char *charset, mc_search_t * lc_mc_s
|
|||
mc_search_cond->str = tmp;
|
||||
|
||||
mc_search__cond_struct_new_init_regex (charset, lc_mc_search, mc_search_cond);
|
||||
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
|
|
@ -49,17 +49,18 @@
|
|||
/*** file scope functions ************************************************************************/
|
||||
|
||||
static GString *
|
||||
mc_search__hex_translate_to_regex (gchar * str, gsize * len)
|
||||
mc_search__hex_translate_to_regex (const GString * astr)
|
||||
{
|
||||
const char *str = astr->str;
|
||||
GString *buff = g_string_new ("");
|
||||
gchar *tmp_str = g_strndup (str, *len);
|
||||
gchar *tmp_str = g_strndup (str, astr->len);
|
||||
gchar *tmp_str2;
|
||||
gsize loop = 0;
|
||||
int val, ptr;
|
||||
|
||||
g_strchug (tmp_str); /* trim leadind whitespaces */
|
||||
|
||||
while (loop < *len) {
|
||||
while (loop < astr->len) {
|
||||
if (sscanf (tmp_str + loop, "%i%n", &val, &ptr)) {
|
||||
if (val < -128 || val > 255) {
|
||||
loop++;
|
||||
|
@ -75,7 +76,7 @@ mc_search__hex_translate_to_regex (gchar * str, gsize * len)
|
|||
if (*(tmp_str + loop) == '"') {
|
||||
gsize loop2 = 0;
|
||||
loop++;
|
||||
while (loop + loop2 < *len) {
|
||||
while (loop + loop2 < astr->len) {
|
||||
if (*(tmp_str + loop + loop2) == '"' &&
|
||||
!strutils_is_char_escaped (tmp_str, tmp_str + loop + loop2))
|
||||
break;
|
||||
|
@ -90,7 +91,6 @@ mc_search__hex_translate_to_regex (gchar * str, gsize * len)
|
|||
|
||||
g_free (tmp_str);
|
||||
|
||||
*len = buff->len;
|
||||
return buff;
|
||||
}
|
||||
|
||||
|
@ -100,14 +100,13 @@ void
|
|||
mc_search__cond_struct_new_init_hex (const char *charset, mc_search_t * lc_mc_search,
|
||||
mc_search_cond_t * mc_search_cond)
|
||||
{
|
||||
GString *tmp =
|
||||
mc_search__hex_translate_to_regex (mc_search_cond->str->str, &mc_search_cond->str->len);
|
||||
GString *tmp;
|
||||
|
||||
tmp = mc_search__hex_translate_to_regex (mc_search_cond->str);
|
||||
g_string_free (mc_search_cond->str, TRUE);
|
||||
mc_search_cond->str = tmp;
|
||||
|
||||
mc_search__cond_struct_new_init_regex (charset, lc_mc_search, mc_search_cond);
|
||||
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
|
|
@ -46,13 +46,13 @@
|
|||
/*** file scope functions ************************************************************************/
|
||||
|
||||
static GString *
|
||||
mc_search__normal_translate_to_regex (gchar * str, gsize * len)
|
||||
mc_search__normal_translate_to_regex (const GString * astr)
|
||||
{
|
||||
const char *str = astr->str;
|
||||
GString *buff = g_string_new ("");
|
||||
gsize orig_len = *len;
|
||||
gsize loop = 0;
|
||||
|
||||
while (loop < orig_len) {
|
||||
while (loop < astr->len) {
|
||||
switch (str[loop]) {
|
||||
case '*':
|
||||
case '?':
|
||||
|
@ -78,7 +78,7 @@ mc_search__normal_translate_to_regex (gchar * str, gsize * len)
|
|||
g_string_append_c (buff, str[loop]);
|
||||
loop++;
|
||||
}
|
||||
*len = buff->len;
|
||||
|
||||
return buff;
|
||||
}
|
||||
|
||||
|
@ -88,10 +88,11 @@ void
|
|||
mc_search__cond_struct_new_init_normal (const char *charset, mc_search_t * lc_mc_search,
|
||||
mc_search_cond_t * mc_search_cond)
|
||||
{
|
||||
GString *tmp =
|
||||
mc_search__normal_translate_to_regex (mc_search_cond->str->str, &mc_search_cond->str->len);
|
||||
GString *tmp;
|
||||
|
||||
tmp = mc_search__normal_translate_to_regex (mc_search_cond->str);
|
||||
g_string_free (mc_search_cond->str, TRUE);
|
||||
|
||||
if (lc_mc_search->whole_words)
|
||||
{
|
||||
/* NOTE: \b as word boundary doesn't allow search
|
||||
|
@ -99,10 +100,9 @@ mc_search__cond_struct_new_init_normal (const char *charset, mc_search_t * lc_mc
|
|||
g_string_prepend (tmp, "(^|[^\\p{L}\\p{N}_])(");
|
||||
g_string_append (tmp, ")([^\\p{L}\\p{N}_]|$)");
|
||||
}
|
||||
|
||||
mc_search_cond->str = tmp;
|
||||
|
||||
mc_search__cond_struct_new_init_regex (charset, lc_mc_search, mc_search_cond);
|
||||
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
|
|
@ -194,12 +194,13 @@ mc_search__cond_struct_new_regex_accum_append (const char *charset, GString * st
|
|||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static GString *
|
||||
mc_search__cond_struct_new_regex_ci_str (const char *charset, const char *str, gsize str_len)
|
||||
mc_search__cond_struct_new_regex_ci_str (const char *charset, const GString *astr)
|
||||
{
|
||||
const char *str = astr->str;
|
||||
GString *accumulator, *spec_char, *ret_str;
|
||||
gsize loop;
|
||||
GString *tmp;
|
||||
tmp = g_string_new_len (str, str_len);
|
||||
tmp = g_string_new_len (str, astr->len);
|
||||
|
||||
|
||||
ret_str = g_string_new ("");
|
||||
|
@ -207,7 +208,7 @@ mc_search__cond_struct_new_regex_ci_str (const char *charset, const char *str, g
|
|||
spec_char = g_string_new ("");
|
||||
loop = 0;
|
||||
|
||||
while (loop <= str_len)
|
||||
while (loop <= astr->len)
|
||||
{
|
||||
if (mc_search__regex_str_append_if_special (spec_char, tmp, &loop))
|
||||
{
|
||||
|
@ -221,13 +222,13 @@ mc_search__cond_struct_new_regex_ci_str (const char *charset, const char *str, g
|
|||
{
|
||||
mc_search__cond_struct_new_regex_accum_append (charset, ret_str, accumulator);
|
||||
|
||||
while (loop < str_len && !(tmp->str[loop] == ']'
|
||||
while (loop < astr->len && !(tmp->str[loop] == ']'
|
||||
&& !strutils_is_char_escaped (tmp->str, &(tmp->str[loop]))))
|
||||
{
|
||||
g_string_append_c (ret_str, tmp->str[loop]);
|
||||
loop++;
|
||||
|
||||
}
|
||||
|
||||
g_string_append_c (ret_str, tmp->str[loop]);
|
||||
loop++;
|
||||
continue;
|
||||
|
@ -522,7 +523,6 @@ void
|
|||
mc_search__cond_struct_new_init_regex (const char *charset, mc_search_t * lc_mc_search,
|
||||
mc_search_cond_t * mc_search_cond)
|
||||
{
|
||||
GString *tmp = NULL;
|
||||
#ifdef SEARCH_TYPE_GLIB
|
||||
GError *error = NULL;
|
||||
#else /* SEARCH_TYPE_GLIB */
|
||||
|
@ -532,8 +532,10 @@ mc_search__cond_struct_new_init_regex (const char *charset, mc_search_t * lc_mc_
|
|||
|
||||
if (!lc_mc_search->is_case_sensitive)
|
||||
{
|
||||
GString *tmp;
|
||||
|
||||
tmp = mc_search_cond->str;
|
||||
mc_search_cond->str = mc_search__cond_struct_new_regex_ci_str (charset, tmp->str, tmp->len);
|
||||
mc_search_cond->str = mc_search__cond_struct_new_regex_ci_str (charset, tmp);
|
||||
g_string_free (tmp, TRUE);
|
||||
}
|
||||
#ifdef SEARCH_TYPE_GLIB
|
||||
|
|
Loading…
Reference in New Issue