NetSurf
|
Free text search (core) More...
#include <ctype.h>
#include <string.h>
#include <dom/dom.h>
#include "utils/config.h"
#include "utils/log.h"
#include "utils/messages.h"
#include "utils/utils.h"
#include "content/content.h"
#include "content/hlcache.h"
#include "desktop/selection.h"
#include "netsurf/search.h"
#include "netsurf/misc.h"
#include "desktop/gui_internal.h"
#include "text/textplain.h"
#include "html/box.h"
#include "html/box_inspect.h"
#include "html/html.h"
#include "html/private.h"
#include "html/search.h"
Go to the source code of this file.
Data Structures | |
struct | list_entry |
struct | search_context |
Macros | |
#define | NOF_ELEMENTS(array) (sizeof(array)/sizeof(*(array))) |
Functions | |
struct search_context * | search_create_context (struct content *c, content_type type, void *gui_data) |
create a search_context More... | |
static void | free_matches (struct search_context *context) |
Release the memory used by the list of matches, deleting selection objects too. More... | |
static const char * | find_pattern (const char *string, int s_len, const char *pattern, int p_len, bool case_sens, unsigned int *m_len) |
Find the first occurrence of 'match' in 'string' and return its index. More... | |
static struct list_entry * | add_entry (unsigned start_idx, unsigned end_idx, struct search_context *context) |
Add a new entry to the list of matches. More... | |
static bool | find_occurrences_html (const char *pattern, int p_len, struct box *cur, bool case_sens, struct search_context *context) |
Finds all occurrences of a given string in the html box tree. More... | |
static bool | find_occurrences_text (const char *pattern, int p_len, struct content *c, bool case_sens, struct search_context *context) |
Finds all occurrences of a given string in a textplain content. More... | |
static void | search_show_all (bool all, struct search_context *context) |
Specifies whether all matches or just the current match should be highlighted in the search text. More... | |
static void | search_text (const char *string, int string_len, struct search_context *context, search_flags_t flags) |
Search for a string in the box tree. More... | |
void | search_step (struct search_context *context, search_flags_t flags, const char *string) |
Begins/continues the search process. More... | |
bool | search_term_highlighted (struct content *c, unsigned start_offset, unsigned end_offset, unsigned *start_idx, unsigned *end_idx, struct search_context *context) |
Determines whether any portion of the given text box should be selected because it matches the current search string. More... | |
void | search_destroy_context (struct search_context *context) |
Ends the search process, invalidating all state freeing the list of found boxes. More... | |
Free text search (core)
Definition in file search.c.
#define NOF_ELEMENTS | ( | array | ) | (sizeof(array)/sizeof(*(array))) |
Definition at line 49 of file search.c.
Referenced by find_pattern().
|
static |
Add a new entry to the list of matches.
start_idx | Offset of match start within textual representation |
end_idx | Offset of match end |
context | The search context to add the entry to. |
Definition at line 278 of file search.c.
References list_entry::end_idx, search_context::found, list_entry::next, list_entry::prev, list_entry::sel, and list_entry::start_idx.
Referenced by find_occurrences_html(), and find_occurrences_text().
|
static |
Finds all occurrences of a given string in the html box tree.
pattern | the string pattern to search for |
p_len | pattern length |
cur | pointer to the current box |
case_sens | whether to perform a case sensitive search |
context | The search context to add the entry to. |
Definition at line 317 of file search.c.
References add_entry(), box::byte_offset, box::children, list_entry::end_box, find_pattern(), box::length, box::next, box::object, list_entry::start_box, box::text, and text().
Referenced by search_text().
|
static |
Finds all occurrences of a given string in a textplain content.
pattern | the string pattern to search for |
p_len | pattern length |
c | the content to be searched |
case_sens | whether to perform a case sensitive search |
context | The search context to add the entry to. |
Definition at line 380 of file search.c.
References add_entry(), find_pattern(), line(), list_entry::start_idx, text(), textplain_get_line(), and textplain_line_count().
Referenced by search_text().
|
static |
Find the first occurrence of 'match' in 'string' and return its index.
string | the string to be searched (unterminated) |
s_len | length of the string to be searched |
pattern | the pattern for which we are searching (unterminated) |
p_len | length of pattern |
case_sens | true iff case sensitive match required |
m_len | accepts length of match in bytes |
Definition at line 163 of file search.c.
References max, and NOF_ELEMENTS.
Referenced by find_occurrences_html(), and find_occurrences_text().
|
static |
Release the memory used by the list of matches, deleting selection objects too.
Definition at line 126 of file search.c.
References search_context::found, list_entry::next, list_entry::prev, list_entry::sel, selection_clear(), and selection_destroy().
Referenced by search_destroy_context(), search_step(), and search_text().
struct search_context* search_create_context | ( | struct content * | c, |
content_type | type, | ||
void * | context | ||
) |
create a search_context
c | The content the search_context is connected to |
type | The content type of c |
context | A context pointer passed to the provider routines. |
Definition at line 80 of file search.c.
References search_context::c, CONTENT_HTML, CONTENT_TEXTPLAIN, search_context::current, list_entry::end_box, list_entry::end_idx, search_context::found, search_context::gui_p, search_context::is_html, search_context::newsearch, list_entry::next, list_entry::prev, search_context::prev_case_sens, list_entry::sel, list_entry::start_box, list_entry::start_idx, and search_context::string.
Referenced by html_search(), and textplain_search().
void search_destroy_context | ( | struct search_context * | context | ) |
Ends the search process, invalidating all state freeing the list of found boxes.
Definition at line 648 of file search.c.
References gui_search_table::add_recent, gui_search_table::back_state, gui_search_table::forward_state, free_matches(), search_context::gui_p, guit, netsurf_table::search, and search_context::string.
Referenced by html_close(), html_search(), html_search_clear(), textplain_close(), textplain_search(), and textplain_search_clear().
|
static |
Specifies whether all matches or just the current match should be highlighted in the search text.
Definition at line 426 of file search.c.
References search_context::c, search_context::current, list_entry::end_idx, search_context::found, search_context::is_html, html_content::layout, html_content::len_ctx, list_entry::next, list_entry::sel, selection_clear(), selection_create(), selection_destroy(), selection_init(), selection_set_end(), selection_set_start(), and list_entry::start_idx.
Referenced by search_text().
void search_step | ( | struct search_context * | context, |
search_flags_t | flags, | ||
const char * | string | ||
) |
Begins/continues the search process.
context | The search context in use. |
flags | The flags forward/back etc |
string | The string to match |
Definition at line 592 of file search.c.
References gui_search_table::add_recent, content_msg_data::area, gui_search_table::back_state, search_context::c, content_broadcast(), CONTENT_MSG_SCROLL, gui_search_table::forward_state, free_matches(), search_context::gui_p, guit, content_msg_data::scroll, netsurf_table::search, search_text(), gui_search_table::status, content_msg_data::x0, and content_msg_data::y0.
Referenced by html_search(), and textplain_search().
bool search_term_highlighted | ( | struct content * | c, |
unsigned | start_offset, | ||
unsigned | end_offset, | ||
unsigned * | start_idx, | ||
unsigned * | end_idx, | ||
struct search_context * | context | ||
) |
Determines whether any portion of the given text box should be selected because it matches the current search string.
c | The content to hilight within. |
start_offset | byte offset within text of string to be checked |
end_offset | byte offset within text |
start_idx | byte offset within string of highlight start |
end_idx | byte offset of highlight end |
context | The search context to hilight entries from. |
Definition at line 626 of file search.c.
References search_context::c, search_context::found, list_entry::next, list_entry::sel, selection_defined, and selection_highlighted().
Referenced by text_draw(), text_redraw(), and textplain_redraw().
|
static |
Search for a string in the box tree.
string | the string to search for |
string_len | length of search string |
context | The search context to add the entry to. |
flags | flags to control the search. |
Definition at line 474 of file search.c.
References content_msg_data::area, gui_search_table::back_state, box_coords(), search_context::c, content_broadcast(), CONTENT_MSG_SCROLL, search_context::current, list_entry::end_box, list_entry::end_idx, find_occurrences_html(), find_occurrences_text(), gui_search_table::forward_state, search_context::found, free_matches(), search_context::gui_p, guit, box::height, gui_search_table::hourglass, search_context::is_html, html_content::layout, search_context::newsearch, list_entry::next, list_entry::prev, search_context::prev_case_sens, content_msg_data::scroll, netsurf_table::search, SEARCH_FLAG_CASE_SENSITIVE, SEARCH_FLAG_FORWARDS, SEARCH_FLAG_SHOWALL, search_show_all(), list_entry::start_box, list_entry::start_idx, gui_search_table::status, search_context::string, textplain_coords_from_range(), box::width, rect::x0, content_msg_data::x0, rect::x1, content_msg_data::x1, rect::y0, content_msg_data::y0, rect::y1, and content_msg_data::y1.
Referenced by search_step().