1 | /* GSK - The GIMP Toolkit |
2 | * Copyright (C) 2019 Benjamin Otte <otte@gnome.org> |
3 | * |
4 | * This library is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU Lesser General Public |
6 | * License as published by the Free Software Foundation; either |
7 | * version 2 of the License, or (at your option) any later version. |
8 | * |
9 | * This library is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | * Lesser General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU Lesser General Public |
15 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. |
16 | */ |
17 | |
18 | #include "config.h" |
19 | |
20 | #include "gtkcsslocationprivate.h" |
21 | |
22 | /** |
23 | * GtkCssLocation: |
24 | * @bytes: number of bytes parsed since the beginning |
25 | * @chars: number of characters parsed since the beginning |
26 | * @lines: number of full lines that have been parsed. If you want to |
27 | * display this as a line number, you need to add 1 to this. |
28 | * @line_bytes: Number of bytes parsed since the last line break |
29 | * @line_chars: Number of characters parsed since the last line break |
30 | * |
31 | * Represents a location in a file or other source of data parsed |
32 | * by the CSS engine. |
33 | * |
34 | * The @bytes and @line_bytes offsets are meant to be used to |
35 | * programmatically match data. The @lines and @line_chars offsets |
36 | * can be used for printing the location in a file. |
37 | * |
38 | * Note that the @lines parameter starts from 0 and is increased |
39 | * whenever a CSS line break is encountered. (CSS defines the C character |
40 | * sequences "\r\n", "\r", "\n" and "\f" as newlines.) |
41 | * If your document uses different rules for line breaking, you might want |
42 | * run into problems here. |
43 | */ |
44 | |
45 | void |
46 | gtk_css_location_init (GtkCssLocation *location) |
47 | { |
48 | memset (s: location, c: 0, n: sizeof (GtkCssLocation)); |
49 | } |
50 | |
51 | void |
52 | gtk_css_location_advance (GtkCssLocation *location, |
53 | gsize bytes, |
54 | gsize chars) |
55 | { |
56 | location->bytes += bytes; |
57 | location->chars += chars; |
58 | location->line_bytes += bytes; |
59 | location->line_chars += chars; |
60 | } |
61 | |
62 | void |
63 | gtk_css_location_advance_newline (GtkCssLocation *location, |
64 | gboolean is_windows) |
65 | { |
66 | gtk_css_location_advance (location, bytes: is_windows ? 2 : 1, chars: is_windows ? 2 : 1); |
67 | |
68 | location->lines++; |
69 | location->line_bytes = 0; |
70 | location->line_chars = 0; |
71 | } |
72 | |
73 | |