Mysterious whitespaces

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rubs
    Enthusiast
    • Jan 2005
    • 27

    Mysterious whitespaces

    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
    Team Scooter
    • Oct 2007
    • 5533

    #2
    Re: Mysterious whitespaces

    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.
    Chris K Scooter Software

    Comment

    • rubs
      Enthusiast
      • Jan 2005
      • 27

      #3
      Re: Mysterious whitespaces

      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 so you can check it out.

      Comment

      • Chris
        Team Scooter
        • Oct 2007
        • 5533

        #4
        Re: Mysterious whitespaces

        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.
        Chris K Scooter Software

        Comment

        • rubs
          Enthusiast
          • Jan 2005
          • 27

          #5
          Re: Mysterious whitespaces

          Hah, I'd never realize that . I think I didn't pay attention to the code itself. Thanks very much for being so speedy and to the point.

          Comment

          Working...