Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1304277
| From | Andy Shevchenko <andriy.shevchenko@linux.intel.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH v1 1/8] lib/string: introduce match_string() helper |
| Date | 2016-01-08 09:50 +0100 |
| Message-ID | <qOAUc-4eB-43@gated-at.bofh.it> (permalink) |
| References | <qOhy9-7Vb-3@gated-at.bofh.it> <qOsWC-7b8-5@gated-at.bofh.it> |
| Organization | Intel Finland Oy |
On Fri, 2016-01-08 at 09:13 +0900, Sergey Senozhatsky wrote:
> On (01/07/16 14:06), Andy Shevchenko wrote:
> >
> > From time to time we have to match a string in an array. Make a
> > simple helper
> > for that purpose.
> >
>
> Hello,
>
> strncmp() case seems to be quite common.
Like I answered to Rasmus, please, provide real examples.
>
> > +int match_string(const char * const *array, size_t len, const char
> > *string)
> ^^^^^^^
> a nitpick, [to me] `len' looks a bit confusing, usually it's array
> 'size'.
Agreed. I would change it to plain 'n'.
>
> > +{
> > + int index = 0;
> > + const char *item;
> > +
> > + do {
> > + item = array[index];
> > + if (!item)
> > + break;
> > + if (!strcmp(item, string))
> > + return index;
> > + } while (++index < len || !len);
> > +
> > + return -ENODATA;
> > +}
>
>
> do you want to do something like this:
>
> /*
> * hm, how to name this thing... nmatch_string() or
> match_nstring()...
> * nmatch_string() _probably_ better, match_nstring() is totally
> cryptic.
> */
> int nmatch_string(array, array_size, string, string_len)
> {
> do {
> strncmp();
> } while ();
> }
>
> int match_string(array, array_size, string)
> {
> return nmatch_string(array, array_size, string,
> strlen(string));
> }
See above.
--
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Intel Finland Oy
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH v1 1/8] lib/string: introduce match_string() helper Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2016-01-07 13:10 +0100
[PATCH v1 8/8] ide: hpt366: convert to use match_string() helper Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2016-01-07 13:10 +0100
[PATCH v1 2/8] device property: convert to use match_string() helper Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2016-01-07 13:10 +0100
Re: [PATCH v1 2/8] device property: convert to use match_string() helper Mika Westerberg <mika.westerberg@linux.intel.com> - 2016-01-08 14:10 +0100
[PATCH v1 6/8] power: ab8500: convert to use match_string() helper Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2016-01-07 13:10 +0100
Re: [PATCH v1 6/8] power: ab8500: convert to use match_string() helper Linus Walleij <linus.walleij@linaro.org> - 2016-01-07 16:20 +0100
[PATCH v1 7/8] ata: hpt366: convert to use match_string() helper Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2016-01-07 13:10 +0100
Re: [PATCH v1 7/8] ata: hpt366: convert to use match_string() helper Tejun Heo <tj@kernel.org> - 2016-01-07 16:50 +0100
[PATCH v1 5/8] power: charger_manager: convert to use match_string() helper Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2016-01-07 13:10 +0100
[PATCH v1 4/8] drm/edid: convert to use match_string() helper Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2016-01-07 13:10 +0100
Re: [PATCH v1 1/8] lib/string: introduce match_string() helper Heikki Krogerus <heikki.krogerus@linux.intel.com> - 2016-01-07 14:10 +0100
Re: [PATCH v1 1/8] lib/string: introduce match_string() helper Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2016-01-07 14:20 +0100
Re: [PATCH v1 1/8] lib/string: introduce match_string() helper Heikki Krogerus <heikki.krogerus@linux.intel.com> - 2016-01-07 14:30 +0100
Re: [PATCH v1 1/8] lib/string: introduce match_string() helper Rasmus Villemoes <linux@rasmusvillemoes.dk> - 2016-01-07 23:10 +0100
Re: [PATCH v1 1/8] lib/string: introduce match_string() helper Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2016-01-08 09:50 +0100
Re: [PATCH v1 1/8] lib/string: introduce match_string() helper Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2016-01-08 01:20 +0100
Re: [PATCH v1 1/8] lib/string: introduce match_string() helper Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2016-01-08 09:50 +0100
Re: [PATCH v1 1/8] lib/string: introduce match_string() helper Sergey Senozhatsky <sergey.senozhatsky@gmail.com> - 2016-01-09 02:20 +0100
Re: [PATCH v1 1/8] lib/string: introduce match_string() helper Andy Shevchenko <andy.shevchenko@gmail.com> - 2016-01-09 13:00 +0100
Re: [PATCH v1 1/8] lib/string: introduce match_string() helper Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2016-01-11 16:00 +0100
Re: [PATCH v1 1/8] lib/string: introduce match_string() helper Rasmus Villemoes <linux@rasmusvillemoes.dk> - 2016-01-11 23:20 +0100
Re: [PATCH v1 1/8] lib/string: introduce match_string() helper Andy Shevchenko <andy.shevchenko@gmail.com> - 2016-01-11 23:30 +0100
Re: [PATCH v1 1/8] lib/string: introduce match_string() helper Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2016-01-12 09:30 +0100
csiph-web