[phobos] Annoying whitespace diffs

Steven Schveighoffer schveiguy at yahoo.com
Sun Aug 22 19:12:38 PDT 2010


sed 's/\s*$//' kills trailing whitespace
Tabs are harder but I'd be shocked if nobody ever solved this before.  There might even be a way with sed.  There is no need for custom tools.

Re svn commits I think you can set up a filter script to reject inappropriate files.  You might even be able to apply filters to the files before they are committed. 

Sent from my iPhone

On Aug 22, 2010, at 5:20 PM, Walter Bright <walter at digitalmars.com> wrote:

> A lot of checkins to Phobos wind up with a lot of invisible changes, because:
> 
> 1. random addition and subtraction of tabs
> 2. random appearance and disappearance of trailing whitespace
> 
> I'd like to put an end to this, with the following rules:
> 
> 1. no tabs are allowed
> 2. no trailing whitespace is allowed
> 
> I use this program to do filter my checkins which takes care of it, feel free to use it or some equivalent.
> --------------------------------------------------------
> /* Replace tabs with spaces, and remove trailing whitespace from lines.
> */
> 
> import std.file;
> import std.path;
> 
> int main(string[] args)
> {
>   foreach (f; args[1 .. $])
>   {
>       auto input = cast(char[]) std.file.read(f);
>       auto output = filter(input);
>       if (output != input)
>           std.file.write(f, output);
>   }
>   return 0;
> }
> 
> 
> char[] filter(char[] input)
> {
>   char[] output;
>   size_t j;
> 
>   int column;
>   for (size_t i = 0; i < input.length; i++)
>   {
>       auto c = input[i];
> 
>       switch (c)
>       {
>           case '\t':
>               while ((column & 7) != 7)
>               {   output ~= ' ';
>                   j++;
>                   column++;
>               }
>               c = ' ';
>               column++;
>               break;
> 
>           case '\r':
>           case '\n':
>               while (j && output[j - 1] == ' ')
>                   j--;
>               output = output[0 .. j];
>               column = 0;
>               break;
> 
>           default:
>               column++;
>               break;
>       }
>       output ~= c;
>       j++;
>   }
>   while (j && output[j - 1] == ' ')
>       j--;
>   return output[0 .. j];
> }
> 
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos


More information about the phobos mailing list