From 9e9b6b08c2fb7b4c58d21206d09054b6a204cef2 Mon Sep 17 00:00:00 2001 From: "Steffen (Daode) Nurpmeso" Date: Thu, 23 Feb 2017 17:39:00 +0100 Subject: [PATCH] Add n_shexp_parse_token_cp() --- nailfuns.h | 5 +++++ shexp.c | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/nailfuns.h b/nailfuns.h index 3a87698e..d301a859 100644 --- a/nailfuns.h +++ b/nailfuns.h @@ -1783,6 +1783,11 @@ FL enum n_shexp_state n_shexp_parse_token(enum n_shexp_parse_flags flags, struct n_string *store, struct str *input, void const **cookie); +/* Quick+dirty simplified : if an error occurs, returns a copy of *cp and set + * *cp to NULL, otherwise advances *cp to over the parsed token */ +FL char *n_shexp_parse_token_cp(enum n_shexp_parse_flags flags, + char const **cp); + /* Quote input in a way that can, in theory, be fed into parse_token() again. * ->s may be NULL if ->l is 0, if ->l EQ UIZ_MAX strlen(->s) is used. * If rndtrip is true we try to make the resulting string "portable" (by diff --git a/shexp.c b/shexp.c index d683af43..df8505c0 100644 --- a/shexp.c +++ b/shexp.c @@ -1555,6 +1555,33 @@ jleave_quick: return rv; } +FL char * +n_shexp_parse_token_cp(enum n_shexp_parse_flags flags, char const **cp){ + struct str input; + struct n_string sou, *soup; + char *rv; + enum n_shexp_state shs; + NYD2_ENTER; + + assert(cp != NULL); + + input.s = n_UNCONST(*cp); + input.l = UIZ_MAX; + soup = n_string_creat_auto(&sou); + + shs = n_shexp_parse_token(flags, soup, &input, NULL); + if(shs & n_SHEXP_STATE_ERR_MASK){ + soup = n_string_assign_cp(soup, *cp); + *cp = NULL; + }else + *cp = input.s; + + rv = n_string_cp(soup); + /*n_string_gut(n_string_drop_ownership(soup));*/ + NYD2_LEAVE; + return rv; +} + FL struct n_string * n_shexp_quote(struct n_string *store, struct str const *input, bool_t rndtrip){ struct a_shexp_quote_lvl sql; -- 2.11.4.GIT