[gtksourceview] SpaceDrawer: improve space_needs_drawing() readability
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview] SpaceDrawer: improve space_needs_drawing() readability
- Date: Fri, 22 Jul 2016 21:52:33 +0000 (UTC)
commit 2d295d75175ef446ace0abf8b5bf2962e9d7559f
Author: Sébastien Wilmet <swilmet gnome org>
Date: Fri Jul 22 23:48:47 2016 +0200
SpaceDrawer: improve space_needs_drawing() readability
gtksourceview/gtksourcespacedrawer.c | 82 +++++++++++++++++----------------
1 files changed, 42 insertions(+), 40 deletions(-)
---
diff --git a/gtksourceview/gtksourcespacedrawer.c b/gtksourceview/gtksourcespacedrawer.c
index 9fb053f..9eb68ae 100644
--- a/gtksourceview/gtksourcespacedrawer.c
+++ b/gtksourceview/gtksourcespacedrawer.c
@@ -396,53 +396,68 @@ space_needs_drawing_according_to_tag (const GtkTextIter *iter,
}
static gboolean
-check_location (GtkSourceSpaceDrawer *drawer,
- const GtkTextIter *iter,
- const GtkTextIter *leading,
- const GtkTextIter *trailing)
+space_needs_drawing_according_to_location (GtkSourceSpaceDrawer *drawer,
+ const GtkTextIter *iter,
+ const GtkTextIter *leading_end,
+ const GtkTextIter *trailing_start)
{
- gint flags = 0;
- gint location = drawer->priv->flags & (GTK_SOURCE_DRAW_SPACES_LEADING |
- GTK_SOURCE_DRAW_SPACES_TEXT |
- GTK_SOURCE_DRAW_SPACES_TRAILING);
+ gint iter_locations = 0;
+ gint allowed_locations = drawer->priv->flags & (GTK_SOURCE_DRAW_SPACES_LEADING |
+ GTK_SOURCE_DRAW_SPACES_TEXT |
+ GTK_SOURCE_DRAW_SPACES_TRAILING);
/* Draw all by default */
- if (location == 0)
+ if (allowed_locations == 0)
{
return TRUE;
}
- if (gtk_text_iter_compare (iter, trailing) >= 0)
+ if (gtk_text_iter_compare (iter, leading_end) < 0)
{
- flags |= GTK_SOURCE_DRAW_SPACES_TRAILING;
+ iter_locations |= GTK_SOURCE_DRAW_SPACES_LEADING;
}
- if (gtk_text_iter_compare (iter, leading) < 0)
+ if (gtk_text_iter_compare (trailing_start, iter) <= 0)
{
- flags |= GTK_SOURCE_DRAW_SPACES_LEADING;
+ iter_locations |= GTK_SOURCE_DRAW_SPACES_TRAILING;
}
- if (flags == 0)
+ /* Neither leading nor trailing, must be in text */
+ if (iter_locations == 0)
{
- /* Neither leading nor trailing, must be in text */
- return location & GTK_SOURCE_DRAW_SPACES_TEXT;
- }
- else
- {
- return location & flags;
+ iter_locations = GTK_SOURCE_DRAW_SPACES_TEXT;
}
+
+ return (iter_locations & allowed_locations) != 0;
+}
+
+static gboolean
+space_needs_drawing_according_to_whitespace_type (GtkSourceSpaceDrawer *drawer,
+ const GtkTextIter *iter)
+{
+ gint flags;
+ gunichar c;
+
+ flags = drawer->priv->flags;
+ c = gtk_text_iter_get_char (iter);
+
+ return ((flags & GTK_SOURCE_DRAW_SPACES_TAB && c == '\t') ||
+ (flags & GTK_SOURCE_DRAW_SPACES_NBSP &&
+ g_unichar_break_type (c) == G_UNICODE_BREAK_NON_BREAKING_GLUE) ||
+ (flags & GTK_SOURCE_DRAW_SPACES_SPACE &&
+ g_unichar_type (c) == G_UNICODE_SPACE_SEPARATOR) ||
+ (flags & GTK_SOURCE_DRAW_SPACES_NEWLINE &&
+ gtk_text_iter_ends_line (iter) && !gtk_text_iter_is_end (iter)));
}
static gboolean
space_needs_drawing (GtkSourceSpaceDrawer *drawer,
const GtkTextIter *iter,
- const GtkTextIter *leading,
- const GtkTextIter *trailing)
+ const GtkTextIter *leading_end,
+ const GtkTextIter *trailing_start)
{
gboolean has_tag;
gboolean needs_drawing;
- gint flags;
- gunichar c;
/* Check the GtkSourceTag:draw-spaces property */
@@ -452,23 +467,10 @@ space_needs_drawing (GtkSourceSpaceDrawer *drawer,
return needs_drawing;
}
- /* Check the GtkSourceView:draw-spaces property */
-
- if (!check_location (drawer, iter, leading, trailing))
- {
- return FALSE;
- }
-
- flags = drawer->priv->flags;
- c = gtk_text_iter_get_char (iter);
+ /* Check the flags */
- return ((flags & GTK_SOURCE_DRAW_SPACES_TAB && c == '\t') ||
- (flags & GTK_SOURCE_DRAW_SPACES_NBSP &&
- g_unichar_break_type (c) == G_UNICODE_BREAK_NON_BREAKING_GLUE) ||
- (flags & GTK_SOURCE_DRAW_SPACES_SPACE &&
- g_unichar_type (c) == G_UNICODE_SPACE_SEPARATOR) ||
- (flags & GTK_SOURCE_DRAW_SPACES_NEWLINE &&
- gtk_text_iter_ends_line (iter) && !gtk_text_iter_is_end (iter)));
+ return (space_needs_drawing_according_to_location (drawer, iter, leading_end, trailing_start) &&
+ space_needs_drawing_according_to_whitespace_type (drawer, iter));
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]