[glib] GVariant parser: match strings without consuming



commit 24ed841d6a65e3beff64b2252d132be9e57ede9a
Author: Ryan Lortie <desrt desrt ca>
Date:   Thu Mar 31 14:45:50 2011 +0530

    GVariant parser: match strings without consuming
    
    Add a new function that allows the parser to check that the current
    token is equal to a given string without consuming the token.
    Reimplement the 'consume' function in terms of the new function.

 glib/gvariant-parser.c |   25 ++++++++++++++-----------
 1 files changed, 14 insertions(+), 11 deletions(-)
---
diff --git a/glib/gvariant-parser.c b/glib/gvariant-parser.c
index 7f81373..b5cfe24 100644
--- a/glib/gvariant-parser.c
+++ b/glib/gvariant-parser.c
@@ -303,22 +303,25 @@ token_stream_is_numeric (TokenStream *stream)
 }
 
 static gboolean
-token_stream_consume (TokenStream *stream,
-                      const gchar *token)
+token_stream_peek_string (TokenStream *stream,
+                          const gchar *token)
 {
   gint length = strlen (token);
 
-  if (!token_stream_prepare (stream))
-    return FALSE;
+  return token_stream_prepare (stream) &&
+         stream->stream - stream->this == length &&
+         memcmp (stream->this, token, length) == 0;
+}
 
-  if (stream->stream - stream->this == length &&
-      memcmp (stream->this, token, length) == 0)
-    {
-      token_stream_next (stream);
-      return TRUE;
-    }
+static gboolean
+token_stream_consume (TokenStream *stream,
+                      const gchar *token)
+{
+  if (!token_stream_peek_string (stream, token))
+    return FALSE;
 
-  return FALSE;
+  token_stream_next (stream);
+  return TRUE;
 }
 
 static gboolean



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