Пример #1
0
static void
mc_search_regex__process_append_str (GString * dest_str, const char *from, gsize len,
                                     replace_transform_type_t * replace_flags)
{
    gsize loop;
    gsize char_len;

    if (len == (gsize) (-1))
        len = strlen (from);

    if (*replace_flags == REPLACE_T_NO_TRANSFORM)
    {
        g_string_append_len (dest_str, from, len);
        return;
    }

    for (loop = 0; loop < len; loop += char_len)
    {
        GString *tmp_string = NULL;
        char *tmp_str;

        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) != 0)
        {
            *replace_flags &= ~REPLACE_T_UPP_TRANSFORM_CHAR;
            tmp_string = mc_search__toupper_case_str (NULL, tmp_str, char_len);
            g_string_append_len (dest_str, tmp_string->str, tmp_string->len);
            g_string_free (tmp_string, TRUE);
        }
        else if ((*replace_flags & REPLACE_T_LOW_TRANSFORM_CHAR) != 0)
        {
            *replace_flags &= ~REPLACE_T_LOW_TRANSFORM_CHAR;
            tmp_string = mc_search__tolower_case_str (NULL, tmp_str, char_len);
            g_string_append_len (dest_str, tmp_string->str, tmp_string->len);
            g_string_free (tmp_string, TRUE);
        }
        else if ((*replace_flags & REPLACE_T_UPP_TRANSFORM) != 0)
        {
            tmp_string = mc_search__toupper_case_str (NULL, tmp_str, char_len);
            g_string_append_len (dest_str, tmp_string->str, tmp_string->len);
            g_string_free (tmp_string, TRUE);
        }
        else if ((*replace_flags & REPLACE_T_LOW_TRANSFORM) != 0)
        {
            tmp_string = mc_search__tolower_case_str (NULL, tmp_str, char_len);
            g_string_append_len (dest_str, tmp_string->str, tmp_string->len);
            g_string_free (tmp_string, TRUE);
        }

        g_free (tmp_str);
    }
}
Пример #2
0
Файл: regex.c Проект: artzub/mc
/* --------------------------------------------------------------------------------------------- */
static void
mc_search__cond_struct_new_regex_hex_add (const char *charset, GString * str_to,
                                          const char *one_char, gsize str_len)
{
    GString *upp, *low;
    gchar *tmp_str;
    gsize loop;

    upp = mc_search__toupper_case_str (charset, one_char, str_len);
    low = mc_search__tolower_case_str (charset, one_char, str_len);

    for (loop = 0; loop < upp->len; loop++)
    {

        if (loop < low->len)
        {
            if (upp->str[loop] == low->str[loop])
                tmp_str = g_strdup_printf ("\\x%02X", (unsigned char) upp->str[loop]);
            else
                tmp_str =
                    g_strdup_printf ("[\\x%02X\\x%02X]", (unsigned char) upp->str[loop],
                                     (unsigned char) low->str[loop]);
        }
        else
        {
            tmp_str = g_strdup_printf ("\\x%02X", (unsigned char) upp->str[loop]);
        }
        g_string_append (str_to, tmp_str);
        g_free (tmp_str);
    }
    g_string_free (upp, TRUE);
    g_string_free (low, TRUE);
}
Пример #3
0
static void
mc_search__cond_struct_new_regex_hex_add (const char *charset, GString * str_to,
                                          const char *one_char, gsize str_len)
{
    GString *upp, *low;
    gsize loop;

    upp = mc_search__toupper_case_str (charset, one_char, str_len);
    low = mc_search__tolower_case_str (charset, one_char, str_len);

    for (loop = 0; loop < upp->len; loop++)
    {
        gchar tmp_str[10 + 1];  /* longest content is "[\\x%02X\\x%02X]" */
        gint tmp_len;

        if (loop >= low->len || upp->str[loop] == low->str[loop])
            tmp_len =
                g_snprintf (tmp_str, sizeof (tmp_str), "\\x%02X", (unsigned char) upp->str[loop]);
        else
            tmp_len =
                g_snprintf (tmp_str, sizeof (tmp_str), "[\\x%02X\\x%02X]",
                            (unsigned char) upp->str[loop], (unsigned char) low->str[loop]);

        g_string_append_len (str_to, tmp_str, tmp_len);
    }

    g_string_free (upp, TRUE);
    g_string_free (low, TRUE);
}