type: Make an assert()ion independent of the last entry of an enum.
[cparser] / separator_t.h
1 /*
2  * This file is part of cparser.
3  * Copyright (C) 2012 Christoph Mallon <christoph.mallon@gmx.de>
4  */
5 #ifndef SEPARATOR_H
6 #define SEPARATOR_H
7
8 #include <stdbool.h>
9
10 typedef struct separator_t separator_t;
11 struct separator_t
12 {
13         char const *first; /**< Returned on the first call to sep_next(). */
14         char const *rest;  /**< Returned on all further calls to sep_next(). */
15 };
16
17 /**
18  * Returns first on the first call for s and rest on all further calls.
19  */
20 static inline char const* sep_next(separator_t* const s)
21 {
22         char const *const cur = s->first;
23         s->first = s->rest;
24         return cur;
25 }
26
27 /**
28  * Returns whether sep_next() has not been called for s.
29  */
30 static inline bool sep_at_first(separator_t const* const s)
31 {
32         return s->first != s->rest;
33 }
34
35 #endif