mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-22 04:22:34 +03:00
Ticket #4587: mcviewer: fix BOL regex search.
Refactoring. * (mc_search_line_t): rename from edit_search_line_t and move to lib/search.h. * (mc_search_get_line_type): rename from edit_get_search_line_type() and move to lib/search/regex.c. Signed-off-by: Andrew Borodin <aborodin@vmail.ru> Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
This commit is contained in:
parent
7950ae8b24
commit
c943b931d7
14
lib/search.h
14
lib/search.h
@ -60,6 +60,18 @@ typedef enum
|
||||
MC_SEARCH_T_GLOB
|
||||
} mc_search_type_t;
|
||||
|
||||
/**
|
||||
* enum to store search conditions check results.
|
||||
* (whether the search condition has BOL (^) or EOL ($) regexp characters).
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
MC_SEARCH_LINE_NONE = 0,
|
||||
MC_SEARCH_LINE_BEGIN = 1 << 0,
|
||||
MC_SEARCH_LINE_END = 1 << 1,
|
||||
MC_SEARCH_LINE_ENTIRE = MC_SEARCH_LINE_BEGIN | MC_SEARCH_LINE_END
|
||||
} mc_search_line_t;
|
||||
|
||||
enum mc_search_cbret_t
|
||||
{
|
||||
MC_SEARCH_CB_OK = 0,
|
||||
@ -185,6 +197,8 @@ gchar **mc_search_get_types_strings_array (size_t *num);
|
||||
gboolean mc_search (const gchar * pattern, const gchar * pattern_charset, const gchar * str,
|
||||
mc_search_type_t type);
|
||||
|
||||
mc_search_line_t mc_search_get_line_type (const mc_search_t *search);
|
||||
|
||||
int mc_search_getstart_result_by_num (mc_search_t * lc_mc_search, int lc_index);
|
||||
int mc_search_getend_result_by_num (mc_search_t * lc_mc_search, int lc_index);
|
||||
|
||||
|
@ -1114,3 +1114,30 @@ mc_search_regex_prepare_replace_str (mc_search_t *lc_mc_search, GString *replace
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Checks whether search condition has BOL (^) or EOL ($) regexp special characters.
|
||||
*
|
||||
* @param search search object
|
||||
* @return check result
|
||||
*/
|
||||
|
||||
mc_search_line_t
|
||||
mc_search_get_line_type (const mc_search_t *search)
|
||||
{
|
||||
mc_search_line_t search_line_type = MC_SEARCH_LINE_NONE;
|
||||
|
||||
if (search->search_type == MC_SEARCH_T_REGEX)
|
||||
{
|
||||
if (search->original.str->str[0] == '^')
|
||||
search_line_type |= MC_SEARCH_LINE_BEGIN;
|
||||
|
||||
if (search->original.str->str[search->original.str->len - 1] == '$')
|
||||
search_line_type |= MC_SEARCH_LINE_END;
|
||||
}
|
||||
|
||||
return search_line_type;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -291,31 +291,6 @@ edit_search_get_current_end_line_char (const WEdit *edit)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Checking if search condition have BOL(^) or EOL ($) regexp special characters.
|
||||
*
|
||||
* @param search search object
|
||||
* @return result of checks.
|
||||
*/
|
||||
|
||||
static edit_search_line_t
|
||||
edit_get_search_line_type (const mc_search_t *search)
|
||||
{
|
||||
edit_search_line_t search_line_type = 0;
|
||||
|
||||
if (search->search_type == MC_SEARCH_T_REGEX)
|
||||
{
|
||||
if (search->original.str->str[0] == '^')
|
||||
search_line_type |= AT_START_LINE;
|
||||
|
||||
if (search->original.str->str[search->original.str->len - 1] == '$')
|
||||
search_line_type |= AT_END_LINE;
|
||||
}
|
||||
|
||||
return search_line_type;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Calculating the start position of next line.
|
||||
@ -460,14 +435,14 @@ edit_find (edit_search_status_msg_t *esm, gsize *len)
|
||||
}
|
||||
|
||||
/* fix the start and the end of search block positions */
|
||||
if ((edit->search_line_type & AT_START_LINE) != 0
|
||||
if ((edit->search_line_type & MC_SEARCH_LINE_BEGIN) != 0
|
||||
&& (start_mark != 0
|
||||
|| edit_buffer_get_byte (&edit->buffer, start_mark - 1) != end_string_symbol))
|
||||
start_mark =
|
||||
edit_calculate_start_of_next_line (&edit->buffer, start_mark, edit->buffer.size,
|
||||
end_string_symbol);
|
||||
|
||||
if ((edit->search_line_type & AT_END_LINE) != 0
|
||||
if ((edit->search_line_type & MC_SEARCH_LINE_END) != 0
|
||||
&& (end_mark - 1 != edit->buffer.size
|
||||
|| edit_buffer_get_byte (&edit->buffer, end_mark) != end_string_symbol))
|
||||
end_mark =
|
||||
@ -488,7 +463,7 @@ edit_find (edit_search_status_msg_t *esm, gsize *len)
|
||||
/* backward search */
|
||||
search_end = end_mark;
|
||||
|
||||
if ((edit->search_line_type & AT_START_LINE) != 0)
|
||||
if ((edit->search_line_type & MC_SEARCH_LINE_BEGIN) != 0)
|
||||
search_start =
|
||||
edit_calculate_start_of_current_line (&edit->buffer, search_start,
|
||||
end_string_symbol);
|
||||
@ -511,7 +486,7 @@ edit_find (edit_search_status_msg_t *esm, gsize *len)
|
||||
if (!ok && edit->search->error != MC_SEARCH_E_NOTFOUND)
|
||||
return FALSE;
|
||||
|
||||
if ((edit->search_line_type & AT_START_LINE) != 0)
|
||||
if ((edit->search_line_type & MC_SEARCH_LINE_BEGIN) != 0)
|
||||
search_start =
|
||||
edit_calculate_start_of_previous_line (&edit->buffer, search_start,
|
||||
end_string_symbol);
|
||||
@ -524,7 +499,7 @@ edit_find (edit_search_status_msg_t *esm, gsize *len)
|
||||
}
|
||||
|
||||
/* forward search */
|
||||
if ((edit->search_line_type & AT_START_LINE) != 0 && search_start != start_mark)
|
||||
if ((edit->search_line_type & MC_SEARCH_LINE_BEGIN) != 0 && search_start != start_mark)
|
||||
search_start =
|
||||
edit_calculate_start_of_next_line (&edit->buffer, search_start, end_mark,
|
||||
end_string_symbol);
|
||||
@ -697,7 +672,7 @@ edit_search_init (WEdit *edit, const char *str)
|
||||
edit->search->search_fn = edit_search_cmd_callback;
|
||||
edit->search->update_fn = edit_search_update_callback;
|
||||
|
||||
edit->search_line_type = edit_get_search_line_type (edit->search);
|
||||
edit->search_line_type = mc_search_get_line_type (edit->search);
|
||||
|
||||
edit_search_fix_search_start_if_selection (edit);
|
||||
|
||||
|
@ -19,16 +19,6 @@
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/**
|
||||
enum for store the search conditions check results.
|
||||
(if search condition have BOL(^) or EOL ($) regexp checial characters).
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
AT_START_LINE = (1 << 0),
|
||||
AT_END_LINE = (1 << 1)
|
||||
} edit_search_line_t;
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
typedef struct edit_book_mark_t edit_book_mark_t;
|
||||
@ -89,8 +79,8 @@ struct WEdit
|
||||
/* search handler */
|
||||
mc_search_t *search;
|
||||
int replace_mode;
|
||||
/* is search conditions should be started from BOL(^) or ended with EOL($) */
|
||||
edit_search_line_t search_line_type;
|
||||
/* whether search conditions should be started with BOL(^) or ended with EOL($) */
|
||||
mc_search_line_t search_line_type;
|
||||
|
||||
char *last_search_string; /* String that have been searched */
|
||||
off_t search_start; /* First character to start searching from */
|
||||
|
Loading…
Reference in New Issue
Block a user