View Full Version : Mysterious whitespaces
rubs
31-Jan-2005, 10:30 AM
Hi,
I'm comparing two PHP files using rules. Both files were originally UNIX-formatted, but one of them was changed using a Windows editor that removes all trailing whitespaces. Some lines that have additional spaces appear as different. "Whitespace includes line endings" is turned on, "ignore unimportant differences" is turned on. I found out that if I add the "\s+$" regex to the irrelevant text list, however, lines show up as similar, which is effectively what I want.
Why do I need to add the regex, and what is the difference between Line Endings and "\s+$"? Shouldn't they be the same?
Thanks a lot,
Chris
31-Jan-2005, 11:38 AM
Normally line terminators are not included in the comparison in any way unless you check the Whitespace Includes: "Line endings (PC/MAC/Unix)". Without that checked, you won't be able to compare line terminators.
With the option checked, Line Terminators are included in the comparison as whitespace, so you'll have to mark them unimportant if you don't want to see the difference.
The "\s+$" regexp matches all trailing whitespace (spaces, tabs, Edit: This does not include line terminators). The "Line endings" check box only matches line termination characters, and the "Trailing whitespace" check box matches trailing spaces and tabs.
The simplest way to ignore the terminator and whitespace differences in your files is to leave "Line endings (PC/MAC/Unix)" unchecked, and check "Trailing whitespace" as Unimportant Text in the Importance tab.
rubs
31-Jan-2005, 11:58 AM
Thanks for your quick reply. However...
The simplest way to ignore the terminator and whitespace differences in your files is to leave "Line endings (PC/MAC/Unix)" unchecked, and check "Trailing whitespace" as Unimportant Text in the Importance tab.
Even if I uncheck "Line endings (PC/MAC/Unix)" and do as you said, the lines keep being marked as different. Only "\s+$" seems to work. I've uploaded a demo here (http://www.hypervisual.com/pub/whitespace.zip) so you can check it out.
Chris
31-Jan-2005, 01:06 PM
It turns out this is because of a string literal. In functions_post.php on line 503, you have a string literal for ' to ' that carries over onto line 504. This is why it is still being marked as important even though you have "Trailing Whitespace" checked as unimportant. BC evaluates text delimiters before RegExp, this is why the "\s+$" regular expression is working, but other methods aren't able to over-ride the string literal.
rubs
31-Jan-2005, 01:18 PM
Hah, I'd never realize that :o. I think I didn't pay attention to the code itself. Thanks very much for being so speedy and to the point.
vBulletin® v3.7.1, Copyright ©2000-2012, Jelsoft Enterprises Ltd.