summaryrefslogtreecommitdiff
path: root/pluma/pluma-document.c
diff options
context:
space:
mode:
authorV.Barkov <[email protected]>2016-11-20 09:36:10 +0300
committerV.Barkov <[email protected]>2016-11-20 09:36:10 +0300
commit206d27c66761cedebec8bedcaa91bf9f08846095 (patch)
tree33d97b7ecc39bb50a26bcb5a745e462dd5624d63 /pluma/pluma-document.c
parent49be92055f3f3319b9149b991d5b55a5ba99d453 (diff)
downloadpluma-206d27c66761cedebec8bedcaa91bf9f08846095.tar.bz2
pluma-206d27c66761cedebec8bedcaa91bf9f08846095.tar.xz
Implemented regexp finding
Diffstat (limited to 'pluma/pluma-document.c')
-rw-r--r--pluma/pluma-document.c165
1 files changed, 94 insertions, 71 deletions
diff --git a/pluma/pluma-document.c b/pluma/pluma-document.c
index 85890566..43abf989 100644
--- a/pluma/pluma-document.c
+++ b/pluma/pluma-document.c
@@ -1919,12 +1919,23 @@ pluma_document_search_forward (PlumaDocument *doc,
while (!found)
{
- found = gtk_text_iter_forward_search (&iter,
- doc->priv->search_text,
- search_flags,
- &m_start,
- &m_end,
- end);
+ if(!PLUMA_SEARCH_IS_MATCH_REGEX(doc->priv->search_flags))
+ {
+ found = gtk_text_iter_forward_search (&iter,
+ doc->priv->search_text,
+ search_flags,
+ &m_start,
+ &m_end,
+ end);
+ }else{
+ found = pluma_gtk_text_iter_regex_search (&iter,
+ doc->priv->search_text,
+ search_flags,
+ &m_start,
+ &m_end,
+ end,
+ TRUE);
+ }
if (found && PLUMA_SEARCH_IS_ENTIRE_WORD (doc->priv->search_flags))
{
@@ -1957,71 +1968,83 @@ pluma_document_search_forward (PlumaDocument *doc,
**/
gboolean
pluma_document_search_backward (PlumaDocument *doc,
- const GtkTextIter *start,
- const GtkTextIter *end,
- GtkTextIter *match_start,
- GtkTextIter *match_end)
-{
- GtkTextIter iter;
- GtkTextSearchFlags search_flags;
- gboolean found = FALSE;
- GtkTextIter m_start;
- GtkTextIter m_end;
-
- g_return_val_if_fail (PLUMA_IS_DOCUMENT (doc), FALSE);
- g_return_val_if_fail ((start == NULL) ||
- (gtk_text_iter_get_buffer (start) == GTK_TEXT_BUFFER (doc)), FALSE);
- g_return_val_if_fail ((end == NULL) ||
- (gtk_text_iter_get_buffer (end) == GTK_TEXT_BUFFER (doc)), FALSE);
-
- if (doc->priv->search_text == NULL)
- {
- pluma_debug_message (DEBUG_DOCUMENT, "doc->priv->search_text == NULL\n");
- return FALSE;
- }
- else
- pluma_debug_message (DEBUG_DOCUMENT, "doc->priv->search_text == \"%s\"\n", doc->priv->search_text);
-
- if (end == NULL)
- gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (doc), &iter);
- else
- iter = *end;
-
- search_flags = GTK_TEXT_SEARCH_VISIBLE_ONLY | GTK_TEXT_SEARCH_TEXT_ONLY;
-
- if (!PLUMA_SEARCH_IS_CASE_SENSITIVE (doc->priv->search_flags))
- {
- search_flags = search_flags | GTK_TEXT_SEARCH_CASE_INSENSITIVE;
- }
-
- while (!found)
- {
- found = gtk_text_iter_backward_search (&iter,
- doc->priv->search_text,
- search_flags,
- &m_start,
- &m_end,
- start);
-
- if (found && PLUMA_SEARCH_IS_ENTIRE_WORD (doc->priv->search_flags))
- {
- found = gtk_text_iter_starts_word (&m_start) &&
- gtk_text_iter_ends_word (&m_end);
-
- if (!found)
- iter = m_start;
- }
- else
- break;
- }
-
- if (found && (match_start != NULL))
- *match_start = m_start;
-
- if (found && (match_end != NULL))
- *match_end = m_end;
-
- return found;
+ const GtkTextIter *start,
+ const GtkTextIter *end,
+ GtkTextIter *match_start,
+ GtkTextIter *match_end)
+{
+ GtkTextIter iter;
+ GtkTextSearchFlags search_flags;
+ gboolean found = FALSE;
+ GtkTextIter m_start;
+ GtkTextIter m_end;
+
+ g_return_val_if_fail (PLUMA_IS_DOCUMENT (doc), FALSE);
+ g_return_val_if_fail ((start == NULL) ||
+ (gtk_text_iter_get_buffer (start) == GTK_TEXT_BUFFER (doc)), FALSE);
+ g_return_val_if_fail ((end == NULL) ||
+ (gtk_text_iter_get_buffer (end) == GTK_TEXT_BUFFER (doc)), FALSE);
+
+ if (doc->priv->search_text == NULL)
+ {
+ pluma_debug_message (DEBUG_DOCUMENT, "doc->priv->search_text == NULL\n");
+ return FALSE;
+ }
+ else
+ pluma_debug_message (DEBUG_DOCUMENT, "doc->priv->search_text == \"%s\"\n", doc->priv->search_text);
+
+ if (end == NULL)
+ gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (doc), &iter);
+ else
+ iter = *end;
+
+ search_flags = GTK_TEXT_SEARCH_VISIBLE_ONLY | GTK_TEXT_SEARCH_TEXT_ONLY;
+
+ if (!PLUMA_SEARCH_IS_CASE_SENSITIVE (doc->priv->search_flags))
+ {
+ search_flags = search_flags | GTK_TEXT_SEARCH_CASE_INSENSITIVE;
+ }
+
+ while (!found)
+ {
+ if(!PLUMA_SEARCH_IS_MATCH_REGEX(doc->priv->search_flags))
+ {
+ found = gtk_text_iter_backward_search (&iter,
+ doc->priv->search_text,
+ search_flags,
+ &m_start,
+ &m_end,
+ start);
+ }
+ else{
+ found = pluma_gtk_text_iter_regex_search (&iter,
+ doc->priv->search_text,
+ search_flags,
+ &m_start,
+ &m_end,
+ end,
+ FALSE);
+ }
+
+ if (found && PLUMA_SEARCH_IS_ENTIRE_WORD (doc->priv->search_flags))
+ {
+ found = gtk_text_iter_starts_word (&m_start) &&
+ gtk_text_iter_ends_word (&m_end);
+
+ if (!found)
+ iter = m_start;
+ }
+ else
+ break;
+ }
+
+ if (found && (match_start != NULL))
+ *match_start = m_start;
+
+ if (found && (match_end != NULL))
+ *match_end = m_end;
+
+ return found;
}
/* FIXME this is an issue for introspection regardning @find */