From 7b0f71cc999be75c608b5e6083695c8c46d1a76a Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Thu, 3 May 2018 17:34:17 +0200 Subject: [PATCH] Add method _parse_str for deque (missing tests for in, out, get_str & parse_str). --- m-deque.h | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/m-deque.h b/m-deque.h index 203d5b26..b276b268 100644 --- a/m-deque.h +++ b/m-deque.h @@ -710,6 +710,37 @@ } \ , /* no OUT_STR */ ) \ \ + M_IF_METHOD(PARSE_STR, oplist)( \ + static inline bool \ + M_C(name, _parse_str)(deque_t deque, const char str[], const char **endp) \ + { \ + DEQUEI_CONTRACT(deque); \ + assert (str != NULL); \ + M_C(name,_clean)(deque); \ + bool success = false; \ + int c = *str++; \ + if (M_UNLIKELY (c != '[')) return false; \ + c = *str++; \ + if (M_UNLIKELY (c == ']')) return true; \ + if (M_UNLIKELY (c == EOF)) return false; \ + str--; \ + type item; \ + M_GET_INIT oplist (item); \ + do { \ + bool b = M_GET_PARSE_STR oplist (item, str, &str); \ + do { c = *str++; } while (isspace(c)); \ + if (b == false || c == 0) { goto exit; } \ + M_C(name, _push_back)(deque, item); \ + } while (c == M_GET_SEPARATOR oplist); \ + M_GET_CLEAR oplist (item); \ + DEQUEI_CONTRACT(deque); \ + success = (c == ']'); \ + exit: \ + if (endp) *endp = str; \ + return success; \ + } \ + , /* no PARSE_STR */ ) \ + \ M_IF_METHOD(IN_STR, oplist)( \ static inline bool \ M_C(name, _in_str)(deque_t deque, FILE *file) \ @@ -727,7 +758,7 @@ M_GET_INIT oplist (item); \ do { \ bool b = M_GET_IN_STR oplist (item, file); \ - c = fgetc(file); \ + do { c = fgetc(file); } while (isspace(c)); \ if (b == false || c == EOF) { break; } \ M_C(name, _push_back)(deque, item); \ } while (c == M_GET_SEPARATOR oplist); \ @@ -767,6 +798,7 @@ ,POP(M_C(name,_pop_back)) \ ,OPLIST(oplist) \ ,M_IF_METHOD(GET_STR, oplist)(GET_STR(M_C(name, _get_str)),) \ + ,M_IF_METHOD(PARSE_STR, oplist)(PARSE_STR(M_C(name, _parse_str)),) \ ,M_IF_METHOD(OUT_STR, oplist)(OUT_STR(M_C(name, _out_str)),) \ ,M_IF_METHOD(IN_STR, oplist)(IN_STR(M_C(name, _in_str)),) \ ,M_IF_METHOD(EQUAL, oplist)(EQUAL(M_C(name, _equal_p)),) \