[phobos] Annoying whitespace diffs
David Simcha
dsimcha at gmail.com
Sun Aug 22 15:17:48 PDT 2010
I develop using CodeBlocks, and apparently in its default setup it
converts tabs to spaces and snips off trailing whitespace. On the one
hand, this is what's probably causing a lot of the weird diffs, but on
the other hand, every time I work on a module that has these defects
they automatically get fixed.
Ideally (not sure how well this would work in practice) such simple,
mechanical style guidelines would automatically be applied to all code
on checkin, i.e. your program or some equivalent would automatically run
on the server side on all uploaded code immediately before it's
committed to the SVN backend.
On 8/22/2010 5:20 PM, Walter Bright 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