NetSurf
|
Free text search. More...
#include <stdbool.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include "utils/errors.h"
#include "utils/utils.h"
#include "utils/ascii.h"
#include "netsurf/types.h"
#include "desktop/selection.h"
#include "content/content.h"
#include "content/content_protected.h"
#include "content/hlcache.h"
#include "content/textsearch.h"
Go to the source code of this file.
Data Structures | |
struct | list_entry |
search match More... | |
struct | textsearch_context |
The context for a free text search. More... | |
Functions | |
static void | textsearch_broadcast (struct textsearch_context *textsearch, int type, bool state, const char *string) |
broadcast textsearch message More... | |
static void | free_matches (struct textsearch_context *textsearch) |
Release the memory used by the list of matches, deleting selection objects too. More... | |
static void | search_show_all (bool all, struct textsearch_context *context) |
Specifies whether all matches or just the current match should be highlighted in the search text. More... | |
static nserror | search_text (struct textsearch_context *context, const char *string, int string_len, search_flags_t flags) |
Search for a string in a content. More... | |
static nserror | content_textsearch_step (struct textsearch_context *textsearch, search_flags_t flags, const char *string) |
Begins/continues the search process. More... | |
static nserror | content_textsearch__clear (struct content *c) |
Terminate a search. More... | |
static nserror | content_textsearch_create (struct content *c, void *gui_data, struct textsearch_context **textsearch_out) |
create a search_context More... | |
const char * | content_textsearch_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... | |
nserror | content_textsearch_add_match (struct textsearch_context *context, unsigned start_idx, unsigned end_idx, struct box *start_box, struct box *end_box) |
Add a new entry to the list of matches. More... | |
bool | content_textsearch_ishighlighted (struct textsearch_context *textsearch, unsigned start_offset, unsigned end_offset, unsigned *start_idx, unsigned *end_idx) |
Determines whether any portion of the given text box should be selected because it matches the current search string. More... | |
nserror | content_textsearch_destroy (struct textsearch_context *textsearch) |
Ends the search process, invalidating all state freeing the list of found boxes. More... | |
nserror | content_textsearch (struct hlcache_handle *h, void *context, search_flags_t flags, const char *string) |
Free text search a content. More... | |
nserror | content_textsearch_clear (struct hlcache_handle *h) |
Clear a search. More... | |
Free text search.
Definition in file textsearch.c.
nserror content_textsearch | ( | struct hlcache_handle * | h, |
void * | context, | ||
search_flags_t | flags, | ||
const char * | string | ||
) |
Free text search a content.
[in] | h | Handle to content to search. |
[in] | context | The context passed to gui table search handlers |
[in] | flags | The flags that control the search |
[in] | The | string being searched for. \retun NSERROR_OK on success else error code on faliure |
Definition at line 682 of file textsearch.c.
References content_textsearch__clear(), content_textsearch_create(), content_textsearch_destroy(), content_textsearch_step(), content::context, hlcache_handle_get_content(), NSERROR_NOMEM, NSERROR_OK, content::string, and content::textsearch.
Referenced by browser_window_search().
Terminate a search.
c | content to clear |
Definition at line 399 of file textsearch.c.
References content_textsearch_destroy(), content::context, NSERROR_OK, content::string, and content::textsearch.
Referenced by content_textsearch(), and content_textsearch_clear().
nserror content_textsearch_add_match | ( | struct textsearch_context * | context, |
unsigned | start_idx, | ||
unsigned | end_idx, | ||
struct box * | start_ptr, | ||
struct box * | end_ptr | ||
) |
Add a new entry to the list of matches.
context | The search context to add the entry to. |
start_idx | Offset of match start within textual representation |
end_idx | Offset of match end |
start | A pointer for the start |
end | A pointer for the end |
Definition at line 586 of file textsearch.c.
References list_entry::end_box, list_entry::end_idx, textsearch_context::found, list_entry::next, NSERROR_NOMEM, NSERROR_OK, list_entry::prev, list_entry::sel, list_entry::start_box, and list_entry::start_idx.
Referenced by find_occurrences_html_box(), and textplain_textsearch_find().
nserror content_textsearch_clear | ( | struct hlcache_handle * | h | ) |
Clear a search.
[in] | h | Handle to content to clear search from. |
Definition at line 734 of file textsearch.c.
References content_textsearch__clear(), and hlcache_handle_get_content().
Referenced by browser_window_search_clear().
|
static |
create a search_context
c | The content the search_context is connected to |
context | A context pointer passed to the provider routines. |
search_out | A pointer to recive the new text search context |
Definition at line 421 of file textsearch.c.
References textsearch_context::c, textsearch_context::current, list_entry::end_box, list_entry::end_idx, textsearch_context::found, textsearch_context::gui_p, content::handler, textsearch_context::newsearch, list_entry::next, NSERROR_NOMEM, NSERROR_NOT_IMPLEMENTED, NSERROR_OK, list_entry::prev, textsearch_context::prev_case_sens, list_entry::sel, list_entry::start_box, list_entry::start_idx, textsearch_context::string, content_handler::textsearch_bounds, content_handler::textsearch_find, content_handler::type, and type.
Referenced by content_textsearch().
nserror content_textsearch_destroy | ( | struct textsearch_context * | textsearch | ) |
Ends the search process, invalidating all state freeing the list of found boxes.
Definition at line 647 of file textsearch.c.
References free_matches(), NSERROR_OK, textsearch_context::string, and textsearch_broadcast().
Referenced by content_close(), content_textsearch(), and content_textsearch__clear().
const char * content_textsearch_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.
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 475 of file textsearch.c.
References ascii_to_upper(), max, and NOF_ELEMENTS.
Referenced by find_occurrences_html_box(), and textplain_textsearch_find().
bool content_textsearch_ishighlighted | ( | struct textsearch_context * | textsearch, |
unsigned | start_offset, | ||
unsigned | end_offset, | ||
unsigned * | start_idx, | ||
unsigned * | end_idx | ||
) |
Determines whether any portion of the given text box should be selected because it matches the current search string.
textsearch | The search context to hilight entries from. |
c | The content to highlight 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 |
Definition at line 623 of file textsearch.c.
References list_entry::end_idx, textsearch_context::found, list_entry::next, list_entry::sel, selection_highlighted(), and list_entry::start_idx.
Referenced by text_draw(), text_redraw(), and textplain_redraw().
|
static |
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 334 of file textsearch.c.
References content_msg_data::area, content_broadcast(), CONTENT_MSG_SCROLL, content_msg_data::CONTENT_TEXTSEARCH_BACK, content_msg_data::CONTENT_TEXTSEARCH_FORWARD, content_msg_data::CONTENT_TEXTSEARCH_MATCH, content_msg_data::CONTENT_TEXTSEARCH_RECENT, content_msg_data::flags, free_matches(), NSERROR_OK, content_msg_data::scroll, search_text(), content_msg_data::textsearch, textsearch_broadcast(), content_msg_data::x0, and content_msg_data::y0.
Referenced by content_textsearch().
|
static |
Release the memory used by the list of matches, deleting selection objects too.
Definition at line 137 of file textsearch.c.
References textsearch_context::found, list_entry::next, list_entry::prev, list_entry::sel, and selection_destroy().
Referenced by content_textsearch_destroy(), content_textsearch_step(), and search_text().
|
static |
Specifies whether all matches or just the current match should be highlighted in the search text.
Definition at line 167 of file textsearch.c.
References textsearch_context::c, textsearch_context::current, list_entry::end_idx, textsearch_context::found, list_entry::next, list_entry::sel, selection_create(), selection_destroy(), selection_init(), selection_set_position(), and list_entry::start_idx.
Referenced by search_text().
|
static |
Search for a string in a content.
context | The search context. |
string | the string to search for |
string_len | length of search string |
flags | flags to control the search. |
Definition at line 204 of file textsearch.c.
References content_msg_data::area, textsearch_context::c, content_broadcast(), CONTENT_MSG_SCROLL, content_msg_data::CONTENT_TEXTSEARCH_BACK, content_msg_data::CONTENT_TEXTSEARCH_FIND, content_msg_data::CONTENT_TEXTSEARCH_FORWARD, content_msg_data::CONTENT_TEXTSEARCH_MATCH, textsearch_context::current, list_entry::end_box, list_entry::end_idx, content_msg_data::flags, textsearch_context::found, free_matches(), content::handler, textsearch_context::newsearch, list_entry::next, NSERROR_OK, list_entry::prev, textsearch_context::prev_case_sens, content_msg_data::scroll, SEARCH_FLAG_CASE_SENSITIVE, SEARCH_FLAG_FORWARDS, SEARCH_FLAG_SHOWALL, search_show_all(), list_entry::start_box, list_entry::start_idx, textsearch_context::string, content_handler::textsearch_bounds, textsearch_broadcast(), content_handler::textsearch_find, content_msg_data::x0, rect::x0, content_msg_data::x1, rect::x1, content_msg_data::y0, rect::y0, content_msg_data::y1, and rect::y1.
Referenced by content_textsearch_step().
|
inlinestatic |
broadcast textsearch message
Definition at line 119 of file textsearch.c.
References content_broadcast(), CONTENT_MSG_TEXTSEARCH, content_msg_data::ctx, content_msg_data::state, content_msg_data::string, content_msg_data::textsearch, content_msg_data::type, and type.
Referenced by content_textsearch_destroy(), content_textsearch_step(), and search_text().