mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-26 05:56:14 +01:00
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.
This commit is contained in:
parent
f6dff49136
commit
24ed841d6a
@ -303,22 +303,25 @@ token_stream_is_numeric (TokenStream *stream)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
token_stream_consume (TokenStream *stream,
|
token_stream_peek_string (TokenStream *stream,
|
||||||
const gchar *token)
|
const gchar *token)
|
||||||
{
|
{
|
||||||
gint length = strlen (token);
|
gint length = strlen (token);
|
||||||
|
|
||||||
if (!token_stream_prepare (stream))
|
return token_stream_prepare (stream) &&
|
||||||
|
stream->stream - stream->this == length &&
|
||||||
|
memcmp (stream->this, token, length) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
token_stream_consume (TokenStream *stream,
|
||||||
|
const gchar *token)
|
||||||
|
{
|
||||||
|
if (!token_stream_peek_string (stream, token))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (stream->stream - stream->this == length &&
|
token_stream_next (stream);
|
||||||
memcmp (stream->this, token, length) == 0)
|
return TRUE;
|
||||||
{
|
|
||||||
token_stream_next (stream);
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
|
Loading…
Reference in New Issue
Block a user