Eric Sunshine <sunsh...@sunshineco.com> writes:

> On Thu, Jun 2, 2016 at 3:51 AM, Eric Wong <e...@80x24.org> wrote:
>> Eric Wong <e...@80x24.org> wrote:
>>> Eric Sunshine <sunsh...@sunshineco.com> wrote:
>>> > On Tue, May 31, 2016 at 3:45 AM, Eric Wong <e...@80x24.org> wrote:
>>> > > Eric Sunshine <sunsh...@sunshineco.com> wrote:
>>> > >> I wonder if hand-coding, rather than using a regex, could be an 
>>> > >> improvement:
>>> > >>
>>> > >>     static int is_mboxrd_from(const char *s, size_t n)
>>> > >>     {
>>> > >>         size_t f = strlen("From ");
>>> > >>         const char *t = s + n;
>>> > >>
>>> > >>         while (s < t && *s == '>')
>>> > >>             s++;
>>> > >>         return t - s >= f && !memcmp(s, "From ", f);
>>> > >>     }
>>> > >>
>>> > >> or something.
>>> > >
>>> > > Yikes.  I mostly work in high-level languages and do my best to
>>> > > avoid string parsing in C; so that scares me.  A lot.
>
> As mentioned above, it's all subjective and, of course, I have a bias
> toward the example I provided, but don't otherwise feel strongly about
> it. I do, however, like the idea of using a simple hand-coded matching
> function over the regex (but no so much that I would complain about
> it). Use whatever you and Junio feel is appropriate.

This is meant to be a replacement for the original that uses
regexec(), which in turn means the string we are checking is
guaranteed to be NUL terminated, right?

        static int is_mboxrd_from(const char *line) {
                return starts_with(line + strspn(line, ">"), "From ");
        }

is sufficiently high-level that no longer is scary, hopefully?

I agree with you that regexec() is way overkill for something small
and simple like this.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to