[tracker] libtracker-data: Add optional() method for tokens that need no retval checks



commit 17962ffe75a82b68c8a7fe07f647db04c932cc27
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sat Aug 5 20:22:28 2017 +0200

    libtracker-data: Add optional() method for tokens that need no retval checks
    
    Also makes code clearer, as accept() implies you may react differently on
    token availability.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=785863

 src/libtracker-data/tracker-sparql-pattern.vala |    4 ++++
 src/libtracker-data/tracker-sparql-query.vala   |    5 +++++
 2 files changed, 9 insertions(+), 0 deletions(-)
---
diff --git a/src/libtracker-data/tracker-sparql-pattern.vala b/src/libtracker-data/tracker-sparql-pattern.vala
index 37faf28..96efc13 100644
--- a/src/libtracker-data/tracker-sparql-pattern.vala
+++ b/src/libtracker-data/tracker-sparql-pattern.vala
@@ -205,6 +205,10 @@ class Tracker.Sparql.Pattern : Object {
                return query.accept (type);
        }
 
+       inline void optional (SparqlTokenType type) throws Sparql.Error {
+               query.optional (type);
+       }
+
        Sparql.Error get_error (string msg) {
                return query.get_error (msg);
        }
diff --git a/src/libtracker-data/tracker-sparql-query.vala b/src/libtracker-data/tracker-sparql-query.vala
index 32d31ef..e611b0f 100644
--- a/src/libtracker-data/tracker-sparql-query.vala
+++ b/src/libtracker-data/tracker-sparql-query.vala
@@ -347,6 +347,11 @@ public class Tracker.Sparql.Query : Object {
                return false;
        }
 
+       internal void optional (SparqlTokenType type) throws Sparql.Error {
+               if (current () == type)
+                       next ();
+       }
+
        internal Sparql.Error get_error (string msg) {
                return new Sparql.Error.PARSE ("%d.%d: syntax error, %s".printf (tokens[index].begin.line, 
tokens[index].begin.column, msg));
        }


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