[tracker: 1/3] tracker-turtle-reader: add support for comments inside triple patterns




commit 6e990629f83c2bf9e058051d3236fd8620dd4bc3
Author: Abanoub Ghadban <abanoub gdb gmail com>
Date:   Tue Jun 22 12:28:22 2021 +0200

    tracker-turtle-reader: add support for comments inside triple patterns
    
    Fixes the crash that happens when the ontology file contains comments at the middle a triple pattern.
    Before this commit, tracker only supports comments at the beginning or end of the triple pattern (either 
before the subject or after the dot).
    This commit consider comments the same as white spaces, can appear anywhere in the ontology file outside 
the string or IRIREF.
    So, I renamed skip_comments() function to advance_whitespaces_and_comments() and made it call 
advance_whitespaces() before checking for the '#' comment delimiter char.
    advance_whitespaces_and_comments() by default assumes the comment be multilined, so it can skip and 
combination of comments and whitespaces.
    Then, I replaced each call to the skip_whitespaces() by a call to advance_whitespaces_and_comments()
    
    tmp

 src/libtracker-data/tracker-turtle-reader.c | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)
---
diff --git a/src/libtracker-data/tracker-turtle-reader.c b/src/libtracker-data/tracker-turtle-reader.c
index e965d22c0..b5eb4247e 100644
--- a/src/libtracker-data/tracker-turtle-reader.c
+++ b/src/libtracker-data/tracker-turtle-reader.c
@@ -71,6 +71,8 @@ G_DEFINE_TYPE (TrackerTurtleReader,
                tracker_turtle_reader,
                G_TYPE_OBJECT)
 
+static void advance_whitespace_and_comments (TrackerTurtleReader *reader);
+
 static void
 tracker_turtle_reader_finalize (GObject *object)
 {
@@ -386,15 +388,15 @@ handle_prefix (TrackerTurtleReader  *reader,
 {
        gchar *prefix = NULL, *uri = NULL;
 
-       advance_whitespace (reader);
+       advance_whitespace_and_comments(reader);
        if (!parse_terminal (reader, terminal_PNAME_NS, 0, &prefix))
                goto error;
 
-       advance_whitespace (reader);
+       advance_whitespace_and_comments(reader);
        if (!parse_terminal (reader, terminal_IRIREF, 1, &uri))
                goto error;
 
-       advance_whitespace (reader);
+       advance_whitespace_and_comments(reader);
        if (!parse_token (reader, "."))
                goto error;
 
@@ -416,11 +418,11 @@ handle_base (TrackerTurtleReader  *reader,
 {
        gchar *base = NULL;
 
-       advance_whitespace (reader);
+       advance_whitespace_and_comments(reader);
        if (!parse_terminal (reader, terminal_IRIREF, 0, &base))
                goto error;
 
-       advance_whitespace (reader);
+       advance_whitespace_and_comments(reader);
        if (!parse_token (reader, "."))
                goto error;
 
@@ -458,12 +460,13 @@ handle_type_cast (TrackerTurtleReader  *reader,
 }
 
 static void
-skip_comments (TrackerTurtleReader *reader)
+advance_whitespace_and_comments (TrackerTurtleReader *reader)
 {
        const gchar *buffer, *str;
        gsize size;
 
        while (TRUE) {
+               advance_whitespace (reader);
                buffer = g_buffered_input_stream_peek_buffer (reader->buffered_stream,
                                                              &size);
                if (size == 0)
@@ -478,8 +481,6 @@ skip_comments (TrackerTurtleReader *reader)
                if (!g_input_stream_skip (G_INPUT_STREAM (reader->buffered_stream),
                                          str + 1 - buffer, NULL, NULL))
                        break;
-
-               advance_whitespace (reader);
        }
 }
 
@@ -490,7 +491,7 @@ tracker_turtle_reader_iterate_next (TrackerTurtleReader  *reader,
        while (TRUE) {
                gchar *str, *lang;
 
-               advance_whitespace (reader);
+               advance_whitespace_and_comments(reader);
 
                if (g_buffered_input_stream_fill (reader->buffered_stream, -1, NULL, error) < 0)
                        return FALSE;
@@ -500,8 +501,6 @@ tracker_turtle_reader_iterate_next (TrackerTurtleReader  *reader,
                        reader->state = STATE_SUBJECT;
                        break;
                case STATE_SUBJECT:
-                       skip_comments (reader);
-
                        if (g_buffered_input_stream_get_available (reader->buffered_stream) == 0)
                                return FALSE;
 
@@ -644,7 +643,7 @@ tracker_turtle_reader_iterate_next (TrackerTurtleReader  *reader,
                                reader->state = STATE_OBJECT;
                        } else if (parse_token (reader, ";")) {
                                /* Dot is allowed after semicolon */
-                               advance_whitespace (reader);
+                               advance_whitespace_and_comments(reader);
                                if (parse_token (reader, "."))
                                        reader->state = STATE_SUBJECT;
                                else


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]