[gtksourceview] buffer: make code a bit clearer for the context class mask
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview] buffer: make code a bit clearer for the context class mask
- Date: Fri, 16 Oct 2015 14:17:32 +0000 (UTC)
commit 74f898d8e18224872885b647cd6439cb1dc87fb7
Author: Sébastien Wilmet <swilmet gnome org>
Date: Fri Oct 16 11:36:18 2015 +0200
buffer: make code a bit clearer for the context class mask
- Move the variable inside the function, so there is one less global
variable.
- Use G_N_ELEMENTS().
- Better function and variable names.
gtksourceview/gtksourcebuffer.c | 40 ++++++++++++++++++++------------------
1 files changed, 21 insertions(+), 19 deletions(-)
---
diff --git a/gtksourceview/gtksourcebuffer.c b/gtksourceview/gtksourcebuffer.c
index 354c1ed..a46799a 100644
--- a/gtksourceview/gtksourcebuffer.c
+++ b/gtksourceview/gtksourcebuffer.c
@@ -1144,31 +1144,33 @@ gtk_source_buffer_real_delete_range (GtkTextBuffer *buffer,
}
}
-/* This describes a mask of relevant context classes for highlighting matching
- * brackets. Additional classes can be added below.
- */
-static const gchar *cclass_mask_definitions[] = {
- "comment",
- "string",
-};
-
static gint
-get_context_class_mask (GtkSourceBuffer *buffer,
- GtkTextIter *iter)
+get_bracket_matching_context_class_mask (GtkSourceBuffer *buffer,
+ GtkTextIter *iter)
{
+ gint mask = 0;
guint i;
- gint ret = 0;
- for (i = 0; i < sizeof (cclass_mask_definitions) / sizeof (gchar *); ++i)
+ /* This describes a mask of relevant context classes for highlighting
+ * matching brackets.
+ */
+ const gchar *cclass_mask_definitions[] = {
+ "comment",
+ "string",
+ };
+
+ for (i = 0; i < G_N_ELEMENTS (cclass_mask_definitions); ++i)
{
- gboolean hasclass = gtk_source_buffer_iter_has_context_class (buffer,
- iter,
- cclass_mask_definitions[i]);
+ gboolean has_class;
+
+ has_class = gtk_source_buffer_iter_has_context_class (buffer,
+ iter,
+ cclass_mask_definitions[i]);
- ret |= hasclass << i;
+ mask |= has_class << i;
}
- return ret;
+ return mask;
}
/* Note that we only look MAX_CHARS_BEFORE_FINDING_A_MATCH at most. */
@@ -1194,7 +1196,7 @@ gtk_source_buffer_find_bracket_match_real (GtkSourceBuffer *buffer,
cur_char = gtk_text_iter_get_char (&iter);
base_char = cur_char;
- cclass_mask = get_context_class_mask (buffer, &iter);
+ cclass_mask = get_bracket_matching_context_class_mask (buffer, &iter);
search_char = bracket_pair (base_char, &addition);
@@ -1215,7 +1217,7 @@ gtk_source_buffer_find_bracket_match_real (GtkSourceBuffer *buffer,
cur_char = gtk_text_iter_get_char (&iter);
++char_cont;
- current_mask = get_context_class_mask (buffer, &iter);
+ current_mask = get_bracket_matching_context_class_mask (buffer, &iter);
/* Check if we lost a class, which means we don't look any
further */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]