git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] builtin/apply.c: use iswspace() to detect line-ending-like chars

From
Michael Haggerty <mhagger@alum.mit.edu>
Date
Mar 21, 2014, 11:14 UTC
Message-ID
<532C1EFA.3000109@alum.mit.edu>
In-Reply-To
<1395344384-7975-1-git-send-email-g3orge.app@gmail.com>
On 03/20/2014 08:39 PM, George Papanikolaou wrote:
Show 32 quoted lines
> Removing the bloat of checking for both '\r' and '\n' with the prettier
> iswspace() function which checks for other characters as well. (read: \f \t \v)
> ---
> 
> This is one more try to clean up this fuzzy_matchlines() function as part of a
> microproject for GSOC. The rest more clarrified microprojects were taken.
> I'm obviously planning on applying.
> 
> Thanks
> 
> Signed-of-by: George 'papanikge' Papanikolaou <g3orge.app@gmail.com>
> 
>  builtin/apply.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/builtin/apply.c b/builtin/apply.c
> index b0d0986..912a53a 100644
> --- a/builtin/apply.c
> +++ b/builtin/apply.c
> @@ -295,9 +295,9 @@ static int fuzzy_matchlines(const char *s1, size_t n1,
>  	int result = 0;
>  
>  	/* ignore line endings */
> -	while ((*last1 == '\r') || (*last1 == '\n'))
> +	while (iswspace(*last1))
>  		last1--;
> -	while ((*last2 == '\r') || (*last2 == '\n'))
> +	while (iswspace(*last2))
>  		last2--;
>  
>  	/* skip leading whitespace */
> 
In addition to Eric's comments...
What happens if the string consists *only* of whitespace?
Michael
-- 
Michael Haggerty
mhagger@alum.mit.edu
http://softwareswirl.blogspot.com/
Previous: Eric SunshineNext: Junio C Hamano
Message 3 of 9 in “builtin/apply.c: use iswspace() to detect line-ending-like chars”
  1. builtin/apply.c: use iswspace() to detect line-ending-like charsGeorge Papanikolaou, Mar 20, 2014
  2. Eric SunshineMar 21, 2014
  3. Michael HaggertyMar 21, 2014
  4. Junio C HamanoMar 25, 2014
  5. George PapanikolaouMar 26, 2014
  6. Junio C HamanoMar 26, 2014
  7. Eric SunshineMar 21, 2014
  8. George PapanikolaouMar 22, 2014
  9. Eric SunshineMar 23, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.