summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2020-05-12 21:21:59 +0100
committerVincent Sanders <vince@kyllikki.org>2020-05-12 21:29:32 +0100
commit68b9417a6bc8344f68f8a8206d2f2781079bd713 (patch)
tree3d17a1a61f50f87f84bb6d2c3938bb6474477679
parent3c7538a9f906e38e78be0300049f9e49839d7fd7 (diff)
downloadnetsurf-68b9417a6bc8344f68f8a8206d2f2781079bd713.tar.gz
netsurf-68b9417a6bc8344f68f8a8206d2f2781079bd713.tar.bz2
consolodate the textsearch code into a single module
-rw-r--r--content/content.c81
-rw-r--r--content/textsearch.c103
-rw-r--r--content/textsearch.h23
-rw-r--r--desktop/search.c2
4 files changed, 102 insertions, 107 deletions
diff --git a/content/content.c b/content/content.c
index 34602d686..bc3f48429 100644
--- a/content/content.c
+++ b/content/content.c
@@ -917,87 +917,6 @@ content_drop_file_at_point(struct hlcache_handle *h,
}
-/**
- * Terminate a search.
- *
- * \param c content to clear
- */
-static nserror content_textsearch__clear(struct content *c)
-{
- free(c->textsearch.string);
- c->textsearch.string = NULL;
-
- if (c->textsearch.context != NULL) {
- content_textsearch_destroy(c->textsearch.context);
- c->textsearch.context = NULL;
- }
- return NSERROR_OK;
-}
-
-/* exported interface, documented in content/content.h */
-nserror
-content_textsearch(struct hlcache_handle *h,
- void *context,
- search_flags_t flags,
- const char *string)
-{
- struct content *c = hlcache_handle_get_content(h);
- nserror res;
-
- assert(c != NULL);
-
- if (string != NULL &&
- c->textsearch.string != NULL &&
- c->textsearch.context != NULL &&
- strcmp(string, c->textsearch.string) == 0) {
- /* Continue prev. search */
- content_textsearch_step(c->textsearch.context, flags, string);
-
- } else if (string != NULL) {
- /* New search */
- free(c->textsearch.string);
- c->textsearch.string = strdup(string);
- if (c->textsearch.string == NULL) {
- return NSERROR_NOMEM;
- }
-
- if (c->textsearch.context != NULL) {
- content_textsearch_destroy(c->textsearch.context);
- c->textsearch.context = NULL;
- }
-
- res = content_textsearch_create(c,
- context,
- &c->textsearch.context);
- if (res != NSERROR_OK) {
- return res;
- }
-
- content_textsearch_step(c->textsearch.context, flags, string);
-
- } else {
- /* Clear search */
- content_textsearch__clear(c);
-
- free(c->textsearch.string);
- c->textsearch.string = NULL;
- }
-
- return NSERROR_OK;
-}
-
-
-
-/* exported interface, documented in content/content.h */
-nserror content_textsearch_clear(struct hlcache_handle *h)
-{
- struct content *c = hlcache_handle_get_content(h);
- assert(c != 0);
-
- return(content_textsearch__clear(c));
-}
-
-
/* exported interface documented in content/content.h */
nserror
content_debug_dump(struct hlcache_handle *h, FILE *f, enum content_debug op)
diff --git a/content/textsearch.c b/content/textsearch.c
index c5359482d..7db0714dc 100644
--- a/content/textsearch.c
+++ b/content/textsearch.c
@@ -30,6 +30,7 @@
#include "utils/errors.h"
#include "utils/utils.h"
#include "content/content.h"
+#include "content/hlcache.h"
#include "desktop/selection.h"
#include "netsurf/search.h"
#include "netsurf/content_type.h"
@@ -583,8 +584,16 @@ search_text(const char *string,
}
-/* Exported function documented in context/textsearch.h */
-nserror
+/**
+ * Begins/continues the search process
+ *
+ * \note that this may be called many times for a single search.
+ *
+ * \param context The search context in use.
+ * \param flags The flags forward/back etc
+ * \param string The string to match
+ */
+static nserror
content_textsearch_step(struct textsearch_context *textsearch,
search_flags_t flags,
const char *string)
@@ -649,7 +658,15 @@ content_textsearch_ishighlighted(struct textsearch_context *textsearch,
/* Exported function documented in content/textsearch.h */
-nserror
+/**
+ * create a search_context
+ *
+ * \param c The content the search_context is connected to
+ * \param context A context pointer passed to the provider routines.
+ * \param search_out A pointer to recive the new text search context
+ * \return NSERROR_OK on success and \a search_out updated else error code
+ */
+static nserror
content_textsearch_create(struct content *c,
void *gui_data,
struct textsearch_context **textsearch_out)
@@ -716,3 +733,83 @@ nserror content_textsearch_destroy(struct textsearch_context *textsearch)
return NSERROR_OK;
}
+
+/**
+ * Terminate a search.
+ *
+ * \param c content to clear
+ */
+static nserror content_textsearch__clear(struct content *c)
+{
+ free(c->textsearch.string);
+ c->textsearch.string = NULL;
+
+ if (c->textsearch.context != NULL) {
+ content_textsearch_destroy(c->textsearch.context);
+ c->textsearch.context = NULL;
+ }
+ return NSERROR_OK;
+}
+
+
+/* exported interface, documented in content/textsearch.h */
+nserror
+content_textsearch(struct hlcache_handle *h,
+ void *context,
+ search_flags_t flags,
+ const char *string)
+{
+ struct content *c = hlcache_handle_get_content(h);
+ nserror res;
+
+ assert(c != NULL);
+
+ if (string != NULL &&
+ c->textsearch.string != NULL &&
+ c->textsearch.context != NULL &&
+ strcmp(string, c->textsearch.string) == 0) {
+ /* Continue prev. search */
+ content_textsearch_step(c->textsearch.context, flags, string);
+
+ } else if (string != NULL) {
+ /* New search */
+ free(c->textsearch.string);
+ c->textsearch.string = strdup(string);
+ if (c->textsearch.string == NULL) {
+ return NSERROR_NOMEM;
+ }
+
+ if (c->textsearch.context != NULL) {
+ content_textsearch_destroy(c->textsearch.context);
+ c->textsearch.context = NULL;
+ }
+
+ res = content_textsearch_create(c,
+ context,
+ &c->textsearch.context);
+ if (res != NSERROR_OK) {
+ return res;
+ }
+
+ content_textsearch_step(c->textsearch.context, flags, string);
+
+ } else {
+ /* Clear search */
+ content_textsearch__clear(c);
+
+ free(c->textsearch.string);
+ c->textsearch.string = NULL;
+ }
+
+ return NSERROR_OK;
+}
+
+
+/* exported interface, documented in content/textsearch.h */
+nserror content_textsearch_clear(struct hlcache_handle *h)
+{
+ struct content *c = hlcache_handle_get_content(h);
+ assert(c != 0);
+
+ return(content_textsearch__clear(c));
+}
diff --git a/content/textsearch.h b/content/textsearch.h
index f94bcdb42..c0a1acf9a 100644
--- a/content/textsearch.h
+++ b/content/textsearch.h
@@ -24,34 +24,11 @@
#ifndef NETSURF_CONTENT_SEARCH_H
#define NETSURF_CONTENT_SEARCH_H
-#include <ctype.h>
-#include <string.h>
-
#include "desktop/search.h"
struct textsearch_context;
struct content;
-/**
- * create a search_context
- *
- * \param c The content the search_context is connected to
- * \param context A context pointer passed to the provider routines.
- * \param search_out A pointer to recive the new text search context
- * \return NSERROR_OK on success and \a search_out updated else error code
- */
-nserror content_textsearch_create(struct content *c, void *context, struct textsearch_context **textsearch_out);
-
-/**
- * Begins/continues the search process
- *
- * \note that this may be called many times for a single search.
- *
- * \param context The search context in use.
- * \param flags The flags forward/back etc
- * \param string The string to match
- */
-nserror content_textsearch_step(struct textsearch_context *textsearch, search_flags_t flags, const char *string);
/**
* Ends the search process, invalidating all state freeing the list of
diff --git a/desktop/search.c b/desktop/search.c
index df77a8fda..d4abfed92 100644
--- a/desktop/search.c
+++ b/desktop/search.c
@@ -23,6 +23,8 @@
* Free text search (core)
*/
+#include <stdbool.h>
+
#include "utils/errors.h"
#include "content/content.h"
#include "netsurf/types.h"