[gnome-builder] auto-indent: improve goto label detection.
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] auto-indent: improve goto label detection.
- Date: Fri, 26 Sep 2014 09:20:54 +0000 (UTC)
commit 2dc49e528753de74d67d2b1a006892c1050a1c7c
Author: Christian Hergert <christian hergert me>
Date: Fri Sep 26 02:20:44 2014 -0700
auto-indent: improve goto label detection.
src/editor/gb-source-auto-indenter-c.c | 58 ++++++++++++++-----------------
1 files changed, 26 insertions(+), 32 deletions(-)
---
diff --git a/src/editor/gb-source-auto-indenter-c.c b/src/editor/gb-source-auto-indenter-c.c
index dabb987..1977c62 100644
--- a/src/editor/gb-source-auto-indenter-c.c
+++ b/src/editor/gb-source-auto-indenter-c.c
@@ -965,42 +965,38 @@ line_is_case (const GtkTextIter *line)
static gboolean
line_is_label (const GtkTextIter *line)
{
- GtkTextIter iter;
- gboolean found_char = FALSE;
- gboolean found_colon = FALSE;
+ GtkTextIter begin;
+ GtkTextIter end;
+ gchar *text;
+ gchar **parts;
+ guint i;
+ guint count = 0;
- gtk_text_iter_assign (&iter, line);
+ gtk_text_iter_assign (&begin, line);
+ while (!gtk_text_iter_starts_line (&begin))
+ if (!gtk_text_iter_backward_char (&begin))
+ return FALSE;
- while (!gtk_text_iter_starts_line (&iter))
- {
- gunichar ch;
+ gtk_text_iter_assign (&end, line);
+ while (!gtk_text_iter_ends_line (&end))
+ if (!gtk_text_iter_forward_char (&end))
+ return FALSE;
- ch = gtk_text_iter_get_char (&iter);
+ text = gtk_text_iter_get_slice (&begin, &end);
+ g_strdelimit (text, "\t", ' ');
+ parts = g_strsplit (text, " ", 0);
- switch (ch)
- {
- case ' ':
- break;
- case ':':
- found_colon = TRUE;
- break;
- case '_':
- found_char = TRUE;
- break;
- default:
- if (g_unichar_isalnum (ch))
- {
- found_char = TRUE;
- break;
- }
- return FALSE;
- }
-
- if (!gtk_text_iter_backward_char (&iter))
- return FALSE;
+ for (i = 0; parts [i]; i++)
+ {
+ g_strstrip (parts [i]);
+ if (*parts [i] && (g_strcmp0 (parts [i], ":") != 0))
+ count++;
}
- return (found_char && found_colon);
+ g_free (text);
+ g_strfreev (parts);
+
+ return (count == 1);
}
static gchar *
@@ -1023,8 +1019,6 @@ maybe_unindent_case_label (GbSourceAutoIndenterC *c,
if (line_is_case (&iter))
{
- TODO ("Implement unindent for case");
-
if (backward_find_matching_char (&iter, '}'))
{
if (line_is_whitespace_until (&iter))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]