From: Vladimir Davydov <vdavydov.dev@gmail.com>
To: Alexander Turenko <alexander.turenko@tarantool.org>
Cc: "Michał Durak" <gdrbyko1@protonmail.com>,
"tarantool-patches@freelists.org"
<tarantool-patches@freelists.org>
Subject: Re: [PATCH v3] lua: add 'chars' param to string.strip functions
Date: Thu, 21 Feb 2019 16:01:34 +0300 [thread overview]
Message-ID: <20190221130134.l4wqw3tjtizl5mpr@esperanza> (raw)
In-Reply-To: <20190218204232.zu72sokzqsiishvf@tkn_work_nb>
On Mon, Feb 18, 2019 at 11:42:32PM +0300, Alexander Turenko wrote:
> On Mon, Feb 11, 2019 at 07:20:38PM +0000, Michał Durak wrote:
> > Add optional 'chars' parameter to string.strip, string.lstrip
> > and string.rstrip for specifying the unwanted characters.
> > Behavior modeled after the equivalent Python built-ins.
> >
> > Closes: tarantool#2977
>
> Does it work in that way? I know that `Closes: #2977` do, but don't sure
> about your form. The documentation (the link is below) doesn't mention
> this form as far as I see.
Fixed it.
> > +void
> > +string_strip_helper(const char *inp, size_t inp_len, const char *chars,
> > + size_t chars_len, bool lstrip, bool rstrip,
> > + size_t *newstart, size_t *newlen)
> > +{
> > + size_t skipped;
> > + uint8_t arr[256] = {0};
> > +
> > + for (size_t i = 0; i < chars_len; ++i) {
> > + unsigned char c = chars[i];
> > + arr[c] = 1;
> > + }
> > +
> > + *newstart = skipped = lstrip ? lstrip_helper(inp, inp_len, arr) : 0;
> > +
> > + if (rstrip)
> > + skipped += rstrip_helper(inp + skipped, inp_len - skipped, arr);
> > +
> > + *newlen = inp_len - skipped;
> > +}
>
> I think that the following way to write it looks simpler (marked changed
> lines with !!):
>
> ```
> void
> string_strip_helper(const char *inp, size_t inp_len, const char *chars,
> size_t chars_len, bool lstrip, bool rstrip,
> size_t *newstart, size_t *newlen)
> {
> !! size_t skipped = 0;
> uint8_t arr[256] = {0};
>
> for (size_t i = 0; i < chars_len; ++i) {
> unsigned char c = chars[i];
> arr[c] = 1;
> }
>
> !! if (lstrip)
> !! skipped += lstrip_helper(inp, inp_len, arr);
>
> !! *newstart = skipped;
>
> if (rstrip)
> skipped += rstrip_helper(inp + skipped, inp_len - skipped, arr);
>
> *newlen = inp_len - skipped;
> }
> ```
Agree. Updated the patch.
> > +#if defined(__cplusplus)
> > +extern "C" {
> > +#endif /* defined(__cplusplus) */
> > +
> > +/** \cond public */
> > +
> > +void
> > +string_strip_helper(const char *inp, size_t inp_len, const char *chars,
> > + size_t chars_len, bool lstrip, bool rstrip,
> > + size_t *newstart, size_t *newlen);
> > +
> > +/** \endcond public */
cond public isn't needed here. Removed.
Pushed to 2.1.
prev parent reply other threads:[~2019-02-21 13:01 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-22 18:51 [tarantool-patches] " Michał Durak
2019-02-04 4:47 ` [tarantool-patches] " Alexander Turenko
2019-02-11 19:20 ` Michał Durak
2019-02-18 20:42 ` Alexander Turenko
2019-02-21 13:01 ` Vladimir Davydov [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190221130134.l4wqw3tjtizl5mpr@esperanza \
--to=vdavydov.dev@gmail.com \
--cc=alexander.turenko@tarantool.org \
--cc=gdrbyko1@protonmail.com \
--cc=tarantool-patches@freelists.org \
--subject='Re: [PATCH v3] lua: add '\''chars'\'' param to string.strip functions' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox