Re: [PATCH v10 3/9] strbuf: add a case insensitive starts_with()

2018-03-09 Thread Ævar Arnfjörð Bjarmason

On Fri, Mar 09 2018, Junio C. Hamano jotted:

> Lars Schneider  writes:
>
>> I think following the boost lib makes most sense. Therefore,
>> I would like to go with "istarts_with". OK with you?
>
> I don't care too deeply; if we took starts_with() from there, where
> what we now want is defined as istarts_with(), then that sounds like
> a good thing to do.

I don't care either, but just a note that we had this exact discussion
around this time last year when I added a starts_with_icase() [1][2]
which eventually got dropped.

1. https://public-inbox.org/git/xmqqpohao2hw@gitster.mtv.corp.google.com/
2. https://public-inbox.org/git/20170326121654.22035-4-ava...@gmail.com/


Re: [PATCH v10 3/9] strbuf: add a case insensitive starts_with()

2018-03-09 Thread Junio C Hamano
Lars Schneider  writes:

> I think following the boost lib makes most sense. Therefore,
> I would like to go with "istarts_with". OK with you?

I don't care too deeply; if we took starts_with() from there, where
what we now want is defined as istarts_with(), then that sounds like
a good thing to do.

Thanks.


Re: [PATCH v10 3/9] strbuf: add a case insensitive starts_with()

2018-03-09 Thread Lars Schneider

> On 09 Mar 2018, at 00:12, Junio C Hamano  wrote:
> 
> Duy Nguyen  writes:
> 
>>> extern int starts_with(const char *str, const char *prefix);
>>> +extern int startscase_with(const char *str, const char *prefix);
>> 
>> This name is a bit hard to read. Boost [1] goes with istarts_with. I
>> wonder if it's better. If not I guess either starts_with_case or
>> starts_case_with will improve readability.
> 
> starts_with_case() sounds quite strange even though
> starts_with_icase() may make it clear that it is "a variant of
> starts_with() function that ignores case".  I dunno.
> dir.c::cmp_icase() takes the _icase suffix for not quite the way
> that is consistent with that understanding, though.

I think following the boost lib makes most sense. Therefore,
I would like to go with "istarts_with". OK with you?

- Lars


Re: [PATCH v10 3/9] strbuf: add a case insensitive starts_with()

2018-03-08 Thread Junio C Hamano
Duy Nguyen  writes:

>>  extern int starts_with(const char *str, const char *prefix);
>> +extern int startscase_with(const char *str, const char *prefix);
>
> This name is a bit hard to read. Boost [1] goes with istarts_with. I
> wonder if it's better. If not I guess either starts_with_case or
> starts_case_with will improve readability.

starts_with_case() sounds quite strange even though
starts_with_icase() may make it clear that it is "a variant of
starts_with() function that ignores case".  I dunno.
dir.c::cmp_icase() takes the _icase suffix for not quite the way
that is consistent with that understanding, though.



Re: [PATCH v10 3/9] strbuf: add a case insensitive starts_with()

2018-03-07 Thread Duy Nguyen
On Thu, Mar 8, 2018 at 12:30 AM,   wrote:
> From: Lars Schneider 
>
> Check in a case insensitive manner if one string is a prefix of another
> string.
>
> This function is used in a subsequent commit.
>
> Signed-off-by: Lars Schneider 
> ---
>  git-compat-util.h | 1 +
>  strbuf.c  | 9 +
>  2 files changed, 10 insertions(+)
>
> diff --git a/git-compat-util.h b/git-compat-util.h
> index 68b2ad531e..f648da0c11 100644
> --- a/git-compat-util.h
> +++ b/git-compat-util.h
> @@ -455,6 +455,7 @@ extern void (*get_warn_routine(void))(const char *warn, 
> va_list params);
>  extern void set_die_is_recursing_routine(int (*routine)(void));
>
>  extern int starts_with(const char *str, const char *prefix);
> +extern int startscase_with(const char *str, const char *prefix);

This name is a bit hard to read. Boost [1] goes with istarts_with. I
wonder if it's better. If not I guess either starts_with_case or
starts_case_with will improve readability.

[1] 
http://www.boost.org/doc/libs/1_41_0/doc/html/boost/algorithm/istarts_with.html

>
>  /*
>   * If the string "str" begins with the string found in "prefix", return 1.
> diff --git a/strbuf.c b/strbuf.c
> index b635f0bdc4..5779a2d591 100644
> --- a/strbuf.c
> +++ b/strbuf.c
> @@ -11,6 +11,15 @@ int starts_with(const char *str, const char *prefix)
> return 0;
>  }
>
> +int startscase_with(const char *str, const char *prefix)
> +{
> +   for (; ; str++, prefix++)
> +   if (!*prefix)
> +   return 1;
> +   else if (tolower(*str) != tolower(*prefix))
> +   return 0;
> +}
> +
>  int skip_to_optional_arg_default(const char *str, const char *prefix,
>  const char **arg, const char *def)
>  {
> --
> 2.16.2
>



-- 
Duy


[PATCH v10 3/9] strbuf: add a case insensitive starts_with()

2018-03-07 Thread lars . schneider
From: Lars Schneider 

Check in a case insensitive manner if one string is a prefix of another
string.

This function is used in a subsequent commit.

Signed-off-by: Lars Schneider 
---
 git-compat-util.h | 1 +
 strbuf.c  | 9 +
 2 files changed, 10 insertions(+)

diff --git a/git-compat-util.h b/git-compat-util.h
index 68b2ad531e..f648da0c11 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -455,6 +455,7 @@ extern void (*get_warn_routine(void))(const char *warn, 
va_list params);
 extern void set_die_is_recursing_routine(int (*routine)(void));
 
 extern int starts_with(const char *str, const char *prefix);
+extern int startscase_with(const char *str, const char *prefix);
 
 /*
  * If the string "str" begins with the string found in "prefix", return 1.
diff --git a/strbuf.c b/strbuf.c
index b635f0bdc4..5779a2d591 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -11,6 +11,15 @@ int starts_with(const char *str, const char *prefix)
return 0;
 }
 
+int startscase_with(const char *str, const char *prefix)
+{
+   for (; ; str++, prefix++)
+   if (!*prefix)
+   return 1;
+   else if (tolower(*str) != tolower(*prefix))
+   return 0;
+}
+
 int skip_to_optional_arg_default(const char *str, const char *prefix,
 const char **arg, const char *def)
 {
-- 
2.16.2