root/lib/search/normal.c

/* [previous][next][first][last][top][bottom][index][help]  */

DEFINITIONS

This source file includes following definitions.
  1. mc_search__normal_translate_to_regex
  2. mc_search__cond_struct_new_init_normal
  3. mc_search__run_normal
  4. mc_search_normal_prepare_replace_str

   1 /*
   2    Search text engine.
   3    Plain search
   4 
   5    Copyright (C) 2009-2024
   6    Free Software Foundation, Inc.
   7 
   8    Written by:
   9    Slava Zanko <slavazanko@gmail.com>, 2009.
  10 
  11    This file is part of the Midnight Commander.
  12 
  13    The Midnight Commander is free software: you can redistribute it
  14    and/or modify it under the terms of the GNU General Public License as
  15    published by the Free Software Foundation, either version 3 of the License,
  16    or (at your option) any later version.
  17 
  18    The Midnight Commander is distributed in the hope that it will be useful,
  19    but WITHOUT ANY WARRANTY; without even the implied warranty of
  20    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21    GNU General Public License for more details.
  22 
  23    You should have received a copy of the GNU General Public License
  24    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  25  */
  26 
  27 #include <config.h>
  28 
  29 #include "lib/global.h"
  30 #include "lib/strutil.h"
  31 #include "lib/search.h"
  32 
  33 #include "internal.h"
  34 
  35 /*** global variables ****************************************************************************/
  36 
  37 /*** file scope macro definitions ****************************************************************/
  38 
  39 /*** file scope type declarations ****************************************************************/
  40 
  41 /*** forward declarations (file scope functions) *************************************************/
  42 
  43 /*** file scope variables ************************************************************************/
  44 
  45 /* --------------------------------------------------------------------------------------------- */
  46 /*** file scope functions ************************************************************************/
  47 /* --------------------------------------------------------------------------------------------- */
  48 
  49 static void
  50 mc_search__normal_translate_to_regex (GString * str)
     /* [previous][next][first][last][top][bottom][index][help]  */
  51 {
  52     gsize loop;
  53 
  54     for (loop = 0; loop < str->len; loop++)
  55         switch (str->str[loop])
  56         {
  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         case '|':
  73             g_string_insert_c (str, loop, '\\');
  74             loop++;
  75         default:
  76             break;
  77         }
  78 }
  79 
  80 /* --------------------------------------------------------------------------------------------- */
  81 /*** public functions ****************************************************************************/
  82 /* --------------------------------------------------------------------------------------------- */
  83 
  84 void
  85 mc_search__cond_struct_new_init_normal (const char *charset, mc_search_t * lc_mc_search,
     /* [previous][next][first][last][top][bottom][index][help]  */
  86                                         mc_search_cond_t * mc_search_cond)
  87 {
  88     mc_search__normal_translate_to_regex (mc_search_cond->str);
  89     mc_search__cond_struct_new_init_regex (charset, lc_mc_search, mc_search_cond);
  90 }
  91 
  92 /* --------------------------------------------------------------------------------------------- */
  93 
  94 gboolean
  95 mc_search__run_normal (mc_search_t * lc_mc_search, const void *user_data,
     /* [previous][next][first][last][top][bottom][index][help]  */
  96                        gsize start_search, gsize end_search, gsize * found_len)
  97 {
  98     return mc_search__run_regex (lc_mc_search, user_data, start_search, end_search, found_len);
  99 }
 100 
 101 /* --------------------------------------------------------------------------------------------- */
 102 GString *
 103 mc_search_normal_prepare_replace_str (mc_search_t * lc_mc_search, GString * replace_str)
     /* [previous][next][first][last][top][bottom][index][help]  */
 104 {
 105     (void) lc_mc_search;
 106 
 107     return mc_g_string_dup (replace_str);
 108 }

/* [previous][next][first][last][top][bottom][index][help]  */