Skip to content
Snippets Groups Projects
Commit 1343434e authored by Niels Möller's avatar Niels Möller
Browse files

* sexp.h (struct sexp_iterator): New field start.

* sexp.c (sexp_iterator_subexpr): New function.
(sexp_iterator_parse): Initialize ITERATOR->start.

Rev: src/nettle/sexp.c:1.11
Rev: src/nettle/sexp.h:1.8
parent a8ff1805
No related branches found
No related tags found
No related merge requests found
...@@ -99,6 +99,8 @@ sexp_iterator_simple(struct sexp_iterator *iterator, ...@@ -99,6 +99,8 @@ sexp_iterator_simple(struct sexp_iterator *iterator,
static int static int
sexp_iterator_parse(struct sexp_iterator *iterator) sexp_iterator_parse(struct sexp_iterator *iterator)
{ {
iterator->start = iterator->pos;
if (EMPTY(iterator)) if (EMPTY(iterator))
{ {
if (iterator->level) if (iterator->level)
...@@ -208,6 +210,19 @@ sexp_iterator_exit_list(struct sexp_iterator *iterator) ...@@ -208,6 +210,19 @@ sexp_iterator_exit_list(struct sexp_iterator *iterator)
return sexp_iterator_parse(iterator); return sexp_iterator_parse(iterator);
} }
const uint8_t *
sexp_iterator_subexpr(struct sexp_iterator *iterator,
unsigned *length)
{
unsigned start = iterator->start;
if (!sexp_iterator_next(iterator))
return 0;
*length = iterator->start - start;
return iterator->buffer + start;
}
int int
sexp_iterator_check_type(struct sexp_iterator *iterator, sexp_iterator_check_type(struct sexp_iterator *iterator,
const uint8_t *type) const uint8_t *type)
......
...@@ -37,6 +37,8 @@ struct sexp_iterator ...@@ -37,6 +37,8 @@ struct sexp_iterator
unsigned length; unsigned length;
const uint8_t *buffer; const uint8_t *buffer;
/* Points at the start of the current sub expression. */
unsigned start;
/* If type is SEXP_LIST, pos points at the start of the current /* If type is SEXP_LIST, pos points at the start of the current
* element. Otherwise, it points at the end. */ * element. Otherwise, it points at the end. */
unsigned pos; unsigned pos;
...@@ -75,6 +77,12 @@ sexp_iterator_enter_list(struct sexp_iterator *iterator); ...@@ -75,6 +77,12 @@ sexp_iterator_enter_list(struct sexp_iterator *iterator);
int int
sexp_iterator_exit_list(struct sexp_iterator *iterator); sexp_iterator_exit_list(struct sexp_iterator *iterator);
/* Gets start and length of the current subexpression. Implies
* sexp_iterator_next. */
const uint8_t *
sexp_iterator_subexpr(struct sexp_iterator *iterator,
unsigned *length);
/* Checks the type of the current expression, which should be a list /* Checks the type of the current expression, which should be a list
* *
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment