Skip to content

Commit

Permalink
Merge pull request #4807 from rainers/checkwhitespace_lines
Browse files Browse the repository at this point in the history
improve checkwhitespace
  • Loading branch information
yebblies committed Jul 8, 2015
2 parents 3c56f56 + 5de2730 commit 26cc2bb
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions src/checkwhitespace.d
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,31 @@ int main(string[] args)
auto r = regex(r" +\n");
foreach(a; args[1..$])
{
auto str = a.readText();
if (str.canFind("\r\n"))
try
{
writefln("Error - file '%s' contains windows line endings", a);
error = true;
ptrdiff_t pos;
auto str = a.readText();
if ((pos = str.indexOf("\r\n")) >= 0)
{
writefln("Error - file '%s' contains windows line endings at line %d", a, str[0..pos].count('\n') + 1);
error = true;
}
if (a.extension() != ".mak" && (pos = str.indexOf('\t')) >= 0)
{
writefln("Error - file '%s' contains tabs at line %d", a, str[0..pos].count('\n') + 1);
error = true;
}
auto m = str.matchFirst(r);
if (!m.empty)
{
pos = m.front.ptr - str.ptr; // assume the match is a slice of the string
writefln("Error - file '%s' contains trailing whitespace at line %d", a, str[0..pos].count('\n') + 1);
error = true;
}
}
if (a.extension() != ".mak" && str.canFind('\t'))
catch(Exception e)
{
writefln("Error - file '%s' contains tabs", a);
error = true;
}
if (!str.matchFirst(r).empty)
{
writefln("Error - file '%s' contains trailing whitespace", a);
error = true;
writefln("Exception - file '%s': %s", a, e.msg);
}
}
return error ? 1 : 0;
Expand Down

0 comments on commit 26cc2bb

Please sign in to comment.