| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #ifndef SEARCH_H | ||
| 2 | #define SEARCH_H | ||
| 3 | |||
| 4 | #include <regex.h> | ||
| 5 | #include <stdbool.h> | ||
| 6 | #include "util/macros.h" | ||
| 7 | #include "view.h" | ||
| 8 | |||
| 9 | typedef enum { | ||
| 10 | CSS_FALSE, | ||
| 11 | CSS_TRUE, | ||
| 12 | CSS_AUTO, | ||
| 13 | } SearchCaseSensitivity; | ||
| 14 | |||
| 15 | typedef struct { | ||
| 16 | regex_t regex; | ||
| 17 | char *pattern; | ||
| 18 | int re_flags; // If zero, regex hasn't been compiled | ||
| 19 | bool reverse; | ||
| 20 | } SearchState; | ||
| 21 | |||
| 22 | bool do_search_next(View *view, SearchState *search, SearchCaseSensitivity cs, bool skip) NONNULL_ARGS WARN_UNUSED_RESULT; | ||
| 23 | |||
| 24 | 2 | static inline void toggle_search_direction(SearchState *search) | |
| 25 | { | ||
| 26 | 2 | search->reverse ^= 1; | |
| 27 | 2 | } | |
| 28 | |||
| 29 | NONNULL_ARGS WARN_UNUSED_RESULT | ||
| 30 | 2 | static inline bool search_next(View *view, SearchState *search, SearchCaseSensitivity cs) | |
| 31 | { | ||
| 32 | 2 | return do_search_next(view, search, cs, false); | |
| 33 | } | ||
| 34 | |||
| 35 | NONNULL_ARGS WARN_UNUSED_RESULT | ||
| 36 | 1 | static inline bool search_prev(View *view, SearchState *search, SearchCaseSensitivity cs) | |
| 37 | { | ||
| 38 | 1 | toggle_search_direction(search); | |
| 39 | 1 | bool r = search_next(view, search, cs); | |
| 40 | 1 | toggle_search_direction(search); | |
| 41 | 1 | return r; | |
| 42 | } | ||
| 43 | |||
| 44 | bool search_tag(View *view, const char *pattern) NONNULL_ARGS WARN_UNUSED_RESULT; | ||
| 45 | void search_set_regexp(SearchState *search, const char *pattern) NONNULL_ARGS; | ||
| 46 | void search_free_regexp(SearchState *search) NONNULL_ARGS; | ||
| 47 | |||
| 48 | #endif | ||
| 49 |