[gnome-builder/gnome-builder-3-20] language: add language helper to generate license headers
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/gnome-builder-3-20] language: add language helper to generate license headers
- Date: Sat, 14 May 2016 12:48:48 +0000 (UTC)
commit adb7edeccba467c5f29eb148f8857ad480a65871
Author: Christian Hergert <chergert redhat com>
Date: Sat May 14 15:36:17 2016 +0300
language: add language helper to generate license headers
This can be used to add the comments to a text blurb for a license header.
Generally you'll want to pair this with a template include.
libide/Makefile.am | 2 +
libide/ide-language.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++++
libide/ide-language.h | 31 +++++++++++++++
libide/ide.h | 1 +
4 files changed, 135 insertions(+), 0 deletions(-)
---
diff --git a/libide/Makefile.am b/libide/Makefile.am
index 6ada4d8..03c9295 100644
--- a/libide/Makefile.am
+++ b/libide/Makefile.am
@@ -69,6 +69,7 @@ libide_1_0_la_public_headers = \
ide-highlighter.h \
ide-indent-style.h \
ide-indenter.h \
+ ide-language.h \
ide-layout-grid.h \
ide-layout-pane.h \
ide-layout-stack-split.h \
@@ -226,6 +227,7 @@ libide_1_0_la_public_sources = \
ide-highlight-index.c \
ide-highlighter.c \
ide-indenter.c \
+ ide-language.c \
ide-layout-grid.c \
ide-layout-pane.c \
ide-layout-stack.c \
diff --git a/libide/ide-language.c b/libide/ide-language.c
new file mode 100644
index 0000000..8459eac
--- /dev/null
+++ b/libide/ide-language.c
@@ -0,0 +1,101 @@
+/* ide-language.c
+ *
+ * Copyright (C) 2016 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#define G_LOG_DOMAIN "ide-language"
+
+#include <string.h>
+#include <tmpl-glib.h>
+
+#include "ide-language.h"
+#include "ide-line-reader.h"
+
+gchar *
+ide_language_format_header (GtkSourceLanguage *self,
+ const gchar *header)
+{
+ IdeLineReader reader;
+ const gchar *first_prefix;
+ const gchar *last_prefix;
+ const gchar *line_prefix;
+ const gchar *line;
+ gboolean first = TRUE;
+ GString *outstr;
+ gsize len;
+ guint prefix_len;
+
+ g_return_val_if_fail (GTK_SOURCE_IS_LANGUAGE (self), NULL);
+ g_return_val_if_fail (header != NULL, NULL);
+
+ first_prefix = gtk_source_language_get_metadata (self, "block-comment-start");
+ last_prefix = gtk_source_language_get_metadata (self, "block-comment-end");
+ line_prefix = gtk_source_language_get_metadata (self, "line-comment-start");
+
+ if ((g_strcmp0 (first_prefix, "/*") == 0) &&
+ (g_strcmp0 (last_prefix, "*/") == 0))
+ line_prefix = " *";
+
+ if (first_prefix == NULL || last_prefix == NULL)
+ {
+ first_prefix = line_prefix;
+ last_prefix = line_prefix;
+ }
+
+ prefix_len = strlen (first_prefix);
+
+ outstr = g_string_new (NULL);
+
+ ide_line_reader_init (&reader, (gchar *)header, -1);
+
+ while (NULL != (line = ide_line_reader_next (&reader, &len)))
+ {
+ if (first)
+ {
+ g_string_append (outstr, first_prefix);
+ first = FALSE;
+ }
+ else if (line_prefix == NULL)
+ {
+ guint i;
+
+ for (i = 0; i < prefix_len; i++)
+ g_string_append_c (outstr, ' ');
+ }
+ else
+ {
+ g_string_append (outstr, line_prefix);
+ }
+
+ if (len)
+ {
+ g_string_append_c (outstr, ' ');
+ g_string_append_len (outstr, line, len);
+ }
+
+ g_string_append_c (outstr, '\n');
+ }
+
+ if (last_prefix && g_strcmp0 (first_prefix, last_prefix) != 0)
+ {
+ if (line_prefix && *line_prefix == ' ')
+ g_string_append_c (outstr, ' ');
+ g_string_append (outstr, last_prefix);
+ g_string_append_c (outstr, '\n');
+ }
+
+ return g_string_free (outstr, FALSE);
+}
diff --git a/libide/ide-language.h b/libide/ide-language.h
new file mode 100644
index 0000000..aace6e1
--- /dev/null
+++ b/libide/ide-language.h
@@ -0,0 +1,31 @@
+/* ide-language.h
+ *
+ * Copyright (C) 2016 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef IDE_LANGUAGE_H
+#define IDE_LANGUAGE_H
+
+#include <gtksourceview/gtksourcelanguage.h>
+
+G_BEGIN_DECLS
+
+gchar *ide_language_format_header (GtkSourceLanguage *language,
+ const gchar *header);
+
+G_END_DECLS
+
+#endif /* IDE_LANGUAGE_H */
diff --git a/libide/ide.h b/libide/ide.h
index caafa11..f12f897 100644
--- a/libide/ide.h
+++ b/libide/ide.h
@@ -67,6 +67,7 @@ G_BEGIN_DECLS
#include "ide-highlight-engine.h"
#include "ide-highlighter.h"
#include "ide-indenter.h"
+#include "ide-language.h"
#include "ide-layout-grid.h"
#include "ide-layout-pane.h"
#include "ide-layout-stack.h"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]