normal.c 3.6 KB

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