gtkcsslocation.c 2.41 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/* 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
Matthias Clasen's avatar
Matthias Clasen committed
26
27
 * @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.
28
 * @line_bytes: Number of bytes parsed since the last line break
Matthias Clasen's avatar
Matthias Clasen committed
29
 * @line_chars: Number of characters parsed since the last line break
30
 *
Matthias Clasen's avatar
Matthias Clasen committed
31
32
33
 * Represents a location in a file or other source of data parsed
 * by the CSS engine.
 *
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
 * 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;
}