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
Junio C Hamano <gitster@pobox.com>
Date
Mar 25, 2014, 04:54 UTC
Message-ID
<7vd2haq3n5.fsf@alter.siamese.dyndns.org>
In-Reply-To
<532C1EFA.3000109@alum.mit.edu>
Michael Haggerty <mhagger@alum.mit.edu> writes:
Show 13 quoted lines
>> -	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?

Also, why would casting char to wchar_t without any conversion be safe and/or sane?

I would sort-of understand if the change were to use isspace(), but I do not think that is a correct conversion, either. Isn't a pair of strings "a bc" and "a bc " supposed not to match?

My understanding is that two strings that differ only at places where they have runs of whitespaces whose length differ are to compare the same, e.g. "a_bc__" and "a__bc_" (SP replaced with _ to make them stand out). Ignoring whitespace change is very different from ignoring all whitespaces (the latter of which would make "a b" and "ab" match).

As a tangent, I have a suspicion that the current implementation may be wrong at the beginning of the string. Wouldn't it match " abc" and "abc", even though these two strings shouldn't match?

Previous: Michael HaggertyNext: George Papanikolaou
Message 4 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.