[gnome-builder] vim-iter: add *_find_char with acces to the iter
- From: Sébastien Lafargue <slafargue src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] vim-iter: add *_find_char with acces to the iter
- Date: Thu, 5 Nov 2015 23:31:58 +0000 (UTC)
commit e26b042ee8e3c07d9b2725b7ffcece41d26444de
Author: Sebastien Lafargue <slafargue gnome org>
Date: Sat Oct 24 22:45:40 2015 +0200
vim-iter: add *_find_char with acces to the iter
libide/ide-vim-iter.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++
libide/ide-vim-iter.h | 30 +++++++++++++++-------
2 files changed, 86 insertions(+), 10 deletions(-)
---
diff --git a/libide/ide-vim-iter.c b/libide/ide-vim-iter.c
index d03b829..69547e9 100644
--- a/libide/ide-vim-iter.c
+++ b/libide/ide-vim-iter.c
@@ -455,3 +455,69 @@ _ide_vim_iter_backward_WORD_end (GtkTextIter *iter)
{
return _ide_vim_iter_backward_classified_end (iter, _ide_vim_WORD_classify);
}
+
+static gboolean
+matches_pred (GtkTextIter *iter,
+ VimIterCharPredicate pred,
+ gpointer user_data)
+{
+ gint ch;
+
+ ch = gtk_text_iter_get_char (iter);
+
+ return (*pred) (iter, ch, user_data);
+}
+
+/* Similar to gtk_text_iter_forward_find_char but
+ * lets us acces to the iter in the predicate
+ */
+gboolean
+_ide_vim_iter_forward_find_char (GtkTextIter *iter,
+ VimIterCharPredicate pred,
+ gpointer user_data,
+ const GtkTextIter *limit)
+{
+ g_return_val_if_fail (iter != NULL, FALSE);
+ g_return_val_if_fail (pred != NULL, FALSE);
+
+ if (limit &&
+ gtk_text_iter_compare (iter, limit) >= 0)
+ return FALSE;
+
+ while ((limit == NULL ||
+ !gtk_text_iter_equal (limit, iter)) &&
+ gtk_text_iter_forward_char (iter))
+ {
+ if (matches_pred (iter, pred, user_data))
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+/* Similar to gtk_text_iter_backward_find_char but
+ * lets us acces to the iter in the predicate
+ */
+gboolean
+_ide_vim_iter_backward_find_char (GtkTextIter *iter,
+ VimIterCharPredicate pred,
+ gpointer user_data,
+ const GtkTextIter *limit)
+{
+ g_return_val_if_fail (iter != NULL, FALSE);
+ g_return_val_if_fail (pred != NULL, FALSE);
+
+ if (limit &&
+ gtk_text_iter_compare (iter, limit) <= 0)
+ return FALSE;
+
+ while ((limit == NULL ||
+ !gtk_text_iter_equal (limit, iter)) &&
+ gtk_text_iter_backward_char (iter))
+ {
+ if (matches_pred (iter, pred, user_data))
+ return TRUE;
+ }
+
+ return FALSE;
+}
diff --git a/libide/ide-vim-iter.h b/libide/ide-vim-iter.h
index 3777238..735a21c 100644
--- a/libide/ide-vim-iter.h
+++ b/libide/ide-vim-iter.h
@@ -23,16 +23,26 @@
G_BEGIN_DECLS
-gboolean _ide_vim_iter_forward_word_start (GtkTextIter *iter);
-gboolean _ide_vim_iter_forward_WORD_start (GtkTextIter *iter);
-gboolean _ide_vim_iter_forward_word_end (GtkTextIter *iter);
-gboolean _ide_vim_iter_forward_WORD_end (GtkTextIter *iter);
-gboolean _ide_vim_iter_backward_paragraph_start (GtkTextIter *iter);
-gboolean _ide_vim_iter_forward_paragraph_end (GtkTextIter *iter);
-gboolean _ide_vim_iter_backward_sentence_start (GtkTextIter *iter);
-gboolean _ide_vim_iter_forward_sentence_end (GtkTextIter *iter);
-gboolean _ide_vim_iter_backward_WORD_end (GtkTextIter *iter);
-gboolean _ide_vim_iter_backward_word_end (GtkTextIter *iter);
+typedef gboolean (* VimIterCharPredicate) (GtkTextIter *iter, gunichar ch, gpointer user_data);
+
+gboolean _ide_vim_iter_forward_find_char (GtkTextIter *iter,
+ VimIterCharPredicate pred,
+ gpointer user_data,
+ const GtkTextIter *limit);
+gboolean _ide_vim_iter_backward_find_char (GtkTextIter *iter,
+ VimIterCharPredicate pred,
+ gpointer user_data,
+ const GtkTextIter *limit);
+gboolean _ide_vim_iter_forward_word_start (GtkTextIter *iter);
+gboolean _ide_vim_iter_forward_WORD_start (GtkTextIter *iter);
+gboolean _ide_vim_iter_forward_word_end (GtkTextIter *iter);
+gboolean _ide_vim_iter_forward_WORD_end (GtkTextIter *iter);
+gboolean _ide_vim_iter_backward_paragraph_start (GtkTextIter *iter);
+gboolean _ide_vim_iter_forward_paragraph_end (GtkTextIter *iter);
+gboolean _ide_vim_iter_backward_sentence_start (GtkTextIter *iter);
+gboolean _ide_vim_iter_forward_sentence_end (GtkTextIter *iter);
+gboolean _ide_vim_iter_backward_WORD_end (GtkTextIter *iter);
+gboolean _ide_vim_iter_backward_word_end (GtkTextIter *iter);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]