Re: [PATCH 00/12] Hard coded string length cleanup
- From
Duy Nguyen <pclouds@gmail.com>
- Date
- Dec 19, 2013, 23:50 UTC
- Message-ID
- <CACsJy8Bb4+V1DEdEmRwj10Oozi8U430ZHDCj_UhnXZcaR-wQ=g@mail.gmail.com>
- In-Reply-To
- <52B38213.2070702@web.de>
On Fri, Dec 20, 2013 at 6:32 AM, René Scharfe <l.s.r@web.de> wrote:
Show 5 quoted lines
> Seeing that skip_prefix_defval is mostly used in the form > skip_prefix_defval(foo, prefix, foo) I wonder if it makes sense to > first change skip_prefix to return the full string instead of NULL > if the prefix is not matched. Would the resulting function cover > most use cases? And would it still be easily usable?
That was skip_prefix_gently() that I forgot to replace in a commit message, before I turned it into _defval variant. The reason for _defval is it could be use to chain expression together without adding temporary variables, e.g.
- if (starts_with(line->buf, ">From") && isspace(line->buf[5])) {
+ if (isspace(*skip_prefix_defval(line->buf, ">From", "NOSPACE"))) {Without _defval, one would need to do if ((p = skip_prefix(..)) && isspace(*p)). I'm not entirely sure this is a good thing though as it could make it a bit harder to read.
-- Duy