identation of code

Signed-off-by: Slava Zanko <slavazanko@gmail.com>
This commit is contained in:
Slava Zanko 2010-07-07 14:04:38 +03:00
parent 973bbb70a2
commit 3aa6758f4f
2 changed files with 68 additions and 49 deletions

View File

@ -54,31 +54,37 @@ mc_search__glob_translate_to_regex (gchar * str, gsize * len)
gsize orig_len = *len;
gsize loop = 0;
gboolean inside_group = FALSE;
while (loop < orig_len) {
switch (str[loop]) {
while (loop < orig_len)
{
switch (str[loop])
{
case '*':
if (!strutils_is_char_escaped (str, &(str[loop]))) {
if (!strutils_is_char_escaped (str, &(str[loop])))
{
g_string_append (buff, (inside_group) ? ".*" : "(.*)");
loop++;
continue;
}
break;
case '?':
if (!strutils_is_char_escaped (str, &(str[loop]))) {
if (!strutils_is_char_escaped (str, &(str[loop])))
{
g_string_append (buff, (inside_group) ? "." : "(.)");
loop++;
continue;
}
break;
case ',':
if (!strutils_is_char_escaped (str, &(str[loop]))) {
if (!strutils_is_char_escaped (str, &(str[loop])))
{
g_string_append (buff, "|");
loop++;
continue;
}
break;
case '{':
if (!strutils_is_char_escaped (str, &(str[loop]))) {
if (!strutils_is_char_escaped (str, &(str[loop])))
{
g_string_append (buff, "(");
inside_group = TRUE;
loop++;
@ -86,7 +92,8 @@ mc_search__glob_translate_to_regex (gchar * str, gsize * len)
}
break;
case '}':
if (!strutils_is_char_escaped (str, &(str[loop]))) {
if (!strutils_is_char_escaped (str, &(str[loop])))
{
g_string_append (buff, ")");
inside_group = FALSE;
loop++;
@ -114,38 +121,40 @@ mc_search__glob_translate_to_regex (gchar * str, gsize * len)
/* --------------------------------------------------------------------------------------------- */
static GString *
mc_search__translate_replace_glob_to_regex (gchar *str)
mc_search__translate_replace_glob_to_regex (gchar * str)
{
GString *buff = g_string_new ("");
int cnt = '0';
gboolean escaped_mode = FALSE;
while (*str) {
char c = *str++;
switch (c) {
case '\\':
if (!escaped_mode)
{
escaped_mode = TRUE;
continue;
}
break;
case '*':
case '?':
if (!escaped_mode)
{
g_string_append_c (buff, '\\');
c = ++cnt;
continue;
}
break;
/* breaks copying: mc uses "\0" internally, it must not be changed */
/*case '\\':*/
case '&':
g_string_append_c (buff, '\\');
break;
}
g_string_append_c (buff, c);
escaped_mode = FALSE;
while (*str)
{
char c = *str++;
switch (c)
{
case '\\':
if (!escaped_mode)
{
escaped_mode = TRUE;
continue;
}
break;
case '*':
case '?':
if (!escaped_mode)
{
g_string_append_c (buff, '\\');
c = ++cnt;
continue;
}
break;
/* breaks copying: mc uses "\0" internally, it must not be changed */
/*case '\\': */
case '&':
g_string_append_c (buff, '\\');
break;
}
g_string_append_c (buff, c);
escaped_mode = FALSE;
}
return buff;
}
@ -161,7 +170,8 @@ mc_search__cond_struct_new_init_glob (const char *charset, mc_search_t * lc_mc_s
g_string_free (mc_search_cond->str, TRUE);
if (lc_mc_search->is_entire_line) {
if (lc_mc_search->is_entire_line)
{
g_string_prepend_c (tmp, '^');
g_string_append_c (tmp, '$');
}
@ -186,7 +196,7 @@ mc_search__run_glob (mc_search_t * lc_mc_search, const void *user_data,
GString *
mc_search_glob_prepare_replace_str (mc_search_t * lc_mc_search, GString * replace_str)
{
GString *repl = mc_search__translate_replace_glob_to_regex(replace_str->str);
GString *repl = mc_search__translate_replace_glob_to_regex (replace_str->str);
GString *res = mc_search_regex_prepare_replace_str (lc_mc_search, repl);
g_string_free (repl, TRUE);
return res;

View File

@ -39,7 +39,7 @@
static const char ESCAPE_SHELL_CHARS[] = " !#$%()&{}[]`?|<>;*\\\"'";
static const char ESCAPE_REGEX_CHARS[] = "^!#$%()&{}[]`?|<>;*.\\";
static const char ESCAPE_GLOB_CHARS[] = "$*\\?";
static const char ESCAPE_GLOB_CHARS[] = "$*\\?";
/*** file scope functions ************************************************************************/
@ -60,12 +60,15 @@ strutils_escape (const char *src, gsize src_len, const char *escaped_chars,
ret = g_string_new ("");
if (src_len == (gsize)-1)
if (src_len == (gsize) - 1)
src_len = strlen (src);
for (curr_index = 0; curr_index < src_len; curr_index++) {
if (escape_non_printable) {
switch (src[curr_index]) {
for (curr_index = 0; curr_index < src_len; curr_index++)
{
if (escape_non_printable)
{
switch (src[curr_index])
{
case '\n':
g_string_append (ret, "\\n");
continue;
@ -92,7 +95,7 @@ strutils_escape (const char *src, gsize src_len, const char *escaped_chars,
/* --------------------------------------------------------------------------------------------- */
char *
strutils_unescape (const char *src, gsize src_len, const char *unescaped_chars,
gboolean unescape_non_printable)
gboolean unescape_non_printable)
{
GString *ret;
gsize curr_index;
@ -105,17 +108,21 @@ strutils_unescape (const char *src, gsize src_len, const char *unescaped_chars,
ret = g_string_new ("");
if (src_len == (gsize)-1)
if (src_len == (gsize) - 1)
src_len = strlen (src);
for (curr_index = 0; curr_index < src_len-1; curr_index++) {
if (src[curr_index] != '\\'){
for (curr_index = 0; curr_index < src_len - 1; curr_index++)
{
if (src[curr_index] != '\\')
{
g_string_append_c (ret, src[curr_index]);
continue;
}
curr_index++;
if (unescape_non_printable) {
switch (src[curr_index]) {
if (unescape_non_printable)
{
switch (src[curr_index])
{
case 'n':
g_string_append_c (ret, '\n');
continue;
@ -139,6 +146,7 @@ strutils_unescape (const char *src, gsize src_len, const char *unescaped_chars,
return g_string_free (ret, FALSE);
}
/* --------------------------------------------------------------------------------------------- */
/** To be compatible with the general posix command lines we have to escape
@ -228,7 +236,8 @@ strutils_is_char_escaped (const char *start, const char *current)
return FALSE;
current--;
while (current >= start && *current == '\\') {
while (current >= start && *current == '\\')
{
num_esc++;
current--;
}