[gtk] css: Split GtkCssLocation into its own file
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk] css: Split GtkCssLocation into its own file
- Date: Fri, 12 Apr 2019 17:35:29 +0000 (UTC)
commit 32e256e5abaa359ddb2a533e09921511ccc5d285
Author: Benjamin Otte <otte redhat com>
Date: Sat Mar 23 03:27:56 2019 +0100
css: Split GtkCssLocation into its own file
And make the struct public, so we can use it in signal handlers.
docs/reference/gtk/gtk4-sections.txt | 1 +
gtk/css/gtkcss.h | 1 +
gtk/css/gtkcsslocation.c | 74 ++++++++++++++++++++++++++++++++++++
gtk/css/gtkcsslocation.h | 43 +++++++++++++++++++++
gtk/css/gtkcsslocationprivate.h | 39 +++++++++++++++++++
gtk/css/gtkcsstokenizer.c | 30 +--------------
gtk/css/gtkcsstokenizerprivate.h | 12 +-----
gtk/css/meson.build | 2 +
8 files changed, 163 insertions(+), 39 deletions(-)
---
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index 460f053d2f..28d7819b09 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -5090,6 +5090,7 @@ GTK_CSS_PARSER_ERROR
GtkCssParserError
GtkCssParserWarning
<SUBSECTION>
+GtkCssLocation
GtkCssSection
GtkCssSectionType
gtk_css_section_get_end_line
diff --git a/gtk/css/gtkcss.h b/gtk/css/gtkcss.h
index c68e6a45fe..343244c2c3 100644
--- a/gtk/css/gtkcss.h
+++ b/gtk/css/gtkcss.h
@@ -33,6 +33,7 @@
#include <gtk/css/gtkcssenums.h>
#include <gtk/css/gtkcssenumtypes.h>
#include <gtk/css/gtkcsserror.h>
+#include <gtk/css/gtkcsslocation.h>
#undef __GTK_CSS_H_INSIDE__
diff --git a/gtk/css/gtkcsslocation.c b/gtk/css/gtkcsslocation.c
new file mode 100644
index 0000000000..4f47501b0b
--- /dev/null
+++ b/gtk/css/gtkcsslocation.c
@@ -0,0 +1,74 @@
+/* GSK - The GIMP Toolkit
+ * Copyright (C) 2019 Benjamin Otte <otte gnome org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include "gtkcsslocationprivate.h"
+
+/**
+ * GtkCssLocation:
+ * @bytes: number of bytes parsed since the beginning
+ * @chars: number of characters parsed since the beginning
+ * @lines: number of full lines that have been parsed
+ * If you want to display this as a line number, you
+ * need to add 1 to this.
+ * @line_bytes: Number of bytes parsed since the last line break
+ * @line_chars: Number of characters parsed since the last line
+ * break
+ *
+ * @GtkCssLocation is used to present a location in a file - or other
+ * source of data parsed by the CSS engine.
+ *
+ * The @bytes and @line_bytes offsets are meant to be used to
+ * programmatically match data. The @lines and @line_chars offsets
+ * can be used for printing the location in a file.
+ *
+ * Note that the @lines parameter starts from 0 and is increased
+ * whenever a CSS line break is encountered. (CSS defines the C character
+ * sequences "\r\n", "\r", "\n" and "\f" as newlines.)
+ * If your document uses different rules for line breaking, you might want
+ * run into problems here.
+ */
+
+void
+gtk_css_location_init (GtkCssLocation *location)
+{
+ memset (location, 0, sizeof (GtkCssLocation));
+}
+
+void
+gtk_css_location_advance (GtkCssLocation *location,
+ gsize bytes,
+ gsize chars)
+{
+ location->bytes += bytes;
+ location->chars += chars;
+ location->line_bytes += bytes;
+ location->line_chars += chars;
+}
+
+void
+gtk_css_location_advance_newline (GtkCssLocation *location,
+ gboolean is_windows)
+{
+ gtk_css_location_advance (location, is_windows ? 2 : 1, is_windows ? 2 : 1);
+
+ location->lines++;
+ location->line_bytes = 0;
+ location->line_chars = 0;
+}
+
diff --git a/gtk/css/gtkcsslocation.h b/gtk/css/gtkcsslocation.h
new file mode 100644
index 0000000000..f1ea3db50f
--- /dev/null
+++ b/gtk/css/gtkcsslocation.h
@@ -0,0 +1,43 @@
+/* GSK - The GIMP Toolkit
+ * Copyright (C) 2011 Benjamin Otte <otte gnome org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GTK_CSS_LOCATION_H__
+#define __GTK_CSS_LOCATION_H__
+
+#if !defined (__GTK_CSS_H_INSIDE__) && !defined (GTK_CSS_COMPILATION)
+#error "Only <gtk/css/gtkcss.h> can be included directly."
+#endif
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+typedef struct _GtkCssLocation GtkCssLocation;
+
+struct _GtkCssLocation
+{
+ gsize bytes;
+ gsize chars;
+ gsize lines;
+ gsize line_bytes;
+ gsize line_chars;
+};
+
+
+G_END_DECLS
+
+#endif /* __GTK_CSS_LOCATION_H__ */
diff --git a/gtk/css/gtkcsslocationprivate.h b/gtk/css/gtkcsslocationprivate.h
new file mode 100644
index 0000000000..46ed3c8056
--- /dev/null
+++ b/gtk/css/gtkcsslocationprivate.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright © 2019 Benjamin Otte
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Benjamin Otte <otte gnome org>
+ */
+
+
+#ifndef __GTK_CSS_LOCATION_PRIVATE_H__
+#define __GTK_CSS_LOCATION_PRIVATE_H__
+
+#include "gtkcsslocation.h"
+
+G_BEGIN_DECLS
+
+void gtk_css_location_init (GtkCssLocation *location);
+
+void gtk_css_location_advance (GtkCssLocation *location,
+ gsize bytes,
+ gsize chars);
+void gtk_css_location_advance_newline (GtkCssLocation *location,
+ gboolean is_windows);
+
+G_END_DECLS
+
+#endif /* __GTK_CSS_LOCATION_PRIVATE_H__ */
+
diff --git a/gtk/css/gtkcsstokenizer.c b/gtk/css/gtkcsstokenizer.c
index 57cf6339a8..b956c86504 100644
--- a/gtk/css/gtkcsstokenizer.c
+++ b/gtk/css/gtkcsstokenizer.c
@@ -19,9 +19,9 @@
#include "gtkcsstokenizerprivate.h"
-/* for error enum */
#include "gtkcssenums.h"
#include "gtkcsserror.h"
+#include "gtkcsslocationprivate.h"
#include <math.h>
#include <string.h>
@@ -37,34 +37,6 @@ struct _GtkCssTokenizer
GtkCssLocation position;
};
-static void
-gtk_css_location_init (GtkCssLocation *location)
-{
- memset (location, 0, sizeof (GtkCssLocation));
-}
-
-static void
-gtk_css_location_advance (GtkCssLocation *location,
- gsize bytes,
- gsize chars)
-{
- location->bytes += bytes;
- location->chars += chars;
- location->line_bytes += bytes;
- location->line_chars += chars;
-}
-
-static void
-gtk_css_location_advance_newline (GtkCssLocation *location,
- gboolean is_windows)
-{
- gtk_css_location_advance (location, is_windows ? 2 : 1, is_windows ? 2 : 1);
-
- location->lines++;
- location->line_bytes = 0;
- location->line_chars = 0;
-}
-
void
gtk_css_token_clear (GtkCssToken *token)
{
diff --git a/gtk/css/gtkcsstokenizerprivate.h b/gtk/css/gtkcsstokenizerprivate.h
index 6adb492d37..8119da28e9 100644
--- a/gtk/css/gtkcsstokenizerprivate.h
+++ b/gtk/css/gtkcsstokenizerprivate.h
@@ -20,6 +20,8 @@
#include <glib.h>
+#include <gtk/css/gtkcsslocation.h>
+
G_BEGIN_DECLS
typedef enum {
@@ -70,7 +72,6 @@ typedef enum {
typedef union _GtkCssToken GtkCssToken;
typedef struct _GtkCssTokenizer GtkCssTokenizer;
-typedef struct _GtkCssLocation GtkCssLocation;
typedef struct _GtkCssStringToken GtkCssStringToken;
typedef struct _GtkCssDelimToken GtkCssDelimToken;
@@ -106,15 +107,6 @@ union _GtkCssToken {
GtkCssDimensionToken dimension;
};
-struct _GtkCssLocation
-{
- gsize bytes;
- gsize chars;
- gsize lines;
- gsize line_bytes;
- gsize line_chars;
-};
-
void gtk_css_token_clear (GtkCssToken *token);
gboolean gtk_css_token_is_finite (const GtkCssToken *token);
diff --git a/gtk/css/meson.build b/gtk/css/meson.build
index 135b3a41fc..0dda25f6aa 100644
--- a/gtk/css/meson.build
+++ b/gtk/css/meson.build
@@ -1,4 +1,5 @@
gtk_css_public_sources = files([
+ 'gtkcsslocation.c',
'gtkcsserror.c',
])
@@ -9,6 +10,7 @@ gtk_css_private_sources = files([
gtk_css_public_headers = files([
'gtkcssenums.h',
'gtkcsserror.h',
+ 'gtkcsslocation.h',
])
install_headers(gtk_css_public_headers, 'gtkcss.h', subdir: 'gtk-4.0/gtk/css')
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]