Cabal syntax file introduced.
[midnight-commander.git] / src / search / normal.c
blobfb31f7159846662042c452abd31475dc29ab74c3
1 /*
2 Search text engine.
3 Plain search
5 Copyright (C) 2009 The Free Software Foundation, Inc.
7 Written by:
8 Slava Zanko <slavazanko@gmail.com>, 2009.
10 This file is part of the Midnight Commander.
12 The Midnight Commander is free software; you can redistribute it
13 and/or modify it under the terms of the GNU General Public License as
14 published by the Free Software Foundation; either version 2 of the
15 License, or (at your option) any later version.
17 The Midnight Commander is distributed in the hope that it will be
18 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
19 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
25 MA 02110-1301, USA.
28 #include <config.h>
31 #include "../src/global.h"
32 #include "../src/search/search.h"
33 #include "../src/search/internal.h"
34 #include "../src/strutil.h"
35 #include "../src/charsets.h"
37 /*** global variables ****************************************************************************/
39 /*** file scope macro definitions ****************************************************************/
41 /*** file scope type declarations ****************************************************************/
43 /*** file scope variables ************************************************************************/
45 /*** file scope functions ************************************************************************/
47 static GString *
48 mc_search__normal_translate_to_regex (gchar * str, gsize * len)
50 GString *buff = g_string_new ("");
51 gsize orig_len = *len;
52 gsize loop = 0;
54 while (loop < orig_len) {
55 switch (str[loop]) {
56 case '*':
57 case '?':
58 case ',':
59 case '{':
60 case '}':
61 case '[':
62 case ']':
63 case '\\':
64 case '+':
65 case '.':
66 case '$':
67 case '(':
68 case ')':
69 case '^':
70 case '-':
71 case '|':
72 g_string_append_c (buff, '\\');
73 g_string_append_c (buff, str[loop]);
74 loop++;
75 continue;
76 break;
78 g_string_append_c (buff, str[loop]);
79 loop++;
81 *len = buff->len;
82 return buff;
85 /*** public functions ****************************************************************************/
87 void
88 mc_search__cond_struct_new_init_normal (const char *charset, mc_search_t * lc_mc_search,
89 mc_search_cond_t * mc_search_cond)
91 GString *tmp =
92 mc_search__normal_translate_to_regex (mc_search_cond->str->str, &mc_search_cond->len);
94 g_string_free (mc_search_cond->str, TRUE);
95 if (lc_mc_search->whole_words) {
96 g_string_prepend (tmp, "\\b");
97 g_string_append (tmp, "\\b");
99 mc_search_cond->str = tmp;
101 mc_search__cond_struct_new_init_regex (charset, lc_mc_search, mc_search_cond);
105 /* --------------------------------------------------------------------------------------------- */
107 gboolean
108 mc_search__run_normal (mc_search_t * lc_mc_search, const void *user_data,
109 gsize start_search, gsize end_search, gsize * found_len)
111 return mc_search__run_regex (lc_mc_search, user_data, start_search, end_search, found_len);
114 /* --------------------------------------------------------------------------------------------- */
115 GString *
116 mc_search_normal_prepare_replace_str (mc_search_t * lc_mc_search, GString * replace_str)
118 (void) lc_mc_search;
119 return g_string_new_len (replace_str->str, replace_str->len);