lkml.org 
[lkml]   [2016]   [Jan]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v1 1/8] lib/string: introduce match_string() helper
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.

> +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'.

> +{
> + 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));
}

-ss

\
 
 \ /
  Last update: 2016-01-08 02:01    [W:0.581 / U:0.200 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site