NetSurf
Data Structures | Functions
textsearch.c File Reference

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"
Include dependency graph for textsearch.c:

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...
 

Detailed Description

Free text search.

Definition in file textsearch.c.

Function Documentation

◆ content_textsearch()

nserror content_textsearch ( struct hlcache_handle h,
void *  context,
search_flags_t  flags,
const char *  string 
)

Free text search a content.

Parameters
[in]hHandle to content to search.
[in]contextThe context passed to gui table search handlers
[in]flagsThe flags that control the search
[in]Thestring 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ content_textsearch__clear()

static nserror content_textsearch__clear ( struct content c)
static

Terminate a search.

Parameters
ccontent 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ content_textsearch_add_match()

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.

Parameters
contextThe search context to add the entry to.
start_idxOffset of match start within textual representation
end_idxOffset of match end
startA pointer for the start
endA pointer for the end
Returns
NSERROR_OK on sucess else error code on faliure

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().

Here is the caller graph for this function:

◆ content_textsearch_clear()

nserror content_textsearch_clear ( struct hlcache_handle h)

Clear a search.

Parameters
[in]hHandle 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ content_textsearch_create()

static nserror content_textsearch_create ( struct content c,
void *  gui_data,
struct textsearch_context **  textsearch_out 
)
static

create a search_context

Parameters
cThe content the search_context is connected to
contextA context pointer passed to the provider routines.
search_outA pointer to recive the new text search context
Returns
NSERROR_OK on success and search_out updated else error code

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().

Here is the caller graph for this function:

◆ content_textsearch_destroy()

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ content_textsearch_find_pattern()

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.

Parameters
stringthe string to be searched (unterminated)
s_lenlength of the string to be searched
patternthe pattern for which we are searching (unterminated)
p_lenlength of pattern
case_senstrue iff case sensitive match required
m_lenaccepts length of match in bytes
Returns
pointer to first match, NULL if none

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ content_textsearch_ishighlighted()

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.

Parameters
textsearchThe search context to hilight entries from.
cThe content to highlight within.
start_offsetbyte offset within text of string to be checked
end_offsetbyte offset within text
start_idxbyte offset within string of highlight start
end_idxbyte offset of highlight end
Returns
true iff part of the box should be highlighted

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ content_textsearch_step()

static nserror content_textsearch_step ( struct textsearch_context textsearch,
search_flags_t  flags,
const char *  string 
)
static

Begins/continues the search process.

Note
that this may be called many times for a single search.
Parameters
contextThe search context in use.
flagsThe flags forward/back etc
stringThe 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ free_matches()

static void free_matches ( struct textsearch_context 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ search_show_all()

static void search_show_all ( bool  all,
struct textsearch_context context 
)
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ search_text()

static nserror search_text ( struct textsearch_context context,
const char *  string,
int  string_len,
search_flags_t  flags 
)
static

Search for a string in a content.

Parameters
contextThe search context.
stringthe string to search for
string_lenlength of search string
flagsflags 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ textsearch_broadcast()

static void textsearch_broadcast ( struct textsearch_context textsearch,
int  type,
bool  state,
const char *  string 
)
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().

Here is the call graph for this function:
Here is the caller graph for this function: